[#552] Add status notification to systemd

Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
This commit is contained in:
Ekaterina Lebedeva 2023-11-16 02:48:05 +03:00
parent 05f8f49289
commit 9b2dce5763
6 changed files with 35 additions and 2 deletions

View file

@ -2,6 +2,7 @@ package main
import (
"context"
"fmt"
"net"
controlconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/control"
@ -10,6 +11,7 @@ import (
controlSvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/server"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/tree"
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
sysdnotify "github.com/iguanesolutions/go-systemd/v5/notify"
"go.uber.org/zap"
"google.golang.org/grpc"
)
@ -83,12 +85,14 @@ func (c *cfg) NetmapStatus() control.NetmapStatus {
}
func (c *cfg) setHealthStatus(st control.HealthStatus) {
c.notifySystemd(st)
c.healthStatus.Store(int32(st))
c.metricsCollector.State().SetHealth(int32(st))
}
func (c *cfg) compareAndSwapHealthStatus(oldSt, newSt control.HealthStatus) (swapped bool) {
if swapped = c.healthStatus.CompareAndSwap(int32(oldSt), int32(newSt)); swapped {
c.notifySystemd(newSt)
c.metricsCollector.State().SetHealth(int32(newSt))
}
return
@ -96,6 +100,7 @@ func (c *cfg) compareAndSwapHealthStatus(oldSt, newSt control.HealthStatus) (swa
func (c *cfg) swapHealthStatus(st control.HealthStatus) (old control.HealthStatus) {
old = control.HealthStatus(c.healthStatus.Swap(int32(st)))
c.notifySystemd(st)
c.metricsCollector.State().SetHealth(int32(st))
return
}
@ -103,3 +108,15 @@ func (c *cfg) swapHealthStatus(st control.HealthStatus) (old control.HealthStatu
func (c *cfg) HealthStatus() control.HealthStatus {
return control.HealthStatus(c.healthStatus.Load())
}
func (c *cfg) notifySystemd(st control.HealthStatus) string {
status := fmt.Sprintf("%v, %v", st.Number(), st)
err := sysdnotify.Status(status)
if err == nil {
c.log.Info(fmt.Sprintf("reported STATUS=\"%v\" to systemd", status))
}
if err != nil {
c.log.Error(logs.FailedToReportStatusToSystemd, zap.String("error", err.Error()))
}
return fmt.Sprintf("%v, %v", st, control.HealthStatus_name[int32(st)])
}