(t *testing.T)
| 1516 | } |
| 1517 | |
| 1518 | func TestHeadCompactionWithHistograms(t *testing.T) { |
| 1519 | for _, floatTest := range []bool{true, false} { |
| 1520 | t.Run(fmt.Sprintf("float=%t", floatTest), func(t *testing.T) { |
| 1521 | head, _ := newTestHead(t, DefaultBlockDuration, compression.None, false) |
| 1522 | require.NoError(t, head.Init(0)) |
| 1523 | |
| 1524 | minute := func(m int) int64 { return int64(m) * time.Minute.Milliseconds() } |
| 1525 | ctx := context.Background() |
| 1526 | appendHistogram := func( |
| 1527 | lbls labels.Labels, from, to int, h *histogram.Histogram, exp *[]chunks.Sample, |
| 1528 | ) { |
| 1529 | t.Helper() |
| 1530 | app := head.Appender(ctx) |
| 1531 | for tsMinute := from; tsMinute <= to; tsMinute++ { |
| 1532 | var err error |
| 1533 | if floatTest { |
| 1534 | _, err = app.AppendHistogram(0, lbls, minute(tsMinute), nil, h.ToFloat(nil)) |
| 1535 | efh := h.ToFloat(nil) |
| 1536 | if tsMinute == from { |
| 1537 | efh.CounterResetHint = histogram.UnknownCounterReset |
| 1538 | } else { |
| 1539 | efh.CounterResetHint = histogram.NotCounterReset |
| 1540 | } |
| 1541 | *exp = append(*exp, sample{t: minute(tsMinute), fh: efh}) |
| 1542 | } else { |
| 1543 | _, err = app.AppendHistogram(0, lbls, minute(tsMinute), h, nil) |
| 1544 | eh := h.Copy() |
| 1545 | if tsMinute == from { |
| 1546 | eh.CounterResetHint = histogram.UnknownCounterReset |
| 1547 | } else { |
| 1548 | eh.CounterResetHint = histogram.NotCounterReset |
| 1549 | } |
| 1550 | *exp = append(*exp, sample{t: minute(tsMinute), h: eh}) |
| 1551 | } |
| 1552 | require.NoError(t, err) |
| 1553 | } |
| 1554 | require.NoError(t, app.Commit()) |
| 1555 | } |
| 1556 | appendFloat := func(lbls labels.Labels, from, to int, exp *[]chunks.Sample) { |
| 1557 | t.Helper() |
| 1558 | app := head.Appender(ctx) |
| 1559 | for tsMinute := from; tsMinute <= to; tsMinute++ { |
| 1560 | _, err := app.Append(0, lbls, minute(tsMinute), float64(tsMinute)) |
| 1561 | require.NoError(t, err) |
| 1562 | *exp = append(*exp, sample{t: minute(tsMinute), f: float64(tsMinute)}) |
| 1563 | } |
| 1564 | require.NoError(t, app.Commit()) |
| 1565 | } |
| 1566 | |
| 1567 | var ( |
| 1568 | series1 = labels.FromStrings("foo", "bar1") |
| 1569 | series2 = labels.FromStrings("foo", "bar2") |
| 1570 | series3 = labels.FromStrings("foo", "bar3") |
| 1571 | series4 = labels.FromStrings("foo", "bar4") |
| 1572 | exp1, exp2, exp3, exp4 []chunks.Sample |
| 1573 | ) |
| 1574 | h := &histogram.Histogram{ |
| 1575 | Count: 15, |
nothing calls this directly
no test coverage detected
searching dependent graphs…