(t *testing.T, appV2 bool)
| 3258 | } |
| 3259 | |
| 3260 | func testScrapeLoopHistogramBucketLimit(t *testing.T, appV2 bool) { |
| 3261 | sl, _ := newTestScrapeLoop(t, func(sl *scrapeLoop) { |
| 3262 | if appV2 { |
| 3263 | sl.appendableV2 = appendableV2Func(func(ctx context.Context) storage.AppenderV2 { |
| 3264 | return &bucketLimitAppenderV2{AppenderV2: teststorage.NewAppendable().AppenderV2(ctx), limit: 2} |
| 3265 | }) |
| 3266 | } else { |
| 3267 | sl.appendable = appendableFunc(func(ctx context.Context) storage.Appender { |
| 3268 | return &bucketLimitAppender{Appender: teststorage.NewAppendable().Appender(ctx), limit: 2} |
| 3269 | }) |
| 3270 | } |
| 3271 | |
| 3272 | sl.enableNativeHistogramScraping = true |
| 3273 | sl.sampleMutator = func(l labels.Labels) labels.Labels { |
| 3274 | if l.Has("deleteme") { |
| 3275 | return labels.EmptyLabels() |
| 3276 | } |
| 3277 | return l |
| 3278 | } |
| 3279 | }) |
| 3280 | app := sl.appender() |
| 3281 | |
| 3282 | metric := dto.Metric{} |
| 3283 | err := sl.metrics.targetScrapeNativeHistogramBucketLimit.Write(&metric) |
| 3284 | require.NoError(t, err) |
| 3285 | beforeMetricValue := metric.GetCounter().GetValue() |
| 3286 | |
| 3287 | nativeHistogram := prometheus.NewHistogramVec( |
| 3288 | prometheus.HistogramOpts{ |
| 3289 | Namespace: "testing", |
| 3290 | Name: "example_native_histogram", |
| 3291 | Help: "This is used for testing", |
| 3292 | ConstLabels: map[string]string{"some": "value"}, |
| 3293 | NativeHistogramBucketFactor: 1.1, // 10% increase from bucket to bucket |
| 3294 | NativeHistogramMaxBucketNumber: 100, // intentionally higher than the limit we'll use in the scraper |
| 3295 | }, |
| 3296 | []string{"size"}, |
| 3297 | ) |
| 3298 | registry := prometheus.NewRegistry() |
| 3299 | require.NoError(t, registry.Register(nativeHistogram)) |
| 3300 | nativeHistogram.WithLabelValues("S").Observe(1.0) |
| 3301 | nativeHistogram.WithLabelValues("M").Observe(1.0) |
| 3302 | nativeHistogram.WithLabelValues("L").Observe(1.0) |
| 3303 | nativeHistogram.WithLabelValues("M").Observe(10.0) |
| 3304 | nativeHistogram.WithLabelValues("L").Observe(10.0) // in different bucket since > 1*1.1 |
| 3305 | |
| 3306 | gathered, err := registry.Gather() |
| 3307 | require.NoError(t, err) |
| 3308 | require.NotEmpty(t, gathered) |
| 3309 | |
| 3310 | histogramMetricFamily := gathered[0] |
| 3311 | msg, err := MetricFamilyToProtobuf(histogramMetricFamily) |
| 3312 | require.NoError(t, err) |
| 3313 | |
| 3314 | now := time.Now() |
| 3315 | total, added, seriesAdded, err := app.append(msg, "application/vnd.google.protobuf", now) |
| 3316 | require.NoError(t, err) |
| 3317 | require.Equal(t, 3, total) |
no test coverage detected
searching dependent graphs…