From 959213520e2ddbab081c1cdffa0c98303535b46b Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Mon, 17 Apr 2023 16:28:27 +0300 Subject: [PATCH] [#32] Update health metric values Now values are: 0 - undefined 1 - starting 2 - ready 3 - shutting down Signed-off-by: Denis Kirillov --- CHANGELOG.md | 1 + app.go | 16 ++++++---------- metrics/metrics.go | 12 +++++++++++- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dee5545..5ad285b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ This document outlines major changes between releases. - Errors have become more detailed (#18) - Update system attribute names (#22) - Separate integration tests with build tags (#24) +- Changed values for `frostfs_http_gw_state_health` metric (#32) ### Updating from v0.26.0 diff --git a/app.go b/app.go index 825da8e..0f49477 100644 --- a/app.go +++ b/app.go @@ -62,15 +62,10 @@ type ( gateMetrics struct { logger *zap.Logger - provider GateMetricsProvider + provider *metrics.GateMetrics mu sync.RWMutex enabled bool } - - GateMetricsProvider interface { - SetHealth(int32) - Unregister() - } ) // WithLogger returns Option to set a specific logger. @@ -214,9 +209,10 @@ func (a *app) getResolverConfig() ([]string, *resolver.Config) { func (a *app) initMetrics() { gateMetricsProvider := metrics.NewGateMetrics(a.pool) a.metrics = newGateMetrics(a.log, gateMetricsProvider, a.cfg.GetBool(cfgPrometheusEnabled)) + a.metrics.SetHealth(metrics.HealthStatusStarting) } -func newGateMetrics(logger *zap.Logger, provider GateMetricsProvider, enabled bool) *gateMetrics { +func newGateMetrics(logger *zap.Logger, provider *metrics.GateMetrics, enabled bool) *gateMetrics { if !enabled { logger.Warn("metrics are disabled") } @@ -236,7 +232,7 @@ func (m *gateMetrics) SetEnabled(enabled bool) { m.mu.Unlock() } -func (m *gateMetrics) SetHealth(status int32) { +func (m *gateMetrics) SetHealth(status metrics.HealthStatus) { m.mu.RLock() if !m.enabled { m.mu.RUnlock() @@ -250,7 +246,7 @@ func (m *gateMetrics) SetHealth(status int32) { func (m *gateMetrics) Shutdown() { m.mu.Lock() if m.enabled { - m.provider.SetHealth(0) + m.provider.SetHealth(metrics.HealthStatusShuttingDown) m.enabled = false } m.provider.Unregister() @@ -335,7 +331,7 @@ func (a *app) Wait() { } func (a *app) setHealthStatus() { - a.metrics.SetHealth(1) + a.metrics.SetHealth(metrics.HealthStatusReady) } func (a *app) Serve(ctx context.Context) { diff --git a/metrics/metrics.go b/metrics/metrics.go index a184588..4797fd6 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -31,6 +31,16 @@ const ( methodCreateSession = "create_session" ) +// HealthStatus of the gate application. +type HealthStatus int32 + +const ( + HealthStatusUndefined HealthStatus = 0 + HealthStatusStarting HealthStatus = 1 + HealthStatusReady HealthStatus = 2 + HealthStatusShuttingDown HealthStatus = 3 +) + type GateMetrics struct { stateMetrics poolMetricsCollector @@ -87,7 +97,7 @@ func (m stateMetrics) unregister() { prometheus.Unregister(m.healthCheck) } -func (m stateMetrics) SetHealth(s int32) { +func (m stateMetrics) SetHealth(s HealthStatus) { m.healthCheck.Set(float64(s)) }