From 19c6cfed033ec5218f81e064433756c6796e7773 Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Thu, 26 Nov 2026 04:14:53 +0000 Subject: [PATCH] docs(metrics): say the provider health gauge is shared with sharedState The HELP text claimed the discovery breaker is never shared via Redis. With redis.sharedState on it is shared, so every replica reports the same value and max() applies. The golden scrape changes by this line. --- metrics.go | 10 ++++------ shared_state_review_test.go | 11 +++++++++++ testdata/fleet_metrics_nostore.golden | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/metrics.go b/metrics.go index d1de127..72f24ad 100644 --- a/metrics.go +++ b/metrics.go @@ -442,12 +442,10 @@ const aggregationNoteStoreBacked = " AGGREGATION ACROSS REPLICAS: with Redis con const aggregationNotePerProcess = " AGGREGATION ACROSS REPLICAS: this counter lives only in this process's memory, never in Redis, regardless of Config.Redis — aggregate with sum(), which is always correct for it, unlike the store-backed families above." // aggregationNoteProviderHealthy is appended to llmgateway_provider_ -// healthy's HELP text: the discovery circuit breaker (registry.go's -// providerState.health) is per-process state, set by each replica's own -// discovery polling loop, and is never written to Redis — two replicas -// can legitimately disagree about one provider's health at the same -// instant (e.g. one mid-backoff, one already recovered). -const aggregationNoteProviderHealthy = " AGGREGATION ACROSS REPLICAS: each replica runs its own discovery circuit breaker in-process, never shared via Redis, so this can legitimately differ per replica. Read it per-instance where possible; if you must aggregate, use min() to surface \"at least one replica sees this provider as unhealthy\" — sum() is meaningless for a 0/1 gauge." +// healthy's HELP text: with redis.sharedState on, the discovery circuit +// breaker (registry.go's providerState.health) is shared through Redis; +// without it, each replica's own discovery loop sets it in-process. +const aggregationNoteProviderHealthy = " AGGREGATION ACROSS REPLICAS: with redis.sharedState on, the discovery circuit breaker is shared via Redis, so every replica reports the same value and max() is correct. Without it, each replica runs its own breaker, so the value can differ per replica; use min() to surface \"at least one replica sees this provider as unhealthy\". sum() is meaningless for a 0/1 gauge." // aggregationNoteTargetHealthy is appended to llmgateway_target_healthy's // HELP text (feat/target-health): the tracker behind this gauge diff --git a/shared_state_review_test.go b/shared_state_review_test.go index b92b576..843308e 100644 --- a/shared_state_review_test.go +++ b/shared_state_review_test.go @@ -441,3 +441,14 @@ func TestFleetLatencyEntriesOnlyWithStore(t *testing.T) { t.Errorf("fleet latency sum in the store = %d, want 300", got) } } + +func TestProviderHealthyHelpNamesSharedState(t *testing.T) { + for _, want := range []string{"redis.sharedState", "max()", "per replica", "min()"} { + if !strings.Contains(aggregationNoteProviderHealthy, want) { + t.Errorf("provider_healthy HELP note lacks %q: %s", want, aggregationNoteProviderHealthy) + } + } + if strings.Contains(aggregationNoteProviderHealthy, "never shared via Redis") { + t.Error("provider_healthy HELP note still says the breaker is never shared via Redis") + } +} diff --git a/testdata/fleet_metrics_nostore.golden b/testdata/fleet_metrics_nostore.golden index 8ade005..593fb48 100644 --- a/testdata/fleet_metrics_nostore.golden +++ b/testdata/fleet_metrics_nostore.golden @@ -28,7 +28,7 @@ llmgateway_provider_attempts_total{provider="gamma"} 0 llmgateway_provider_failures_total{provider="alpha"} 0 llmgateway_provider_failures_total{provider="beta"} 0 llmgateway_provider_failures_total{provider="gamma"} 0 -# HELP llmgateway_provider_healthy 1 when the provider's discovery circuit breaker is not open (closed or half-open), 0 when open (discoveryHealthy, registry.go). AGGREGATION ACROSS REPLICAS: each replica runs its own discovery circuit breaker in-process, never shared via Redis, so this can legitimately differ per replica. Read it per-instance where possible; if you must aggregate, use min() to surface "at least one replica sees this provider as unhealthy" — sum() is meaningless for a 0/1 gauge. +# HELP llmgateway_provider_healthy 1 when the provider's discovery circuit breaker is not open (closed or half-open), 0 when open (discoveryHealthy, registry.go). AGGREGATION ACROSS REPLICAS: with redis.sharedState on, the discovery circuit breaker is shared via Redis, so every replica reports the same value and max() is correct. Without it, each replica runs its own breaker, so the value can differ per replica; use min() to surface "at least one replica sees this provider as unhealthy". sum() is meaningless for a 0/1 gauge. # TYPE llmgateway_provider_healthy gauge llmgateway_provider_healthy{provider="alpha"} 1 llmgateway_provider_healthy{provider="beta"} 1