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

Function requireCounter

coderd/x/chatd/chatloop/metrics_test.go:365–388  ·  view source on GitHub ↗

requireCounter gathers metrics from reg, finds the named counter family, and asserts it has exactly one series with the given value and labels.

(t *testing.T, reg *prometheus.Registry, name string, wantValue float64, wantLabels map[string]string)

Source from the content-addressed store, hash-verified

363// family, and asserts it has exactly one series with the given value
364// and labels.
365func requireCounter(t *testing.T, reg *prometheus.Registry, name string, wantValue float64, wantLabels map[string]string) {
366 t.Helper()
367
368 families, err := reg.Gather()
369 require.NoError(t, err)
370
371 for _, f := range families {
372 if f.GetName() != name {
373 continue
374 }
375 require.Len(t, f.GetMetric(), 1, "expected exactly one series for %s", name)
376 metric := f.GetMetric()[0]
377 assert.Equal(t, wantValue, metric.GetCounter().GetValue(), "counter value for %s", name)
378 labels := map[string]string{}
379 for _, lp := range metric.GetLabel() {
380 labels[lp.GetName()] = lp.GetValue()
381 }
382 for k, v := range wantLabels {
383 assert.Equal(t, v, labels[k], "label %s for %s", k, name)
384 }
385 return
386 }
387 t.Fatalf("metric %s not found in gathered families", name)
388}
389
390func TestRecordToolError(t *testing.T) {
391 t.Parallel()

Callers 5

TestRecordCompactionFunction · 0.85
TestRecordStreamRetryFunction · 0.85
TestRecordToolErrorFunction · 0.85

Calls 6

HelperMethod · 0.65
GetNameMethod · 0.45
LenMethod · 0.45
EqualMethod · 0.45
GetValueMethod · 0.45
FatalfMethod · 0.45

Tested by

no test coverage detected