From ef07c1a3c96e0a1c39c00eee20b7bbeb7855dcdb Mon Sep 17 00:00:00 2001 From: Ekaterina Lebedeva Date: Tue, 21 Nov 2023 15:07:37 +0300 Subject: [PATCH] [#552] Add sysd notifications to storage service Signed-off-by: Ekaterina Lebedeva --- cmd/frostfs-node/config.go | 12 ++++++++++++ cmd/frostfs-node/control.go | 19 ++++++++++++++----- config/example/node.yaml | 3 +++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/cmd/frostfs-node/config.go b/cmd/frostfs-node/config.go index 82b01b56..27c028ba 100644 --- a/cmd/frostfs-node/config.go +++ b/cmd/frostfs-node/config.go @@ -62,6 +62,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/util/response" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" + "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/sdnotify" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/state" "git.frostfs.info/TrueCloudLab/frostfs-observability/logging/lokicore" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" @@ -361,6 +362,8 @@ type internals struct { healthStatus *atomic.Int32 // is node under maintenance isMaintenance atomic.Bool + + sdNotify bool } // starts node's maintenance. @@ -632,9 +635,18 @@ func initInternals(appCfg *config.Config, log *logger.Logger) internals { log: log, apiVersion: version.Current(), healthStatus: &healthStatus, + sdNotify: initSdNotify(appCfg), } } +func initSdNotify(appCfg *config.Config) bool { + if config.BoolSafe(appCfg.Sub("systemdnotify"), "enabled") { + fatalOnErr(sdnotify.InitSocket()) + return true + } + return false +} + func initShared(appCfg *config.Config, key *keys.PrivateKey, netState *networkState, relayOnly bool) shared { var netAddr network.AddressGroup diff --git a/cmd/frostfs-node/control.go b/cmd/frostfs-node/control.go index 6b603d43..ee2a2952 100644 --- a/cmd/frostfs-node/control.go +++ b/cmd/frostfs-node/control.go @@ -110,12 +110,21 @@ func (c *cfg) HealthStatus() control.HealthStatus { } func (c *cfg) notifySystemd(st control.HealthStatus) { - status := fmt.Sprintf("%v, %v", st.Number(), st) - err := sdnotify.Status(status) - if err == nil { - c.log.Info(fmt.Sprintf("reported STATUS=\"%v\" to systemd", status)) + if !c.sdNotify { + return + } + var err error + switch st { + case control.HealthStatus_READY: + err = sdnotify.FlagAndStatus(sdnotify.ReadyEnabled) + case control.HealthStatus_SHUTTING_DOWN: + err = sdnotify.FlagAndStatus(sdnotify.StoppingEnabled) + case control.HealthStatus_RECONFIGURING: + err = sdnotify.FlagAndStatus(sdnotify.ReloadingEnabled) + default: + err = sdnotify.Status(fmt.Sprintf("%v", st)) } if err != nil { - c.log.Error(logs.FailedToReportStatusToSystemd, zap.String("error", err.Error())) + c.log.Error(logs.FailedToReportStatusToSystemd, zap.Error(err)) } } diff --git a/config/example/node.yaml b/config/example/node.yaml index 1355113a..c6a2be9a 100644 --- a/config/example/node.yaml +++ b/config/example/node.yaml @@ -1,6 +1,9 @@ logger: level: debug # logger level: one of "debug", "info" (default), "warn", "error", "dpanic", "panic", "fatal" +systemdnotify: + enabled: true + pprof: enabled: true address: localhost:6060 # endpoint for Node profiling