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

Function collectAndSortMetrics

coderd/prometheusmetrics/collector_test.go:119–141  ·  view source on GitHub ↗
(t *testing.T, collector prometheus.Collector, count int)

Source from the content-addressed store, hash-verified

117}
118
119func collectAndSortMetrics(t *testing.T, collector prometheus.Collector, count int) []*dto.Metric {
120 ch := make(chan prometheus.Metric, count)
121 defer close(ch)
122
123 var metrics []*dto.Metric
124
125 collector.Collect(ch)
126 for i := 0; i < count; i++ {
127 m := <-ch
128
129 var metric dto.Metric
130 err := m.Write(&metric)
131 require.NoError(t, err)
132
133 metrics = append(metrics, &metric)
134 }
135
136 // Ensure always the same order of metrics
137 sort.Slice(metrics, func(i, j int) bool {
138 return slices.IsSorted([]string{metrics[i].Label[0].GetValue(), metrics[j].Label[1].GetValue()})
139 })
140 return metrics
141}

Callers 3

TestCollector_AddFunction · 0.85
TestCollector_SetFunction · 0.85
TestCollector_Set_AddFunction · 0.85

Calls 3

CollectMethod · 0.65
WriteMethod · 0.65
GetValueMethod · 0.45

Tested by

no test coverage detected