(t *testing.T, floatHistogram bool)
| 8592 | } |
| 8593 | |
| 8594 | func testHistogramAppendAndQueryHelper(t *testing.T, floatHistogram bool) { |
| 8595 | t.Helper() |
| 8596 | db := newTestDB(t) |
| 8597 | minute := func(m int) int64 { return int64(m) * time.Minute.Milliseconds() } |
| 8598 | |
| 8599 | ctx := context.Background() |
| 8600 | appendHistogram := func(t *testing.T, |
| 8601 | lbls labels.Labels, tsMinute int, h *histogram.Histogram, |
| 8602 | exp *[]chunks.Sample, expCRH histogram.CounterResetHint, |
| 8603 | ) { |
| 8604 | t.Helper() |
| 8605 | var err error |
| 8606 | app := db.Appender(ctx) |
| 8607 | if floatHistogram { |
| 8608 | _, err = app.AppendHistogram(0, lbls, minute(tsMinute), nil, h.ToFloat(nil)) |
| 8609 | efh := h.ToFloat(nil) |
| 8610 | efh.CounterResetHint = expCRH |
| 8611 | *exp = append(*exp, sample{t: minute(tsMinute), fh: efh}) |
| 8612 | } else { |
| 8613 | _, err = app.AppendHistogram(0, lbls, minute(tsMinute), h.Copy(), nil) |
| 8614 | eh := h.Copy() |
| 8615 | eh.CounterResetHint = expCRH |
| 8616 | *exp = append(*exp, sample{t: minute(tsMinute), h: eh}) |
| 8617 | } |
| 8618 | require.NoError(t, err) |
| 8619 | require.NoError(t, app.Commit()) |
| 8620 | } |
| 8621 | appendFloat := func(t *testing.T, lbls labels.Labels, tsMinute int, val float64, exp *[]chunks.Sample) { |
| 8622 | t.Helper() |
| 8623 | app := db.Appender(ctx) |
| 8624 | _, err := app.Append(0, lbls, minute(tsMinute), val) |
| 8625 | require.NoError(t, err) |
| 8626 | require.NoError(t, app.Commit()) |
| 8627 | *exp = append(*exp, sample{t: minute(tsMinute), f: val}) |
| 8628 | } |
| 8629 | |
| 8630 | testQuery := func(t *testing.T, name, value string, exp map[string][]chunks.Sample) { |
| 8631 | t.Helper() |
| 8632 | q, err := db.Querier(math.MinInt64, math.MaxInt64) |
| 8633 | require.NoError(t, err) |
| 8634 | act := query(t, q, labels.MustNewMatcher(labels.MatchRegexp, name, value)) |
| 8635 | require.Equal(t, exp, act) |
| 8636 | } |
| 8637 | |
| 8638 | baseH := &histogram.Histogram{ |
| 8639 | Count: 15, |
| 8640 | ZeroCount: 4, |
| 8641 | ZeroThreshold: 0.001, |
| 8642 | Sum: 35.5, |
| 8643 | Schema: 1, |
| 8644 | PositiveSpans: []histogram.Span{ |
| 8645 | {Offset: 0, Length: 2}, |
| 8646 | {Offset: 2, Length: 2}, |
| 8647 | }, |
| 8648 | PositiveBuckets: []int64{1, 1, -1, 0}, |
| 8649 | NegativeSpans: []histogram.Span{ |
| 8650 | {Offset: 0, Length: 1}, |
| 8651 | {Offset: 1, Length: 2}, |
no test coverage detected
searching dependent graphs…