MCPcopy Index your code
hub / github.com/coder/coder / TestMetricsRecordReloadSuccess

Function TestMetricsRecordReloadSuccess

coderd/aibridged/metrics_test.go:19–46  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

17// surface: every reload pass rewrites the series for the current
18// outcomes and the Reset on each pass drops stale series.
19func 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

Callers

nothing calls this directly

Calls 6

RecordReloadAttemptMethod · 0.95
RecordReloadSuccessMethod · 0.95
NewMetricsFunction · 0.92
WithLabelValuesMethod · 0.80
NewMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected