(t *testing.T)
| 153 | } |
| 154 | |
| 155 | func Test_histogram_cantAdd(t *testing.T) { |
| 156 | canAdd := false |
| 157 | overflowLabels := labels.FromStrings("metric_overflow", "true") |
| 158 | overflowHash := overflowLabels.Hash() |
| 159 | lifecycler := &mockLimiter{ |
| 160 | onAddFunc: func(_ uint64, count uint32, lbls labels.Labels) (labels.Labels, uint64) { |
| 161 | assert.Equal(t, uint32(5), count) |
| 162 | if canAdd { |
| 163 | return lbls, lbls.Hash() |
| 164 | } |
| 165 | return overflowLabels, overflowHash |
| 166 | }, |
| 167 | } |
| 168 | |
| 169 | h := newHistogram("my_histogram", []float64{1.0, 2.0}, lifecycler, "", nil, 15*time.Minute) |
| 170 | |
| 171 | // allow adding new series |
| 172 | canAdd = true |
| 173 | |
| 174 | h.ObserveWithExemplar(buildTestLabels([]string{"label"}, []string{"value-1"}), 1.0, "", 1.0) |
| 175 | h.ObserveWithExemplar(buildTestLabels([]string{"label"}, []string{"value-2"}), 1.5, "", 1.0) |
| 176 | |
| 177 | collectionTimeMs := time.Now().UnixMilli() |
| 178 | endOfLastMinuteMs := getEndOfLastMinuteMs(collectionTimeMs) |
| 179 | expectedSamples := []sample{ |
| 180 | newSample(map[string]string{"__name__": "my_histogram_count", "label": "value-1"}, endOfLastMinuteMs, 0), |
| 181 | newSample(map[string]string{"__name__": "my_histogram_count", "label": "value-1"}, collectionTimeMs, 1), |
| 182 | newSample(map[string]string{"__name__": "my_histogram_sum", "label": "value-1"}, collectionTimeMs, 1), |
| 183 | newSample(map[string]string{"__name__": "my_histogram_bucket", "label": "value-1", "le": "1"}, endOfLastMinuteMs, 0), |
| 184 | newSample(map[string]string{"__name__": "my_histogram_bucket", "label": "value-1", "le": "1"}, collectionTimeMs, 1), |
| 185 | newSample(map[string]string{"__name__": "my_histogram_bucket", "label": "value-1", "le": "2"}, endOfLastMinuteMs, 0), |
| 186 | newSample(map[string]string{"__name__": "my_histogram_bucket", "label": "value-1", "le": "2"}, collectionTimeMs, 1), |
| 187 | newSample(map[string]string{"__name__": "my_histogram_bucket", "label": "value-1", "le": "+Inf"}, endOfLastMinuteMs, 0), |
| 188 | newSample(map[string]string{"__name__": "my_histogram_bucket", "label": "value-1", "le": "+Inf"}, collectionTimeMs, 1), |
| 189 | newSample(map[string]string{"__name__": "my_histogram_count", "label": "value-2"}, endOfLastMinuteMs, 0), |
| 190 | newSample(map[string]string{"__name__": "my_histogram_count", "label": "value-2"}, collectionTimeMs, 1), |
| 191 | newSample(map[string]string{"__name__": "my_histogram_sum", "label": "value-2"}, collectionTimeMs, 1.5), |
| 192 | newSample(map[string]string{"__name__": "my_histogram_bucket", "label": "value-2", "le": "1"}, endOfLastMinuteMs, 0), |
| 193 | newSample(map[string]string{"__name__": "my_histogram_bucket", "label": "value-2", "le": "1"}, collectionTimeMs, 0), |
| 194 | newSample(map[string]string{"__name__": "my_histogram_bucket", "label": "value-2", "le": "2"}, endOfLastMinuteMs, 0), |
| 195 | newSample(map[string]string{"__name__": "my_histogram_bucket", "label": "value-2", "le": "2"}, collectionTimeMs, 1), |
| 196 | newSample(map[string]string{"__name__": "my_histogram_bucket", "label": "value-2", "le": "+Inf"}, endOfLastMinuteMs, 0), |
| 197 | newSample(map[string]string{"__name__": "my_histogram_bucket", "label": "value-2", "le": "+Inf"}, collectionTimeMs, 1), |
| 198 | } |
| 199 | collectMetricAndAssert(t, h, collectionTimeMs, 10, expectedSamples, nil) |
| 200 | |
| 201 | // block new series - existing series can still be updated |
| 202 | canAdd = false |
| 203 | |
| 204 | h.ObserveWithExemplar(buildTestLabels([]string{"label"}, []string{"value-2"}), 2.5, "", 1.0) |
| 205 | h.ObserveWithExemplar(buildTestLabels([]string{"label"}, []string{"value-3"}), 3.0, "", 1.0) |
| 206 | |
| 207 | collectionTimeMs = time.Now().UnixMilli() |
| 208 | expectedSamples = []sample{ |
| 209 | newSample(map[string]string{"__name__": "my_histogram_count", "label": "value-1"}, collectionTimeMs, 1), |
| 210 | newSample(map[string]string{"__name__": "my_histogram_sum", "label": "value-1"}, collectionTimeMs, 1), |
| 211 | newSample(map[string]string{"__name__": "my_histogram_bucket", "label": "value-1", "le": "1"}, collectionTimeMs, 1), |
| 212 | newSample(map[string]string{"__name__": "my_histogram_bucket", "label": "value-1", "le": "2"}, collectionTimeMs, 1), |
nothing calls this directly
no test coverage detected