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

Function TestCollector_Set

coderd/prometheusmetrics/collector_test.go:49–80  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

47}
48
49func TestCollector_Set(t *testing.T) {
50 t.Parallel()
51
52 // given
53 agentsGauge := prometheusmetrics.NewCachedGaugeVec(prometheus.NewGaugeVec(prometheus.GaugeOpts{
54 Namespace: "coderd",
55 Subsystem: "agents",
56 Name: "up",
57 Help: "The number of active agents per workspace.",
58 }, []string{"username", "workspace_name"}))
59
60 // when
61 agentsGauge.WithLabelValues(prometheusmetrics.VectorOperationSet, 3, "first user", "my workspace")
62 agentsGauge.WithLabelValues(prometheusmetrics.VectorOperationSet, 4, "second user", "your workspace")
63 agentsGauge.WithLabelValues(prometheusmetrics.VectorOperationSet, 5, "first user", "my workspace")
64 agentsGauge.WithLabelValues(prometheusmetrics.VectorOperationSet, 6, "second user", "your workspace")
65 agentsGauge.Commit()
66
67 // then
68 ch := make(chan prometheus.Metric, 2)
69 agentsGauge.Collect(ch)
70
71 metrics := collectAndSortMetrics(t, agentsGauge, 2)
72
73 assert.Equal(t, "first user", metrics[0].Label[0].GetValue()) // Username
74 assert.Equal(t, "my workspace", metrics[0].Label[1].GetValue()) // Workspace name
75 assert.Equal(t, 5, int(metrics[0].Gauge.GetValue())) // Metric value
76
77 assert.Equal(t, "second user", metrics[1].Label[0].GetValue()) // Username
78 assert.Equal(t, "your workspace", metrics[1].Label[1].GetValue()) // Workspace name
79 assert.Equal(t, 6, int(metrics[1].Gauge.GetValue())) // Metric value
80}
81
82func TestCollector_Set_Add(t *testing.T) {
83 t.Parallel()

Callers

nothing calls this directly

Calls 7

WithLabelValuesMethod · 0.95
CommitMethod · 0.95
CollectMethod · 0.95
NewCachedGaugeVecFunction · 0.92
collectAndSortMetricsFunction · 0.85
EqualMethod · 0.45
GetValueMethod · 0.45

Tested by

no test coverage detected