MCPcopy Create free account
hub / github.com/cortexproject/cortex / BenchmarkGetMetricsWithLabelNames

Function BenchmarkGetMetricsWithLabelNames

pkg/util/metrics_helper_test.go:98–134  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

96}
97
98func BenchmarkGetMetricsWithLabelNames(b *testing.B) {
99 const (
100 numMetrics = 1000
101 numLabelsPerMetric = 10
102 )
103
104 // Generate metrics and add them to a metric family.
105 mf := &dto.MetricFamily{Metric: make([]*dto.Metric, 0, numMetrics)}
106 for i := range numMetrics {
107 labels := []*dto.LabelPair{{
108 Name: proto.String("unique"),
109 Value: proto.String(strconv.Itoa(i)),
110 }}
111
112 for l := 1; l < numLabelsPerMetric; l++ {
113 labels = append(labels, &dto.LabelPair{
114 Name: proto.String(fmt.Sprintf("label_%d", l)),
115 Value: proto.String(fmt.Sprintf("value_%d", l)),
116 })
117 }
118
119 mf.Metric = append(mf.Metric, &dto.Metric{
120 Label: labels,
121 Counter: &dto.Counter{Value: proto.Float64(1.5)},
122 })
123 }
124
125 b.ReportAllocs()
126
127 for b.Loop() {
128 out := getMetricsWithLabelNames(mf, []string{"label_1", "label_2", "label_3"})
129
130 if expected := 1; len(out) != expected {
131 b.Fatalf("unexpected number of output groups: expected = %d got = %d", expected, len(out))
132 }
133 }
134}
135
136func makeLabels(namesAndValues ...string) []*dto.LabelPair {
137 out := []*dto.LabelPair(nil)

Callers

nothing calls this directly

Calls 3

getMetricsWithLabelNamesFunction · 0.85
LoopMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected