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

Function BenchmarkGetLabels_MediumSet

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

Source from the content-addressed store, hash-verified

1142}
1143
1144func BenchmarkGetLabels_MediumSet(b *testing.B) {
1145 m := prometheus.NewCounterVec(prometheus.CounterOpts{
1146 Name: "test",
1147 ConstLabels: map[string]string{
1148 "cluster": "abc",
1149 },
1150 }, []string{"reason", "user"})
1151
1152 for i := 1; i <= 1000; i++ {
1153 m.WithLabelValues("bad", fmt.Sprintf("user%d", i)).Inc()
1154 m.WithLabelValues("worse", fmt.Sprintf("user%d", i)).Inc()
1155 m.WithLabelValues("worst", fmt.Sprintf("user%d", i)).Inc()
1156
1157 if i%2 == 0 {
1158 m.WithLabelValues("bad", fmt.Sprintf("user%d", i)).Inc()
1159 m.WithLabelValues("worst", fmt.Sprintf("user%d", i)).Inc()
1160 } else {
1161 m.WithLabelValues("worst", fmt.Sprintf("user%d", i)).Inc()
1162 }
1163 }
1164
1165 for b.Loop() {
1166 if _, err := GetLabels(m, map[string]string{"user": "user1", "reason": "worse"}); err != nil {
1167 b.Fatal(err)
1168 }
1169 }
1170}
1171
1172func TestGetLabels(t *testing.T) {
1173 m := prometheus.NewCounterVec(prometheus.CounterOpts{

Callers

nothing calls this directly

Calls 3

GetLabelsFunction · 0.85
LoopMethod · 0.80
IncMethod · 0.45

Tested by

no test coverage detected