From 4a8c38249123e7c7646930629d3bc9b9b81eeb0a Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Mon, 17 Apr 2023 16:15:11 +0300 Subject: [PATCH] [#91] Update values for health metric Signed-off-by: Denis Kirillov --- CHANGELOG.md | 1 + cmd/s3-gw/app.go | 3 ++- metrics/app.go | 4 ++-- metrics/state.go | 12 +++++++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 422c17e..a52ef9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ This document outlines major changes between releases. - Limit number of objects to delete at one time (TrueCloudLab#37) - CompleteMultipartUpload handler now sends whitespace characters to keep alive client's connection (#60) - Support new system attributes (#64) +- Changed values for `frostfs_s3_gw_state_health` metric (#91) ## [0.26.0] - 2022-12-28 diff --git a/cmd/s3-gw/app.go b/cmd/s3-gw/app.go index d8da913..7ea8151 100644 --- a/cmd/s3-gw/app.go +++ b/cmd/s3-gw/app.go @@ -182,6 +182,7 @@ func (a *App) initAPI(ctx context.Context) { func (a *App) initMetrics() { a.metrics = metrics.NewAppMetrics(a.log, frostfs.NewPoolStatistic(a.pool), a.cfg.GetBool(cfgPrometheusEnabled)) + a.metrics.SetHealth(metrics.HealthStatusStarting) } func (a *App) initResolver() { @@ -369,7 +370,7 @@ func (a *App) Wait() { } func (a *App) setHealthStatus() { - a.metrics.SetHealth(1) + a.metrics.SetHealth(metrics.HealthStatusReady) } // Serve runs HTTP server to handle S3 API requests. diff --git a/metrics/app.go b/metrics/app.go index 4de4317..c757617 100644 --- a/metrics/app.go +++ b/metrics/app.go @@ -37,7 +37,7 @@ func (m *AppMetrics) SetEnabled(enabled bool) { m.mu.Unlock() } -func (m *AppMetrics) SetHealth(status int32) { +func (m *AppMetrics) SetHealth(status HealthStatus) { if !m.isEnabled() { return } @@ -48,7 +48,7 @@ func (m *AppMetrics) SetHealth(status int32) { func (m *AppMetrics) Shutdown() { m.mu.Lock() if m.enabled { - m.gate.State.SetHealth(0) + m.gate.State.SetHealth(HealthStatusShuttingDown) m.enabled = false } m.gate.Unregister() diff --git a/metrics/state.go b/metrics/state.go index 9d28c5b..e4317ac 100644 --- a/metrics/state.go +++ b/metrics/state.go @@ -4,6 +4,16 @@ import "github.com/prometheus/client_golang/prometheus" const stateSubsystem = "state" +// HealthStatus of the gate application. +type HealthStatus int32 + +const ( + HealthStatusUndefined HealthStatus = 0 + HealthStatusStarting HealthStatus = 1 + HealthStatusReady HealthStatus = 2 + HealthStatusShuttingDown HealthStatus = 3 +) + type stateMetrics struct { healthCheck prometheus.Gauge } @@ -27,6 +37,6 @@ 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)) }