[#32] Update health metric values

Now values are:
0 - undefined
1 - starting
2 - ready
3 - shutting down

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
Denis Kirillov 2023-04-17 16:28:27 +03:00
parent 162738e771
commit 959213520e
3 changed files with 18 additions and 11 deletions

View file

@ -14,6 +14,7 @@ This document outlines major changes between releases.
- Errors have become more detailed (#18) - Errors have become more detailed (#18)
- Update system attribute names (#22) - Update system attribute names (#22)
- Separate integration tests with build tags (#24) - Separate integration tests with build tags (#24)
- Changed values for `frostfs_http_gw_state_health` metric (#32)
### Updating from v0.26.0 ### Updating from v0.26.0

16
app.go
View file

@ -62,15 +62,10 @@ type (
gateMetrics struct { gateMetrics struct {
logger *zap.Logger logger *zap.Logger
provider GateMetricsProvider provider *metrics.GateMetrics
mu sync.RWMutex mu sync.RWMutex
enabled bool enabled bool
} }
GateMetricsProvider interface {
SetHealth(int32)
Unregister()
}
) )
// WithLogger returns Option to set a specific logger. // WithLogger returns Option to set a specific logger.
@ -214,9 +209,10 @@ func (a *app) getResolverConfig() ([]string, *resolver.Config) {
func (a *app) initMetrics() { func (a *app) initMetrics() {
gateMetricsProvider := metrics.NewGateMetrics(a.pool) gateMetricsProvider := metrics.NewGateMetrics(a.pool)
a.metrics = newGateMetrics(a.log, gateMetricsProvider, a.cfg.GetBool(cfgPrometheusEnabled)) 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 { if !enabled {
logger.Warn("metrics are disabled") logger.Warn("metrics are disabled")
} }
@ -236,7 +232,7 @@ func (m *gateMetrics) SetEnabled(enabled bool) {
m.mu.Unlock() m.mu.Unlock()
} }
func (m *gateMetrics) SetHealth(status int32) { func (m *gateMetrics) SetHealth(status metrics.HealthStatus) {
m.mu.RLock() m.mu.RLock()
if !m.enabled { if !m.enabled {
m.mu.RUnlock() m.mu.RUnlock()
@ -250,7 +246,7 @@ func (m *gateMetrics) SetHealth(status int32) {
func (m *gateMetrics) Shutdown() { func (m *gateMetrics) Shutdown() {
m.mu.Lock() m.mu.Lock()
if m.enabled { if m.enabled {
m.provider.SetHealth(0) m.provider.SetHealth(metrics.HealthStatusShuttingDown)
m.enabled = false m.enabled = false
} }
m.provider.Unregister() m.provider.Unregister()
@ -335,7 +331,7 @@ func (a *app) Wait() {
} }
func (a *app) setHealthStatus() { func (a *app) setHealthStatus() {
a.metrics.SetHealth(1) a.metrics.SetHealth(metrics.HealthStatusReady)
} }
func (a *app) Serve(ctx context.Context) { func (a *app) Serve(ctx context.Context) {

View file

@ -31,6 +31,16 @@ const (
methodCreateSession = "create_session" 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 { type GateMetrics struct {
stateMetrics stateMetrics
poolMetricsCollector poolMetricsCollector
@ -87,7 +97,7 @@ func (m stateMetrics) unregister() {
prometheus.Unregister(m.healthCheck) prometheus.Unregister(m.healthCheck)
} }
func (m stateMetrics) SetHealth(s int32) { func (m stateMetrics) SetHealth(s HealthStatus) {
m.healthCheck.Set(float64(s)) m.healthCheck.Set(float64(s))
} }