TestMetricsRecordReloadSuccess covers the provider_info GaugeVec surface: every reload pass rewrites the series for the current outcomes and the Reset on each pass drops stale series.
(t *testing.T)
| 17 | // surface: every reload pass rewrites the series for the current |
| 18 | // outcomes and the Reset on each pass drops stale series. |
| 19 | func TestMetricsRecordReloadSuccess(t *testing.T) { |
| 20 | t.Parallel() |
| 21 | |
| 22 | reg := prometheus.NewRegistry() |
| 23 | m := aibridged.NewMetrics(reg) |
| 24 | |
| 25 | outcomes := []aibridged.ProviderOutcome{ |
| 26 | {Name: "alpha", Type: "openai", Status: aibridged.ProviderStatusEnabled}, |
| 27 | {Name: "beta", Type: "anthropic", Status: aibridged.ProviderStatusDisabled}, |
| 28 | {Name: "gamma", Type: "openai", Status: aibridged.ProviderStatusError, Err: xerrors.New("bad config")}, |
| 29 | } |
| 30 | |
| 31 | before := time.Now().Unix() |
| 32 | m.RecordReloadAttempt() |
| 33 | m.RecordReloadSuccess(outcomes) |
| 34 | after := time.Now().Unix() |
| 35 | |
| 36 | assert.Equal(t, 1.0, promtest.ToFloat64(m.ProviderInfo.WithLabelValues("alpha", "openai", "enabled"))) |
| 37 | assert.Equal(t, 1.0, promtest.ToFloat64(m.ProviderInfo.WithLabelValues("beta", "anthropic", "disabled"))) |
| 38 | assert.Equal(t, 1.0, promtest.ToFloat64(m.ProviderInfo.WithLabelValues("gamma", "openai", "error"))) |
| 39 | |
| 40 | attemptTS := int64(promtest.ToFloat64(m.ProvidersLastReloadTimestampSeconds)) |
| 41 | successTS := int64(promtest.ToFloat64(m.ProvidersLastReloadSuccessTimestampSeconds)) |
| 42 | assert.GreaterOrEqual(t, attemptTS, before) |
| 43 | assert.LessOrEqual(t, attemptTS, after) |
| 44 | assert.GreaterOrEqual(t, successTS, before) |
| 45 | assert.LessOrEqual(t, successTS, after) |
| 46 | } |
| 47 | |
| 48 | // TestMetricsResetsStaleProviderSeries verifies that providers removed |
| 49 | // from the outcome set between reloads do not leave behind stale |
nothing calls this directly
no test coverage detected