[#493] Refactor serving of prometheus and pprof services

Rename `util/profiler` package to `httputil` and refactor it:

  * simplify utility HTTP server;

  * make more generic server's parameters in order to remove `viper.Viper`
    dependency;

  * use single constructor for creating the pprof and prometheus servers;

  * replace `enabled` config value with empty-check of the network address.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-12 01:59:05 +03:00 committed by Alex Vanin
parent 6339f1a468
commit 8d17dab86e
15 changed files with 295 additions and 304 deletions

26
pkg/util/http/opts.go Normal file
View file

@ -0,0 +1,26 @@
package httputil
import (
"time"
)
// Option sets an optional parameter of Server.
type Option func(*cfg)
type cfg struct {
shutdownTimeout time.Duration
}
func defaultCfg() *cfg {
return &cfg{
shutdownTimeout: 15 * time.Second,
}
}
// WithShutdownTimeout returns option to set shutdown timeout
// of the internal HTTP server.
func WithShutdownTimeout(dur time.Duration) Option {
return func(c *cfg) {
c.shutdownTimeout = dur
}
}