[#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>
poc/vitrual-host
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)
- 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

16
app.go
View File

@ -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) {

View File

@ -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))
}