MCPcopy
hub / github.com/prometheus/prometheus / TestInconsistentHistogramCount

Function TestInconsistentHistogramCount

promql/engine_test.go:4593–4681  ·  view source on GitHub ↗

TestInconsistentHistogramCount is testing for https://github.com/prometheus/prometheus/issues/16681 which needs mixed integer and float histograms. The promql test framework only uses float histograms, so we cannot move this to promql tests.

(t *testing.T)

Source from the content-addressed store, hash-verified

4591// integer and float histograms. The promql test framework only uses float
4592// histograms, so we cannot move this to promql tests.
4593func TestInconsistentHistogramCount(t *testing.T) {
4594 dir := t.TempDir()
4595
4596 opts := tsdb.DefaultHeadOptions()
4597 opts.ChunkDirRoot = dir
4598 // We use TSDB head only. By using full TSDB DB, and appending samples to it, closing it would cause unnecessary HEAD compaction, which slows down the test.
4599 head, err := tsdb.NewHead(nil, nil, nil, nil, opts, nil)
4600 require.NoError(t, err)
4601 t.Cleanup(func() {
4602 _ = head.Close()
4603 })
4604
4605 app := head.Appender(context.Background())
4606
4607 l := labels.FromStrings("__name__", "series_1")
4608
4609 mint := time.Now().Add(-time.Hour).UnixMilli()
4610 maxt := mint
4611 dT := int64(15 * 1000) // 15 seconds in milliseconds.
4612 inHs := []*histogram.Histogram{
4613 {
4614 Count: 2,
4615 Sum: 100,
4616 PositiveSpans: []histogram.Span{
4617 {Offset: 0, Length: 1},
4618 },
4619 PositiveBuckets: []int64{2},
4620 },
4621 {
4622 Count: 4,
4623 Sum: 200,
4624 PositiveSpans: []histogram.Span{
4625 {Offset: 0, Length: 1},
4626 },
4627 PositiveBuckets: []int64{4},
4628 },
4629 {}, // Empty histogram to trigger counter reset.
4630 }
4631
4632 for i, h := range inHs {
4633 maxt = mint + dT*int64(i)
4634 _, err = app.AppendHistogram(0, l, maxt, h, nil)
4635 require.NoError(t, err)
4636 }
4637
4638 require.NoError(t, app.Commit())
4639 queryable := storage.QueryableFunc(func(mint, maxt int64) (storage.Querier, error) {
4640 return tsdb.NewBlockQuerier(head, mint, maxt)
4641 })
4642
4643 engine := promql.NewEngine(promql.EngineOpts{
4644 MaxSamples: 1000000,
4645 Timeout: 10 * time.Second,
4646 LookbackDelta: 5 * time.Minute,
4647 })
4648
4649 var (
4650 query promql.Query

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
AppenderMethod · 0.95
NewInstantQueryMethod · 0.95
DefaultHeadOptionsFunction · 0.92
NewHeadFunction · 0.92
FromStringsFunction · 0.92
QueryableFuncFuncType · 0.92
NewBlockQuerierFunction · 0.92
NewEngineFunction · 0.92
VectorMethod · 0.80
AddMethod · 0.65
AppendHistogramMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…