(t *testing.T)
| 3523 | } |
| 3524 | |
| 3525 | func TestHeadLabelNamesValuesWithMinMaxRange(t *testing.T) { |
| 3526 | head, _ := newTestHead(t, 1000, compression.None, false) |
| 3527 | |
| 3528 | const ( |
| 3529 | firstSeriesTimestamp int64 = 100 |
| 3530 | secondSeriesTimestamp int64 = 200 |
| 3531 | lastSeriesTimestamp int64 = 300 |
| 3532 | ) |
| 3533 | var ( |
| 3534 | seriesTimestamps = []int64{ |
| 3535 | firstSeriesTimestamp, |
| 3536 | secondSeriesTimestamp, |
| 3537 | lastSeriesTimestamp, |
| 3538 | } |
| 3539 | expectedLabelNames = []string{"a", "b", "c"} |
| 3540 | expectedLabelValues = []string{"d", "e", "f"} |
| 3541 | ctx = context.Background() |
| 3542 | ) |
| 3543 | |
| 3544 | app := head.Appender(ctx) |
| 3545 | for i, name := range expectedLabelNames { |
| 3546 | _, err := app.Append(0, labels.FromStrings(name, expectedLabelValues[i]), seriesTimestamps[i], 0) |
| 3547 | require.NoError(t, err) |
| 3548 | } |
| 3549 | require.NoError(t, app.Commit()) |
| 3550 | require.Equal(t, firstSeriesTimestamp, head.MinTime()) |
| 3551 | require.Equal(t, lastSeriesTimestamp, head.MaxTime()) |
| 3552 | |
| 3553 | testCases := []struct { |
| 3554 | name string |
| 3555 | mint int64 |
| 3556 | maxt int64 |
| 3557 | expectedNames []string |
| 3558 | expectedValues []string |
| 3559 | }{ |
| 3560 | {"maxt less than head min", head.MaxTime() - 10, head.MinTime() - 10, []string{}, []string{}}, |
| 3561 | {"mint less than head max", head.MaxTime() + 10, head.MinTime() + 10, []string{}, []string{}}, |
| 3562 | {"mint and maxt outside head", head.MaxTime() + 10, head.MinTime() - 10, []string{}, []string{}}, |
| 3563 | {"mint and maxt within head", head.MaxTime() - 10, head.MinTime() + 10, expectedLabelNames, expectedLabelValues}, |
| 3564 | } |
| 3565 | |
| 3566 | for _, tt := range testCases { |
| 3567 | t.Run(tt.name, func(t *testing.T) { |
| 3568 | headIdxReader := head.indexRange(tt.mint, tt.maxt) |
| 3569 | actualLabelNames, err := headIdxReader.LabelNames(ctx) |
| 3570 | require.NoError(t, err) |
| 3571 | require.Equal(t, tt.expectedNames, actualLabelNames) |
| 3572 | if len(tt.expectedValues) > 0 { |
| 3573 | for i, name := range expectedLabelNames { |
| 3574 | actualLabelValue, err := headIdxReader.SortedLabelValues(ctx, name, nil) |
| 3575 | require.NoError(t, err) |
| 3576 | require.Equal(t, []string{tt.expectedValues[i]}, actualLabelValue) |
| 3577 | } |
| 3578 | } |
| 3579 | }) |
| 3580 | } |
| 3581 | } |
| 3582 |
nothing calls this directly
no test coverage detected
searching dependent graphs…