(t *testing.T)
| 47 | } |
| 48 | |
| 49 | func 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 | |
| 82 | func TestCollector_Set_Add(t *testing.T) { |
| 83 | t.Parallel() |
nothing calls this directly
no test coverage detected