Skip to content

Commit

Permalink
metrics, pprof: make their closers map
Browse files Browse the repository at this point in the history
Add consts for the metric and profiler names. Make `c.veryLastClosers` a map.

Signed-off-by: Andrey Butusov <[email protected]>
  • Loading branch information
End-rey committed Nov 19, 2024
1 parent 3344356 commit 3592189
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion cmd/neofs-node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ const maxMsgSize = 4 << 20 // transport msg limit 4 MiB
// for each contract listener.
const notificationHandlerPoolSize = 10

const metricName = "prometheus"

const profilerName = "pprof"

// applicationConfiguration reads and stores component-specific configuration
// values. It should not store any application helpers structs (pointers to shared
// structs).
Expand Down Expand Up @@ -289,7 +293,7 @@ type internals struct {
closers []func()
// services that are useful for debug (e.g. when a regular closer does not
// close), must be close at the very end of application life cycle
veryLastClosers []func()
veryLastClosers map[string]func()

apiVersion version.Version
healthStatus atomic.Int32
Expand Down Expand Up @@ -638,6 +642,8 @@ func initCfg(appCfg *config.Config) *cfg {
c.basics.networkState.metrics = c.metricsCollector
}

c.veryLastClosers = make(map[string]func())

c.onShutdown(c.clientCache.CloseAll) // clean up connections
c.onShutdown(c.bgClientCache.CloseAll) // clean up connections
c.onShutdown(c.putClientCache.CloseAll) // clean up connections
Expand Down
8 changes: 4 additions & 4 deletions cmd/neofs-node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func main() {

c := initCfg(appCfg)

preRunAndLog(c, "prometheus", initMetrics(c))
preRunAndLog(c, metricName, initMetrics(c))

preRunAndLog(c, "pprof", initProfiler(c))
preRunAndLog(c, profilerName, initProfiler(c))

initApp(c)

Expand Down Expand Up @@ -97,7 +97,7 @@ func preRunAndLog(c *cfg, name string, srv *httputil.Server) {
})
}()

c.veryLastClosers = append(c.veryLastClosers, func() {
c.veryLastClosers[name] = func() {
c.log.Debug(fmt.Sprintf("shutting down %s service", name))

err := srv.Shutdown()
Expand All @@ -108,7 +108,7 @@ func preRunAndLog(c *cfg, name string, srv *httputil.Server) {
}

c.log.Debug(fmt.Sprintf("%s service has been stopped", name))
})
}
}

func initAndLog(c *cfg, name string, initializer func(*cfg)) {
Expand Down

0 comments on commit 3592189

Please sign in to comment.