(t *testing.T)
| 56 | } |
| 57 | |
| 58 | func TestCounterDifferentLabels(t *testing.T) { |
| 59 | var seriesAdded int |
| 60 | lifecycler := &mockLimiter{ |
| 61 | onAddFunc: func(hash uint64, _ uint32, lbls labels.Labels) (labels.Labels, uint64) { |
| 62 | seriesAdded++ |
| 63 | return lbls, hash |
| 64 | }, |
| 65 | } |
| 66 | |
| 67 | c := newCounter("my_counter", lifecycler, map[string]string{}, 15*time.Minute) |
| 68 | |
| 69 | c.Inc(buildTestLabels([]string{"label"}, []string{"value-1"}), 1.0) |
| 70 | c.Inc(buildTestLabels([]string{"another_label"}, []string{"another_value"}), 2.0) |
| 71 | |
| 72 | assert.Equal(t, 2, seriesAdded) |
| 73 | |
| 74 | collectionTimeMs := time.Now().UnixMilli() |
| 75 | endOfLastMinuteMs := getEndOfLastMinuteMs(collectionTimeMs) |
| 76 | expectedSamples := []sample{ |
| 77 | newSample(map[string]string{"__name__": "my_counter", "label": "value-1"}, endOfLastMinuteMs, 0), |
| 78 | newSample(map[string]string{"__name__": "my_counter", "label": "value-1"}, collectionTimeMs, 1), |
| 79 | newSample(map[string]string{"__name__": "my_counter", "another_label": "another_value"}, endOfLastMinuteMs, 0), |
| 80 | newSample(map[string]string{"__name__": "my_counter", "another_label": "another_value"}, collectionTimeMs, 2), |
| 81 | } |
| 82 | collectMetricAndAssert(t, c, collectionTimeMs, 2, expectedSamples, nil) |
| 83 | } |
| 84 | |
| 85 | func Test_counter_cantAdd(t *testing.T) { |
| 86 | canAdd := false |
nothing calls this directly
no test coverage detected