[#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:
parent
6339f1a468
commit
8d17dab86e
15 changed files with 295 additions and 304 deletions
|
@ -1,17 +1,40 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/profiler"
|
||||
"context"
|
||||
|
||||
httputil "github.com/nspcc-dev/neofs-node/pkg/util/http"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func initMetrics(c *cfg) {
|
||||
if c.metricsCollector != nil {
|
||||
c.metricsServer = profiler.NewMetrics(c.log, c.viper)
|
||||
addr := c.viper.GetString(cfgMetricsAddr)
|
||||
if addr == "" {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func serveMetrics(c *cfg) {
|
||||
if c.metricsServer != nil {
|
||||
c.metricsServer.Start(c.ctx)
|
||||
}
|
||||
var prm httputil.Prm
|
||||
|
||||
prm.Address = addr
|
||||
prm.Handler = promhttp.Handler()
|
||||
|
||||
srv := httputil.New(prm,
|
||||
httputil.WithShutdownTimeout(
|
||||
c.viper.GetDuration(cfgMetricsShutdownTimeout),
|
||||
),
|
||||
)
|
||||
|
||||
c.workers = append(c.workers, newWorkerFromFunc(func(context.Context) {
|
||||
fatalOnErr(srv.Serve())
|
||||
}))
|
||||
|
||||
c.closers = append(c.closers, func() {
|
||||
err := srv.Shutdown()
|
||||
if err != nil {
|
||||
c.log.Debug("could not shutdown metrics server",
|
||||
zap.String("error", err.Error()),
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue