2020-08-03 03:32:56 -07:00
|
|
|
// Copyright 2020 The Prometheus Authors
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
2023-09-12 03:37:38 -07:00
|
|
|
"context"
|
2022-07-01 09:59:50 -07:00
|
|
|
"errors"
|
2020-08-03 03:32:56 -07:00
|
|
|
"fmt"
|
|
|
|
"math"
|
|
|
|
"sort"
|
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
|
2020-10-29 02:43:23 -07:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-08-03 03:32:56 -07:00
|
|
|
|
2023-09-19 08:06:46 -07:00
|
|
|
"github.com/prometheus/prometheus/model/histogram"
|
2021-11-08 06:23:17 -08:00
|
|
|
"github.com/prometheus/prometheus/model/labels"
|
2020-08-03 03:32:56 -07:00
|
|
|
"github.com/prometheus/prometheus/tsdb/chunkenc"
|
2023-08-24 06:21:17 -07:00
|
|
|
"github.com/prometheus/prometheus/tsdb/chunks"
|
2020-08-03 03:32:56 -07:00
|
|
|
"github.com/prometheus/prometheus/tsdb/tsdbutil"
|
2023-09-14 09:57:31 -07:00
|
|
|
"github.com/prometheus/prometheus/util/annotations"
|
2020-08-03 03:32:56 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMergeQuerierWithChainMerger(t *testing.T) {
|
|
|
|
for _, tc := range []struct {
|
|
|
|
name string
|
|
|
|
primaryQuerierSeries []Series
|
|
|
|
querierSeries [][]Series
|
|
|
|
extraQueriers []Querier
|
|
|
|
|
|
|
|
expected SeriesSet
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "one primary querier with no series",
|
|
|
|
primaryQuerierSeries: []Series{},
|
|
|
|
expected: NewMockSeriesSet(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "one secondary querier with no series",
|
|
|
|
querierSeries: [][]Series{{}},
|
|
|
|
expected: NewMockSeriesSet(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "many secondary queriers with no series",
|
|
|
|
querierSeries: [][]Series{{}, {}, {}, {}, {}, {}, {}},
|
|
|
|
expected: NewMockSeriesSet(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mix of queriers with no series",
|
|
|
|
primaryQuerierSeries: []Series{},
|
|
|
|
querierSeries: [][]Series{{}, {}, {}, {}, {}, {}, {}},
|
|
|
|
expected: NewMockSeriesSet(),
|
|
|
|
},
|
|
|
|
// Test rest of cases on secondary queriers as the different between primary vs secondary is just error handling.
|
|
|
|
{
|
|
|
|
name: "one querier, two series",
|
|
|
|
querierSeries: [][]Series{{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListSeries(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}}),
|
|
|
|
NewListSeries(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{0, 0}, fSample{1, 1}, fSample{2, 2}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}},
|
|
|
|
expected: NewMockSeriesSet(
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListSeries(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}}),
|
|
|
|
NewListSeries(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{0, 0}, fSample{1, 1}, fSample{2, 2}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "two queriers, one different series each",
|
|
|
|
querierSeries: [][]Series{{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListSeries(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}, {
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListSeries(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{0, 0}, fSample{1, 1}, fSample{2, 2}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}},
|
|
|
|
expected: NewMockSeriesSet(
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListSeries(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}}),
|
|
|
|
NewListSeries(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{0, 0}, fSample{1, 1}, fSample{2, 2}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "two time unsorted queriers, two series each",
|
|
|
|
querierSeries: [][]Series{{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListSeries(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{5, 5}, fSample{6, 6}}),
|
|
|
|
NewListSeries(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{0, 0}, fSample{1, 1}, fSample{2, 2}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}, {
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListSeries(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}}),
|
|
|
|
NewListSeries(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{3, 3}, fSample{4, 4}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}},
|
|
|
|
expected: NewMockSeriesSet(
|
|
|
|
NewListSeries(
|
|
|
|
labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}, fSample{5, 5}, fSample{6, 6}},
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
NewListSeries(
|
|
|
|
labels.FromStrings("foo", "bar"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{fSample{0, 0}, fSample{1, 1}, fSample{2, 2}, fSample{3, 3}, fSample{4, 4}},
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "five queriers, only two queriers have two time unsorted series each",
|
|
|
|
querierSeries: [][]Series{{}, {}, {
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListSeries(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{5, 5}, fSample{6, 6}}),
|
|
|
|
NewListSeries(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{0, 0}, fSample{1, 1}, fSample{2, 2}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}, {
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListSeries(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}}),
|
|
|
|
NewListSeries(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{3, 3}, fSample{4, 4}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}, {}},
|
|
|
|
expected: NewMockSeriesSet(
|
|
|
|
NewListSeries(
|
|
|
|
labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}, fSample{5, 5}, fSample{6, 6}},
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
NewListSeries(
|
|
|
|
labels.FromStrings("foo", "bar"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{fSample{0, 0}, fSample{1, 1}, fSample{2, 2}, fSample{3, 3}, fSample{4, 4}},
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "two queriers, only two queriers have two time unsorted series each, with 3 noop and one nil querier together",
|
|
|
|
querierSeries: [][]Series{{}, {}, {
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListSeries(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{5, 5}, fSample{6, 6}}),
|
|
|
|
NewListSeries(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{0, 0}, fSample{1, 1}, fSample{2, 2}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}, {
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListSeries(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}}),
|
|
|
|
NewListSeries(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{3, 3}, fSample{4, 4}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}, {}},
|
|
|
|
extraQueriers: []Querier{NoopQuerier(), NoopQuerier(), nil, NoopQuerier()},
|
|
|
|
expected: NewMockSeriesSet(
|
|
|
|
NewListSeries(
|
|
|
|
labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}, fSample{5, 5}, fSample{6, 6}},
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
NewListSeries(
|
|
|
|
labels.FromStrings("foo", "bar"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{fSample{0, 0}, fSample{1, 1}, fSample{2, 2}, fSample{3, 3}, fSample{4, 4}},
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "two queriers, with two series, one is overlapping",
|
|
|
|
querierSeries: [][]Series{{}, {}, {
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListSeries(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{2, 21}, fSample{3, 31}, fSample{5, 5}, fSample{6, 6}}),
|
|
|
|
NewListSeries(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{0, 0}, fSample{1, 1}, fSample{2, 2}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}, {
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListSeries(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 22}, fSample{3, 32}}),
|
|
|
|
NewListSeries(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{3, 3}, fSample{4, 4}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}, {}},
|
|
|
|
expected: NewMockSeriesSet(
|
|
|
|
NewListSeries(
|
|
|
|
labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{fSample{1, 1}, fSample{2, 21}, fSample{3, 31}, fSample{5, 5}, fSample{6, 6}},
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
NewListSeries(
|
|
|
|
labels.FromStrings("foo", "bar"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{fSample{0, 0}, fSample{1, 1}, fSample{2, 2}, fSample{3, 3}, fSample{4, 4}},
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "two queries, one with NaN samples series",
|
|
|
|
querierSeries: [][]Series{{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListSeries(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{0, math.NaN()}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}, {
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListSeries(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{1, 1}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}},
|
|
|
|
expected: NewMockSeriesSet(
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListSeries(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{0, math.NaN()}, fSample{1, 1}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
var p Querier
|
|
|
|
if tc.primaryQuerierSeries != nil {
|
|
|
|
p = &mockQuerier{toReturn: tc.primaryQuerierSeries}
|
|
|
|
}
|
|
|
|
var qs []Querier
|
|
|
|
for _, in := range tc.querierSeries {
|
|
|
|
qs = append(qs, &mockQuerier{toReturn: in})
|
|
|
|
}
|
|
|
|
qs = append(qs, tc.extraQueriers...)
|
|
|
|
|
2023-09-12 03:37:38 -07:00
|
|
|
mergedQuerier := NewMergeQuerier([]Querier{p}, qs, ChainedSeriesMerge).Select(context.Background(), false, nil)
|
2020-08-03 03:32:56 -07:00
|
|
|
|
|
|
|
// Get all merged series upfront to make sure there are no incorrectly retained shared
|
|
|
|
// buffers causing bugs.
|
|
|
|
var mergedSeries []Series
|
|
|
|
for mergedQuerier.Next() {
|
|
|
|
mergedSeries = append(mergedSeries, mergedQuerier.At())
|
|
|
|
}
|
2020-10-29 02:43:23 -07:00
|
|
|
require.NoError(t, mergedQuerier.Err())
|
2020-08-03 03:32:56 -07:00
|
|
|
|
|
|
|
for _, actualSeries := range mergedSeries {
|
2020-10-29 02:43:23 -07:00
|
|
|
require.True(t, tc.expected.Next(), "Expected Next() to be true")
|
2020-08-03 03:32:56 -07:00
|
|
|
expectedSeries := tc.expected.At()
|
2020-10-29 02:43:23 -07:00
|
|
|
require.Equal(t, expectedSeries.Labels(), actualSeries.Labels())
|
2020-08-03 03:32:56 -07:00
|
|
|
|
2022-09-20 10:16:45 -07:00
|
|
|
expSmpl, expErr := ExpandSamples(expectedSeries.Iterator(nil), nil)
|
|
|
|
actSmpl, actErr := ExpandSamples(actualSeries.Iterator(nil), nil)
|
2020-10-29 02:43:23 -07:00
|
|
|
require.Equal(t, expErr, actErr)
|
|
|
|
require.Equal(t, expSmpl, actSmpl)
|
2020-08-03 03:32:56 -07:00
|
|
|
}
|
2020-10-29 02:43:23 -07:00
|
|
|
require.False(t, tc.expected.Next(), "Expected Next() to be false")
|
2020-08-03 03:32:56 -07:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMergeChunkQuerierWithNoVerticalChunkSeriesMerger(t *testing.T) {
|
|
|
|
for _, tc := range []struct {
|
|
|
|
name string
|
|
|
|
primaryChkQuerierSeries []ChunkSeries
|
|
|
|
chkQuerierSeries [][]ChunkSeries
|
|
|
|
extraQueriers []ChunkQuerier
|
|
|
|
|
|
|
|
expected ChunkSeriesSet
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "one primary querier with no series",
|
|
|
|
primaryChkQuerierSeries: []ChunkSeries{},
|
|
|
|
expected: NewMockChunkSeriesSet(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "one secondary querier with no series",
|
|
|
|
chkQuerierSeries: [][]ChunkSeries{{}},
|
|
|
|
expected: NewMockChunkSeriesSet(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "many secondary queriers with no series",
|
|
|
|
chkQuerierSeries: [][]ChunkSeries{{}, {}, {}, {}, {}, {}, {}},
|
|
|
|
expected: NewMockChunkSeriesSet(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mix of queriers with no series",
|
|
|
|
primaryChkQuerierSeries: []ChunkSeries{},
|
|
|
|
chkQuerierSeries: [][]ChunkSeries{{}, {}, {}, {}, {}, {}, {}},
|
|
|
|
expected: NewMockChunkSeriesSet(),
|
|
|
|
},
|
|
|
|
// Test rest of cases on secondary queriers as the different between primary vs secondary is just error handling.
|
|
|
|
{
|
|
|
|
name: "one querier, two series",
|
|
|
|
chkQuerierSeries: [][]ChunkSeries{{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}}, []chunks.Sample{fSample{3, 3}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{0, 0}, fSample{1, 1}}, []chunks.Sample{fSample{2, 2}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}},
|
|
|
|
expected: NewMockChunkSeriesSet(
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}}, []chunks.Sample{fSample{3, 3}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{0, 0}, fSample{1, 1}}, []chunks.Sample{fSample{2, 2}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "two secondaries, one different series each",
|
|
|
|
chkQuerierSeries: [][]ChunkSeries{{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}}, []chunks.Sample{fSample{3, 3}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}, {
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{0, 0}, fSample{1, 1}}, []chunks.Sample{fSample{2, 2}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}},
|
|
|
|
expected: NewMockChunkSeriesSet(
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}}, []chunks.Sample{fSample{3, 3}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{0, 0}, fSample{1, 1}}, []chunks.Sample{fSample{2, 2}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "two secondaries, two not in time order series each",
|
|
|
|
chkQuerierSeries: [][]ChunkSeries{{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{5, 5}}, []chunks.Sample{fSample{6, 6}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{0, 0}, fSample{1, 1}}, []chunks.Sample{fSample{2, 2}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}, {
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}}, []chunks.Sample{fSample{3, 3}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{3, 3}}, []chunks.Sample{fSample{4, 4}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}},
|
|
|
|
expected: NewMockChunkSeriesSet(
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{fSample{1, 1}, fSample{2, 2}},
|
|
|
|
[]chunks.Sample{fSample{3, 3}},
|
|
|
|
[]chunks.Sample{fSample{5, 5}},
|
|
|
|
[]chunks.Sample{fSample{6, 6}},
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("foo", "bar"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{fSample{0, 0}, fSample{1, 1}},
|
|
|
|
[]chunks.Sample{fSample{2, 2}},
|
|
|
|
[]chunks.Sample{fSample{3, 3}},
|
|
|
|
[]chunks.Sample{fSample{4, 4}},
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "five secondaries, only two have two not in time order series each",
|
|
|
|
chkQuerierSeries: [][]ChunkSeries{{}, {}, {
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{5, 5}}, []chunks.Sample{fSample{6, 6}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{0, 0}, fSample{1, 1}}, []chunks.Sample{fSample{2, 2}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}, {
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}}, []chunks.Sample{fSample{3, 3}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{3, 3}}, []chunks.Sample{fSample{4, 4}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}, {}},
|
|
|
|
expected: NewMockChunkSeriesSet(
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{fSample{1, 1}, fSample{2, 2}},
|
|
|
|
[]chunks.Sample{fSample{3, 3}},
|
|
|
|
[]chunks.Sample{fSample{5, 5}},
|
|
|
|
[]chunks.Sample{fSample{6, 6}},
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("foo", "bar"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{fSample{0, 0}, fSample{1, 1}},
|
|
|
|
[]chunks.Sample{fSample{2, 2}},
|
|
|
|
[]chunks.Sample{fSample{3, 3}},
|
|
|
|
[]chunks.Sample{fSample{4, 4}},
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "two secondaries, with two not in time order series each, with 3 noop queries and one nil together",
|
|
|
|
chkQuerierSeries: [][]ChunkSeries{{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{5, 5}}, []chunks.Sample{fSample{6, 6}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{0, 0}, fSample{1, 1}}, []chunks.Sample{fSample{2, 2}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}, {
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}}, []chunks.Sample{fSample{3, 3}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{3, 3}}, []chunks.Sample{fSample{4, 4}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}},
|
|
|
|
extraQueriers: []ChunkQuerier{NoopChunkedQuerier(), NoopChunkedQuerier(), nil, NoopChunkedQuerier()},
|
|
|
|
expected: NewMockChunkSeriesSet(
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{fSample{1, 1}, fSample{2, 2}},
|
|
|
|
[]chunks.Sample{fSample{3, 3}},
|
|
|
|
[]chunks.Sample{fSample{5, 5}},
|
|
|
|
[]chunks.Sample{fSample{6, 6}},
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("foo", "bar"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{fSample{0, 0}, fSample{1, 1}},
|
|
|
|
[]chunks.Sample{fSample{2, 2}},
|
|
|
|
[]chunks.Sample{fSample{3, 3}},
|
|
|
|
[]chunks.Sample{fSample{4, 4}},
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "two queries, one with NaN samples series",
|
|
|
|
chkQuerierSeries: [][]ChunkSeries{{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{0, math.NaN()}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}, {
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{1, 1}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
}},
|
|
|
|
expected: NewMockChunkSeriesSet(
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("foo", "bar"), []chunks.Sample{fSample{0, math.NaN()}}, []chunks.Sample{fSample{1, 1}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
var p ChunkQuerier
|
|
|
|
if tc.primaryChkQuerierSeries != nil {
|
|
|
|
p = &mockChunkQurier{toReturn: tc.primaryChkQuerierSeries}
|
|
|
|
}
|
|
|
|
|
|
|
|
var qs []ChunkQuerier
|
|
|
|
for _, in := range tc.chkQuerierSeries {
|
|
|
|
qs = append(qs, &mockChunkQurier{toReturn: in})
|
|
|
|
}
|
|
|
|
qs = append(qs, tc.extraQueriers...)
|
|
|
|
|
2023-09-12 03:37:38 -07:00
|
|
|
merged := NewMergeChunkQuerier([]ChunkQuerier{p}, qs, NewCompactingChunkSeriesMerger(nil)).Select(context.Background(), false, nil)
|
2020-08-03 03:32:56 -07:00
|
|
|
for merged.Next() {
|
2020-10-29 02:43:23 -07:00
|
|
|
require.True(t, tc.expected.Next(), "Expected Next() to be true")
|
2020-08-03 03:32:56 -07:00
|
|
|
actualSeries := merged.At()
|
|
|
|
expectedSeries := tc.expected.At()
|
2020-10-29 02:43:23 -07:00
|
|
|
require.Equal(t, expectedSeries.Labels(), actualSeries.Labels())
|
2020-08-03 03:32:56 -07:00
|
|
|
|
2022-09-20 10:16:45 -07:00
|
|
|
expChks, expErr := ExpandChunks(expectedSeries.Iterator(nil))
|
|
|
|
actChks, actErr := ExpandChunks(actualSeries.Iterator(nil))
|
2020-10-29 02:43:23 -07:00
|
|
|
require.Equal(t, expErr, actErr)
|
|
|
|
require.Equal(t, expChks, actChks)
|
2020-08-03 03:32:56 -07:00
|
|
|
|
|
|
|
}
|
2020-10-29 02:43:23 -07:00
|
|
|
require.NoError(t, merged.Err())
|
|
|
|
require.False(t, tc.expected.Next(), "Expected Next() to be false")
|
2020-08-03 03:32:56 -07:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-19 08:06:46 -07:00
|
|
|
func histogramSample(ts int64, hint histogram.CounterResetHint) hSample {
|
|
|
|
h := tsdbutil.GenerateTestHistogram(int(ts + 1))
|
|
|
|
h.CounterResetHint = hint
|
|
|
|
return hSample{t: ts, h: h}
|
|
|
|
}
|
|
|
|
|
|
|
|
func floatHistogramSample(ts int64, hint histogram.CounterResetHint) fhSample {
|
|
|
|
fh := tsdbutil.GenerateTestFloatHistogram(int(ts + 1))
|
|
|
|
fh.CounterResetHint = hint
|
|
|
|
return fhSample{t: ts, fh: fh}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shorthands for counter reset hints.
|
|
|
|
const (
|
|
|
|
uk = histogram.UnknownCounterReset
|
|
|
|
cr = histogram.CounterReset
|
|
|
|
nr = histogram.NotCounterReset
|
|
|
|
ga = histogram.GaugeType
|
|
|
|
)
|
|
|
|
|
2020-08-03 03:32:56 -07:00
|
|
|
func TestCompactingChunkSeriesMerger(t *testing.T) {
|
|
|
|
m := NewCompactingChunkSeriesMerger(ChainedSeriesMerge)
|
|
|
|
|
2022-08-22 06:34:39 -07:00
|
|
|
// histogramSample returns a histogram that is unique to the ts.
|
2022-12-08 04:31:08 -08:00
|
|
|
histogramSample := func(ts int64) hSample {
|
2023-09-19 08:06:46 -07:00
|
|
|
return histogramSample(ts, uk)
|
2023-02-10 03:39:33 -08:00
|
|
|
}
|
|
|
|
|
2022-12-08 04:31:08 -08:00
|
|
|
floatHistogramSample := func(ts int64) fhSample {
|
2023-09-19 08:06:46 -07:00
|
|
|
return floatHistogramSample(ts, uk)
|
2022-08-22 06:34:39 -07:00
|
|
|
}
|
|
|
|
|
2020-08-03 03:32:56 -07:00
|
|
|
for _, tc := range []struct {
|
|
|
|
name string
|
|
|
|
input []ChunkSeries
|
|
|
|
expected ChunkSeries
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "single empty series",
|
|
|
|
input: []ChunkSeries{
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), nil),
|
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), nil),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "single series",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}}, []chunks.Sample{fSample{3, 3}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
2023-08-24 06:21:17 -07:00
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}}, []chunks.Sample{fSample{3, 3}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "two empty series",
|
|
|
|
input: []ChunkSeries{
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), nil),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), nil),
|
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), nil),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "two non overlapping",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}}, []chunks.Sample{fSample{3, 3}, fSample{5, 5}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{7, 7}, fSample{9, 9}}, []chunks.Sample{fSample{10, 10}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
2023-08-24 06:21:17 -07:00
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}}, []chunks.Sample{fSample{3, 3}, fSample{5, 5}}, []chunks.Sample{fSample{7, 7}, fSample{9, 9}}, []chunks.Sample{fSample{10, 10}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "two overlapping",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}}, []chunks.Sample{fSample{3, 3}, fSample{8, 8}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{7, 7}, fSample{9, 9}}, []chunks.Sample{fSample{10, 10}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
2023-08-24 06:21:17 -07:00
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}}, []chunks.Sample{fSample{3, 3}, fSample{7, 7}, fSample{8, 8}, fSample{9, 9}}, []chunks.Sample{fSample{10, 10}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "two duplicated",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}, fSample{5, 5}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{2, 2}, fSample{3, 3}, fSample{5, 5}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
2023-08-24 06:21:17 -07:00
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}, fSample{5, 5}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "three overlapping",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}, fSample{5, 5}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{2, 2}, fSample{3, 3}, fSample{6, 6}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{0, 0}, fSample{4, 4}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
2023-08-24 06:21:17 -07:00
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{0, 0}, fSample{1, 1}, fSample{2, 2}, fSample{3, 3}, fSample{4, 4}, fSample{5, 5}, fSample{6, 6}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "three in chained overlap",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}, fSample{5, 5}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{4, 4}, fSample{6, 66}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{6, 6}, fSample{10, 10}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
2023-08-24 06:21:17 -07:00
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}, fSample{4, 4}, fSample{5, 5}, fSample{6, 66}, fSample{10, 10}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "three in chained overlap complex",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{0, 0}, fSample{5, 5}}, []chunks.Sample{fSample{10, 10}, fSample{15, 15}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{2, 2}, fSample{20, 20}}, []chunks.Sample{fSample{25, 25}, fSample{30, 30}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{18, 18}, fSample{26, 26}}, []chunks.Sample{fSample{31, 31}, fSample{35, 35}}),
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{fSample{0, 0}, fSample{2, 2}, fSample{5, 5}, fSample{10, 10}, fSample{15, 15}, fSample{18, 18}, fSample{20, 20}, fSample{25, 25}, fSample{26, 26}, fSample{30, 30}},
|
|
|
|
[]chunks.Sample{fSample{31, 31}, fSample{35, 35}},
|
2020-08-03 03:32:56 -07:00
|
|
|
),
|
|
|
|
},
|
2021-05-18 09:37:16 -07:00
|
|
|
{
|
|
|
|
name: "110 overlapping",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), chunks.GenerateSamples(0, 110)), // [0 - 110)
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), chunks.GenerateSamples(60, 50)), // [60 - 110)
|
2021-05-18 09:37:16 -07:00
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
chunks.GenerateSamples(0, 110),
|
2021-05-18 09:37:16 -07:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "150 overlapping samples, split chunk",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), chunks.GenerateSamples(0, 90)), // [0 - 90)
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), chunks.GenerateSamples(60, 90)), // [90 - 150)
|
2021-05-18 09:37:16 -07:00
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
chunks.GenerateSamples(0, 120),
|
|
|
|
chunks.GenerateSamples(120, 30),
|
2021-05-18 09:37:16 -07:00
|
|
|
),
|
|
|
|
},
|
2022-08-22 06:34:39 -07:00
|
|
|
{
|
|
|
|
name: "histogram chunks overlapping",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{histogramSample(0), histogramSample(5)}, []chunks.Sample{histogramSample(10), histogramSample(15)}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{histogramSample(2), histogramSample(20)}, []chunks.Sample{histogramSample(25), histogramSample(30)}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{histogramSample(18), histogramSample(26)}, []chunks.Sample{histogramSample(31), histogramSample(35)}),
|
2022-08-22 06:34:39 -07:00
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{histogramSample(0), histogramSample(2), histogramSample(5), histogramSample(10), histogramSample(15), histogramSample(18), histogramSample(20), histogramSample(25), histogramSample(26), histogramSample(30)},
|
|
|
|
[]chunks.Sample{histogramSample(31), histogramSample(35)},
|
2022-08-22 06:34:39 -07:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "histogram chunks overlapping with float chunks",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{histogramSample(0), histogramSample(5)}, []chunks.Sample{histogramSample(10), histogramSample(15)}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{12, 12}}, []chunks.Sample{fSample{14, 14}}),
|
2022-08-22 06:34:39 -07:00
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{histogramSample(0)},
|
|
|
|
[]chunks.Sample{fSample{1, 1}},
|
|
|
|
[]chunks.Sample{histogramSample(5), histogramSample(10)},
|
|
|
|
[]chunks.Sample{fSample{12, 12}, fSample{14, 14}},
|
|
|
|
[]chunks.Sample{histogramSample(15)},
|
2022-08-22 06:34:39 -07:00
|
|
|
),
|
|
|
|
},
|
2023-02-10 03:39:33 -08:00
|
|
|
{
|
|
|
|
name: "float histogram chunks overlapping",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{floatHistogramSample(0), floatHistogramSample(5)}, []chunks.Sample{floatHistogramSample(10), floatHistogramSample(15)}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{floatHistogramSample(2), floatHistogramSample(20)}, []chunks.Sample{floatHistogramSample(25), floatHistogramSample(30)}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{floatHistogramSample(18), floatHistogramSample(26)}, []chunks.Sample{floatHistogramSample(31), floatHistogramSample(35)}),
|
2023-02-10 03:39:33 -08:00
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{floatHistogramSample(0), floatHistogramSample(2), floatHistogramSample(5), floatHistogramSample(10), floatHistogramSample(15), floatHistogramSample(18), floatHistogramSample(20), floatHistogramSample(25), floatHistogramSample(26), floatHistogramSample(30)},
|
|
|
|
[]chunks.Sample{floatHistogramSample(31), floatHistogramSample(35)},
|
2023-02-10 03:39:33 -08:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "float histogram chunks overlapping with float chunks",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{floatHistogramSample(0), floatHistogramSample(5)}, []chunks.Sample{floatHistogramSample(10), floatHistogramSample(15)}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{12, 12}}, []chunks.Sample{fSample{14, 14}}),
|
2023-02-10 03:39:33 -08:00
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{floatHistogramSample(0)},
|
|
|
|
[]chunks.Sample{fSample{1, 1}},
|
|
|
|
[]chunks.Sample{floatHistogramSample(5), floatHistogramSample(10)},
|
|
|
|
[]chunks.Sample{fSample{12, 12}, fSample{14, 14}},
|
|
|
|
[]chunks.Sample{floatHistogramSample(15)},
|
2023-02-10 03:39:33 -08:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "float histogram chunks overlapping with histogram chunks",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{floatHistogramSample(0), floatHistogramSample(5)}, []chunks.Sample{floatHistogramSample(10), floatHistogramSample(15)}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{histogramSample(1), histogramSample(12)}, []chunks.Sample{histogramSample(14)}),
|
2023-02-10 03:39:33 -08:00
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{floatHistogramSample(0)},
|
|
|
|
[]chunks.Sample{histogramSample(1)},
|
|
|
|
[]chunks.Sample{floatHistogramSample(5), floatHistogramSample(10)},
|
|
|
|
[]chunks.Sample{histogramSample(12), histogramSample(14)},
|
|
|
|
[]chunks.Sample{floatHistogramSample(15)},
|
2023-02-10 03:39:33 -08:00
|
|
|
),
|
|
|
|
},
|
2020-08-03 03:32:56 -07:00
|
|
|
} {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
merged := m(tc.input...)
|
2020-10-29 02:43:23 -07:00
|
|
|
require.Equal(t, tc.expected.Labels(), merged.Labels())
|
2022-09-20 10:16:45 -07:00
|
|
|
actChks, actErr := ExpandChunks(merged.Iterator(nil))
|
|
|
|
expChks, expErr := ExpandChunks(tc.expected.Iterator(nil))
|
2020-08-03 03:32:56 -07:00
|
|
|
|
2020-10-29 02:43:23 -07:00
|
|
|
require.Equal(t, expErr, actErr)
|
|
|
|
require.Equal(t, expChks, actChks)
|
2023-09-19 08:06:46 -07:00
|
|
|
|
|
|
|
actSamples := chunks.ChunkMetasToSamples(actChks)
|
|
|
|
expSamples := chunks.ChunkMetasToSamples(expChks)
|
|
|
|
require.Equal(t, expSamples, actSamples)
|
2020-08-03 03:32:56 -07:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-19 08:06:46 -07:00
|
|
|
func TestCompactingChunkSeriesMergerHistogramCounterResetHint(t *testing.T) {
|
|
|
|
m := NewCompactingChunkSeriesMerger(ChainedSeriesMerge)
|
|
|
|
|
|
|
|
for sampleType, sampleFunc := range map[string]func(int64, histogram.CounterResetHint) chunks.Sample{
|
|
|
|
"histogram": func(ts int64, hint histogram.CounterResetHint) chunks.Sample { return histogramSample(ts, hint) },
|
|
|
|
"float histogram": func(ts int64, hint histogram.CounterResetHint) chunks.Sample { return floatHistogramSample(ts, hint) },
|
|
|
|
} {
|
|
|
|
for name, tc := range map[string]struct {
|
|
|
|
input []ChunkSeries
|
|
|
|
expected ChunkSeries
|
|
|
|
}{
|
|
|
|
"histogram counter reset hint kept in single series": {
|
|
|
|
input: []ChunkSeries{
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
|
|
|
[]chunks.Sample{sampleFunc(0, cr), sampleFunc(5, uk)},
|
|
|
|
[]chunks.Sample{sampleFunc(10, cr), sampleFunc(15, uk)},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
|
|
|
[]chunks.Sample{sampleFunc(0, cr), sampleFunc(5, uk)},
|
|
|
|
[]chunks.Sample{sampleFunc(10, cr), sampleFunc(15, uk)},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
"histogram not counter reset hint kept in single series": {
|
|
|
|
input: []ChunkSeries{
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
|
|
|
[]chunks.Sample{sampleFunc(0, nr), sampleFunc(5, uk)},
|
|
|
|
[]chunks.Sample{sampleFunc(10, nr), sampleFunc(15, uk)},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
|
|
|
[]chunks.Sample{sampleFunc(0, nr), sampleFunc(5, uk)},
|
|
|
|
[]chunks.Sample{sampleFunc(10, nr), sampleFunc(15, uk)},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
"histogram counter reset hint kept in multiple equal series": {
|
|
|
|
input: []ChunkSeries{
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
|
|
|
[]chunks.Sample{sampleFunc(0, cr), sampleFunc(5, uk)},
|
|
|
|
[]chunks.Sample{sampleFunc(10, cr), sampleFunc(15, uk)},
|
|
|
|
),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
|
|
|
[]chunks.Sample{sampleFunc(0, cr), sampleFunc(5, uk)},
|
|
|
|
[]chunks.Sample{sampleFunc(10, cr), sampleFunc(15, uk)},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
|
|
|
[]chunks.Sample{sampleFunc(0, cr), sampleFunc(5, uk)},
|
|
|
|
[]chunks.Sample{sampleFunc(10, cr), sampleFunc(15, uk)},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
"histogram not counter reset hint kept in multiple equal series": {
|
|
|
|
input: []ChunkSeries{
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
|
|
|
[]chunks.Sample{sampleFunc(0, nr), sampleFunc(5, uk)},
|
|
|
|
[]chunks.Sample{sampleFunc(10, nr), sampleFunc(15, uk)},
|
|
|
|
),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
|
|
|
[]chunks.Sample{sampleFunc(0, nr), sampleFunc(5, uk)},
|
|
|
|
[]chunks.Sample{sampleFunc(10, nr), sampleFunc(15, uk)},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
|
|
|
[]chunks.Sample{sampleFunc(0, nr), sampleFunc(5, uk)},
|
|
|
|
[]chunks.Sample{sampleFunc(10, nr), sampleFunc(15, uk)},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
"histogram counter reset hint dropped from differing series": {
|
|
|
|
input: []ChunkSeries{
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
|
|
|
[]chunks.Sample{sampleFunc(0, cr), sampleFunc(5, uk)},
|
|
|
|
[]chunks.Sample{sampleFunc(10, cr), sampleFunc(15, uk)},
|
|
|
|
),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
|
|
|
[]chunks.Sample{sampleFunc(0, cr), sampleFunc(5, uk)},
|
|
|
|
[]chunks.Sample{sampleFunc(10, cr), sampleFunc(12, uk), sampleFunc(15, uk)},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
|
|
|
[]chunks.Sample{sampleFunc(0, cr), sampleFunc(5, uk)},
|
|
|
|
[]chunks.Sample{sampleFunc(10, uk), sampleFunc(12, uk), sampleFunc(15, uk)},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
"histogram counter not reset hint dropped from differing series": {
|
|
|
|
input: []ChunkSeries{
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
|
|
|
[]chunks.Sample{sampleFunc(0, nr), sampleFunc(5, uk)},
|
|
|
|
[]chunks.Sample{sampleFunc(10, nr), sampleFunc(15, uk)},
|
|
|
|
),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
|
|
|
[]chunks.Sample{sampleFunc(0, nr), sampleFunc(5, uk)},
|
|
|
|
[]chunks.Sample{sampleFunc(10, nr), sampleFunc(12, uk), sampleFunc(15, uk)},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
|
|
|
[]chunks.Sample{sampleFunc(0, nr), sampleFunc(5, uk)},
|
|
|
|
[]chunks.Sample{sampleFunc(10, uk), sampleFunc(12, uk), sampleFunc(15, uk)},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run(sampleType+"/"+name, func(t *testing.T) {
|
|
|
|
merged := m(tc.input...)
|
|
|
|
require.Equal(t, tc.expected.Labels(), merged.Labels())
|
|
|
|
actChks, actErr := ExpandChunks(merged.Iterator(nil))
|
|
|
|
expChks, expErr := ExpandChunks(tc.expected.Iterator(nil))
|
|
|
|
|
|
|
|
require.Equal(t, expErr, actErr)
|
|
|
|
require.Equal(t, expChks, actChks)
|
|
|
|
|
|
|
|
actSamples := chunks.ChunkMetasToSamples(actChks)
|
|
|
|
expSamples := chunks.ChunkMetasToSamples(expChks)
|
|
|
|
require.Equal(t, expSamples, actSamples)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-20 10:05:50 -07:00
|
|
|
func TestConcatenatingChunkSeriesMerger(t *testing.T) {
|
|
|
|
m := NewConcatenatingChunkSeriesMerger()
|
|
|
|
|
|
|
|
for _, tc := range []struct {
|
|
|
|
name string
|
|
|
|
input []ChunkSeries
|
|
|
|
expected ChunkSeries
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "single empty series",
|
|
|
|
input: []ChunkSeries{
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), nil),
|
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), nil),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "single series",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}}, []chunks.Sample{fSample{3, 3}}),
|
2022-09-20 10:05:50 -07:00
|
|
|
},
|
2023-08-24 06:21:17 -07:00
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}}, []chunks.Sample{fSample{3, 3}}),
|
2022-09-20 10:05:50 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "two empty series",
|
|
|
|
input: []ChunkSeries{
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), nil),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), nil),
|
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), nil, nil),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "two non overlapping",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}}, []chunks.Sample{fSample{3, 3}, fSample{5, 5}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{7, 7}, fSample{9, 9}}, []chunks.Sample{fSample{10, 10}}),
|
2022-09-20 10:05:50 -07:00
|
|
|
},
|
2023-08-24 06:21:17 -07:00
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}}, []chunks.Sample{fSample{3, 3}, fSample{5, 5}}, []chunks.Sample{fSample{7, 7}, fSample{9, 9}}, []chunks.Sample{fSample{10, 10}}),
|
2022-09-20 10:05:50 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "two overlapping",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}}, []chunks.Sample{fSample{3, 3}, fSample{8, 8}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{7, 7}, fSample{9, 9}}, []chunks.Sample{fSample{10, 10}}),
|
2022-09-20 10:05:50 -07:00
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{fSample{1, 1}, fSample{2, 2}}, []chunks.Sample{fSample{3, 3}, fSample{8, 8}},
|
|
|
|
[]chunks.Sample{fSample{7, 7}, fSample{9, 9}}, []chunks.Sample{fSample{10, 10}},
|
2022-09-20 10:05:50 -07:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "two duplicated",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}, fSample{5, 5}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{2, 2}, fSample{3, 3}, fSample{5, 5}}),
|
2022-09-20 10:05:50 -07:00
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}, fSample{5, 5}},
|
|
|
|
[]chunks.Sample{fSample{2, 2}, fSample{3, 3}, fSample{5, 5}},
|
2022-09-20 10:05:50 -07:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "three overlapping",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}, fSample{5, 5}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{2, 2}, fSample{3, 3}, fSample{6, 6}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{0, 0}, fSample{4, 4}}),
|
2022-09-20 10:05:50 -07:00
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}, fSample{5, 5}},
|
|
|
|
[]chunks.Sample{fSample{2, 2}, fSample{3, 3}, fSample{6, 6}},
|
|
|
|
[]chunks.Sample{fSample{0, 0}, fSample{4, 4}},
|
2022-09-20 10:05:50 -07:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "three in chained overlap",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}, fSample{5, 5}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{4, 4}, fSample{6, 66}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{6, 6}, fSample{10, 10}}),
|
2022-09-20 10:05:50 -07:00
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{fSample{1, 1}, fSample{2, 2}, fSample{3, 3}, fSample{5, 5}},
|
|
|
|
[]chunks.Sample{fSample{4, 4}, fSample{6, 66}},
|
|
|
|
[]chunks.Sample{fSample{6, 6}, fSample{10, 10}},
|
2022-09-20 10:05:50 -07:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "three in chained overlap complex",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{0, 0}, fSample{5, 5}}, []chunks.Sample{fSample{10, 10}, fSample{15, 15}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{2, 2}, fSample{20, 20}}, []chunks.Sample{fSample{25, 25}, fSample{30, 30}}),
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), []chunks.Sample{fSample{18, 18}, fSample{26, 26}}, []chunks.Sample{fSample{31, 31}, fSample{35, 35}}),
|
2022-09-20 10:05:50 -07:00
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
[]chunks.Sample{fSample{0, 0}, fSample{5, 5}}, []chunks.Sample{fSample{10, 10}, fSample{15, 15}},
|
|
|
|
[]chunks.Sample{fSample{2, 2}, fSample{20, 20}}, []chunks.Sample{fSample{25, 25}, fSample{30, 30}},
|
|
|
|
[]chunks.Sample{fSample{18, 18}, fSample{26, 26}}, []chunks.Sample{fSample{31, 31}, fSample{35, 35}},
|
2022-09-20 10:05:50 -07:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "110 overlapping",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), chunks.GenerateSamples(0, 110)), // [0 - 110)
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), chunks.GenerateSamples(60, 50)), // [60 - 110)
|
2022-09-20 10:05:50 -07:00
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
chunks.GenerateSamples(0, 110),
|
|
|
|
chunks.GenerateSamples(60, 50),
|
2022-09-20 10:05:50 -07:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "150 overlapping samples, simply concatenated and no splits",
|
|
|
|
input: []ChunkSeries{
|
2023-08-24 06:21:17 -07:00
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), chunks.GenerateSamples(0, 90)), // [0 - 90)
|
|
|
|
NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"), chunks.GenerateSamples(60, 90)), // [90 - 150)
|
2022-09-20 10:05:50 -07:00
|
|
|
},
|
|
|
|
expected: NewListChunkSeriesFromSamples(labels.FromStrings("bar", "baz"),
|
2023-08-24 06:21:17 -07:00
|
|
|
chunks.GenerateSamples(0, 90),
|
|
|
|
chunks.GenerateSamples(60, 90),
|
2022-09-20 10:05:50 -07:00
|
|
|
),
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
merged := m(tc.input...)
|
|
|
|
require.Equal(t, tc.expected.Labels(), merged.Labels())
|
2022-09-20 10:16:45 -07:00
|
|
|
actChks, actErr := ExpandChunks(merged.Iterator(nil))
|
|
|
|
expChks, expErr := ExpandChunks(tc.expected.Iterator(nil))
|
2022-09-20 10:05:50 -07:00
|
|
|
|
|
|
|
require.Equal(t, expErr, actErr)
|
|
|
|
require.Equal(t, expChks, actChks)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-01 21:29:09 -07:00
|
|
|
func TestConcatenatingChunkIterator(t *testing.T) {
|
|
|
|
chunk1, err := chunks.ChunkFromSamples([]chunks.Sample{fSample{t: 1, f: 10}})
|
|
|
|
require.NoError(t, err)
|
|
|
|
chunk2, err := chunks.ChunkFromSamples([]chunks.Sample{fSample{t: 2, f: 20}})
|
|
|
|
require.NoError(t, err)
|
|
|
|
chunk3, err := chunks.ChunkFromSamples([]chunks.Sample{fSample{t: 3, f: 30}})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
testError := errors.New("something went wrong")
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
|
|
|
iterators []chunks.Iterator
|
|
|
|
expectedChunks []chunks.Meta
|
|
|
|
expectedError error
|
|
|
|
}{
|
|
|
|
"many successful iterators": {
|
|
|
|
iterators: []chunks.Iterator{
|
|
|
|
NewListChunkSeriesIterator(chunk1, chunk2),
|
|
|
|
NewListChunkSeriesIterator(chunk3),
|
|
|
|
},
|
|
|
|
expectedChunks: []chunks.Meta{chunk1, chunk2, chunk3},
|
|
|
|
},
|
|
|
|
"single failing iterator": {
|
|
|
|
iterators: []chunks.Iterator{
|
|
|
|
errChunksIterator{err: testError},
|
|
|
|
},
|
|
|
|
expectedError: testError,
|
|
|
|
},
|
|
|
|
"some failing and some successful iterators": {
|
|
|
|
iterators: []chunks.Iterator{
|
|
|
|
NewListChunkSeriesIterator(chunk1, chunk2),
|
|
|
|
errChunksIterator{err: testError},
|
|
|
|
NewListChunkSeriesIterator(chunk3),
|
|
|
|
},
|
|
|
|
expectedChunks: []chunks.Meta{chunk1, chunk2}, // Should stop before advancing to last iterator.
|
|
|
|
expectedError: testError,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, testCase := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
it := concatenatingChunkIterator{iterators: testCase.iterators}
|
|
|
|
var chks []chunks.Meta
|
|
|
|
|
|
|
|
for it.Next() {
|
|
|
|
chks = append(chks, it.At())
|
|
|
|
}
|
|
|
|
|
|
|
|
require.Equal(t, testCase.expectedChunks, chks)
|
|
|
|
|
|
|
|
if testCase.expectedError == nil {
|
|
|
|
require.NoError(t, it.Err())
|
|
|
|
} else {
|
|
|
|
require.EqualError(t, it.Err(), testCase.expectedError.Error())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-03 03:32:56 -07:00
|
|
|
type mockQuerier struct {
|
|
|
|
LabelQuerier
|
|
|
|
|
|
|
|
toReturn []Series
|
|
|
|
}
|
|
|
|
|
|
|
|
type seriesByLabel []Series
|
|
|
|
|
|
|
|
func (a seriesByLabel) Len() int { return len(a) }
|
|
|
|
func (a seriesByLabel) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
|
|
|
func (a seriesByLabel) Less(i, j int) bool { return labels.Compare(a[i].Labels(), a[j].Labels()) < 0 }
|
|
|
|
|
2023-09-12 03:37:38 -07:00
|
|
|
func (m *mockQuerier) Select(_ context.Context, sortSeries bool, _ *SelectHints, _ ...*labels.Matcher) SeriesSet {
|
2020-08-03 03:32:56 -07:00
|
|
|
cpy := make([]Series, len(m.toReturn))
|
|
|
|
copy(cpy, m.toReturn)
|
|
|
|
if sortSeries {
|
|
|
|
sort.Sort(seriesByLabel(cpy))
|
|
|
|
}
|
|
|
|
|
|
|
|
return NewMockSeriesSet(cpy...)
|
|
|
|
}
|
|
|
|
|
|
|
|
type mockChunkQurier struct {
|
|
|
|
LabelQuerier
|
|
|
|
|
|
|
|
toReturn []ChunkSeries
|
|
|
|
}
|
|
|
|
|
|
|
|
type chunkSeriesByLabel []ChunkSeries
|
|
|
|
|
|
|
|
func (a chunkSeriesByLabel) Len() int { return len(a) }
|
|
|
|
func (a chunkSeriesByLabel) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
|
|
|
func (a chunkSeriesByLabel) Less(i, j int) bool {
|
|
|
|
return labels.Compare(a[i].Labels(), a[j].Labels()) < 0
|
|
|
|
}
|
|
|
|
|
2023-09-12 03:37:38 -07:00
|
|
|
func (m *mockChunkQurier) Select(_ context.Context, sortSeries bool, _ *SelectHints, _ ...*labels.Matcher) ChunkSeriesSet {
|
2020-08-03 03:32:56 -07:00
|
|
|
cpy := make([]ChunkSeries, len(m.toReturn))
|
|
|
|
copy(cpy, m.toReturn)
|
|
|
|
if sortSeries {
|
|
|
|
sort.Sort(chunkSeriesByLabel(cpy))
|
|
|
|
}
|
|
|
|
|
|
|
|
return NewMockChunkSeriesSet(cpy...)
|
|
|
|
}
|
|
|
|
|
|
|
|
type mockSeriesSet struct {
|
|
|
|
idx int
|
|
|
|
series []Series
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMockSeriesSet(series ...Series) SeriesSet {
|
|
|
|
return &mockSeriesSet{
|
|
|
|
idx: -1,
|
|
|
|
series: series,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockSeriesSet) Next() bool {
|
|
|
|
m.idx++
|
|
|
|
return m.idx < len(m.series)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockSeriesSet) At() Series { return m.series[m.idx] }
|
|
|
|
|
|
|
|
func (m *mockSeriesSet) Err() error { return nil }
|
|
|
|
|
2023-09-14 09:57:31 -07:00
|
|
|
func (m *mockSeriesSet) Warnings() annotations.Annotations { return nil }
|
2020-08-03 03:32:56 -07:00
|
|
|
|
|
|
|
type mockChunkSeriesSet struct {
|
|
|
|
idx int
|
|
|
|
series []ChunkSeries
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMockChunkSeriesSet(series ...ChunkSeries) ChunkSeriesSet {
|
|
|
|
return &mockChunkSeriesSet{
|
|
|
|
idx: -1,
|
|
|
|
series: series,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockChunkSeriesSet) Next() bool {
|
|
|
|
m.idx++
|
|
|
|
return m.idx < len(m.series)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockChunkSeriesSet) At() ChunkSeries { return m.series[m.idx] }
|
|
|
|
|
|
|
|
func (m *mockChunkSeriesSet) Err() error { return nil }
|
|
|
|
|
2023-09-14 09:57:31 -07:00
|
|
|
func (m *mockChunkSeriesSet) Warnings() annotations.Annotations { return nil }
|
2020-08-03 03:32:56 -07:00
|
|
|
|
|
|
|
func TestChainSampleIterator(t *testing.T) {
|
2023-09-19 08:06:46 -07:00
|
|
|
for sampleType, sampleFunc := range map[string]func(int64) chunks.Sample{
|
|
|
|
"float": func(ts int64) chunks.Sample { return fSample{ts, float64(ts)} },
|
|
|
|
"histogram": func(ts int64) chunks.Sample { return histogramSample(ts, uk) },
|
|
|
|
"float histogram": func(ts int64) chunks.Sample { return floatHistogramSample(ts, uk) },
|
|
|
|
} {
|
|
|
|
for name, tc := range map[string]struct {
|
|
|
|
input []chunkenc.Iterator
|
|
|
|
expected []chunks.Sample
|
|
|
|
}{
|
|
|
|
"single iterator": {
|
|
|
|
input: []chunkenc.Iterator{
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0), sampleFunc(1)}),
|
|
|
|
},
|
|
|
|
expected: []chunks.Sample{sampleFunc(0), sampleFunc(1)},
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
2023-09-19 08:06:46 -07:00
|
|
|
"non overlapping iterators": {
|
|
|
|
input: []chunkenc.Iterator{
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0), sampleFunc(1)}),
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(2), sampleFunc(3)}),
|
|
|
|
},
|
|
|
|
expected: []chunks.Sample{sampleFunc(0), sampleFunc(1), sampleFunc(2), sampleFunc(3)},
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
2023-09-19 08:06:46 -07:00
|
|
|
"overlapping but distinct iterators": {
|
|
|
|
input: []chunkenc.Iterator{
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0), sampleFunc(3)}),
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(1), sampleFunc(4)}),
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(2), sampleFunc(5)}),
|
|
|
|
},
|
|
|
|
expected: []chunks.Sample{
|
|
|
|
sampleFunc(0), sampleFunc(1), sampleFunc(2), sampleFunc(3), sampleFunc(4), sampleFunc(5),
|
|
|
|
},
|
2021-10-22 01:06:44 -07:00
|
|
|
},
|
2023-09-19 08:06:46 -07:00
|
|
|
"overlapping iterators": {
|
|
|
|
input: []chunkenc.Iterator{
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0), sampleFunc(1)}),
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0), sampleFunc(2)}),
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(2), sampleFunc(3)}),
|
|
|
|
NewListSeriesIterator(samples{}),
|
|
|
|
NewListSeriesIterator(samples{}),
|
|
|
|
NewListSeriesIterator(samples{}),
|
|
|
|
},
|
|
|
|
expected: []chunks.Sample{sampleFunc(0), sampleFunc(1), sampleFunc(2), sampleFunc(3)},
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
2023-09-19 08:06:46 -07:00
|
|
|
} {
|
|
|
|
t.Run(sampleType+"/"+name, func(t *testing.T) {
|
|
|
|
merged := ChainSampleIteratorFromIterators(nil, tc.input)
|
|
|
|
actual, err := ExpandSamples(merged, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, tc.expected, actual)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestChainSampleIteratorHistogramCounterResetHint(t *testing.T) {
|
|
|
|
for sampleType, sampleFunc := range map[string]func(int64, histogram.CounterResetHint) chunks.Sample{
|
|
|
|
"histogram": func(ts int64, hint histogram.CounterResetHint) chunks.Sample { return histogramSample(ts, hint) },
|
|
|
|
"float histogram": func(ts int64, hint histogram.CounterResetHint) chunks.Sample { return floatHistogramSample(ts, hint) },
|
2020-08-03 03:32:56 -07:00
|
|
|
} {
|
2023-09-19 08:06:46 -07:00
|
|
|
for name, tc := range map[string]struct {
|
|
|
|
input []chunkenc.Iterator
|
|
|
|
expected []chunks.Sample
|
|
|
|
}{
|
|
|
|
"single iterator": {
|
|
|
|
input: []chunkenc.Iterator{
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0, cr), sampleFunc(1, cr), sampleFunc(2, uk)}),
|
|
|
|
},
|
|
|
|
expected: []chunks.Sample{sampleFunc(0, uk), sampleFunc(1, cr), sampleFunc(2, uk)},
|
|
|
|
},
|
|
|
|
"single iterator gauge": {
|
|
|
|
input: []chunkenc.Iterator{
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0, ga), sampleFunc(1, ga), sampleFunc(2, ga)}),
|
|
|
|
},
|
|
|
|
expected: []chunks.Sample{sampleFunc(0, ga), sampleFunc(1, ga), sampleFunc(2, ga)},
|
|
|
|
},
|
|
|
|
"overlapping iterators gauge": {
|
|
|
|
input: []chunkenc.Iterator{
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0, ga), sampleFunc(1, ga), sampleFunc(2, ga), sampleFunc(4, ga)}),
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0, ga), sampleFunc(1, ga), sampleFunc(3, ga), sampleFunc(5, ga)}),
|
|
|
|
},
|
|
|
|
expected: []chunks.Sample{sampleFunc(0, ga), sampleFunc(1, ga), sampleFunc(2, ga), sampleFunc(3, ga), sampleFunc(4, ga), sampleFunc(5, ga)},
|
|
|
|
},
|
|
|
|
"non overlapping iterators": {
|
|
|
|
input: []chunkenc.Iterator{
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0, cr), sampleFunc(1, uk)}),
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(2, cr), sampleFunc(3, cr)}),
|
|
|
|
},
|
|
|
|
expected: []chunks.Sample{sampleFunc(0, uk), sampleFunc(1, uk), sampleFunc(2, uk), sampleFunc(3, cr)},
|
|
|
|
},
|
|
|
|
"overlapping but distinct iterators": {
|
|
|
|
input: []chunkenc.Iterator{
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0, cr), sampleFunc(3, uk), sampleFunc(5, cr)}),
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(1, uk), sampleFunc(2, cr), sampleFunc(4, cr)}),
|
|
|
|
},
|
|
|
|
expected: []chunks.Sample{
|
|
|
|
sampleFunc(0, uk), sampleFunc(1, uk), sampleFunc(2, cr), sampleFunc(3, uk), sampleFunc(4, uk), sampleFunc(5, uk),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"overlapping iterators": {
|
|
|
|
input: []chunkenc.Iterator{
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0, cr), sampleFunc(1, cr), sampleFunc(2, cr)}),
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0, cr), sampleFunc(1, cr), sampleFunc(2, cr)}),
|
|
|
|
},
|
|
|
|
expected: []chunks.Sample{sampleFunc(0, uk), sampleFunc(1, uk), sampleFunc(2, uk)},
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run(sampleType+"/"+name, func(t *testing.T) {
|
|
|
|
merged := ChainSampleIteratorFromIterators(nil, tc.input)
|
|
|
|
actual, err := ExpandSamples(merged, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, tc.expected, actual)
|
|
|
|
})
|
|
|
|
}
|
2020-08-03 03:32:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestChainSampleIteratorSeek(t *testing.T) {
|
2023-09-19 08:06:46 -07:00
|
|
|
for sampleType, sampleFunc := range map[string]func(int64) chunks.Sample{
|
|
|
|
"float": func(ts int64) chunks.Sample { return fSample{ts, float64(ts)} },
|
|
|
|
"histogram": func(ts int64) chunks.Sample { return histogramSample(ts, uk) },
|
|
|
|
"float histogram": func(ts int64) chunks.Sample { return floatHistogramSample(ts, uk) },
|
|
|
|
} {
|
|
|
|
for name, tc := range map[string]struct {
|
|
|
|
input []chunkenc.Iterator
|
|
|
|
seek int64
|
|
|
|
expected []chunks.Sample
|
|
|
|
}{
|
|
|
|
"single iterator": {
|
|
|
|
input: []chunkenc.Iterator{
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0), sampleFunc(1), sampleFunc(2)}),
|
|
|
|
},
|
|
|
|
seek: 1,
|
|
|
|
expected: []chunks.Sample{sampleFunc(1), sampleFunc(2)},
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
2023-09-19 08:06:46 -07:00
|
|
|
"non overlapping iterators": {
|
|
|
|
input: []chunkenc.Iterator{
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0), sampleFunc(1)}),
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(2), sampleFunc(3)}),
|
|
|
|
},
|
|
|
|
seek: 2,
|
|
|
|
expected: []chunks.Sample{sampleFunc(2), sampleFunc(3)},
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
2023-09-19 08:06:46 -07:00
|
|
|
"overlapping but distinct iterators": {
|
|
|
|
input: []chunkenc.Iterator{
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0), sampleFunc(3)}),
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(1), sampleFunc(4)}),
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(2), sampleFunc(5)}),
|
|
|
|
},
|
|
|
|
seek: 2,
|
|
|
|
expected: []chunks.Sample{sampleFunc(2), sampleFunc(3), sampleFunc(4), sampleFunc(5)},
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
2023-09-19 08:06:46 -07:00
|
|
|
"overlapping iterators": {
|
|
|
|
input: []chunkenc.Iterator{
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0), sampleFunc(2), sampleFunc(3)}),
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0), sampleFunc(1), sampleFunc(2)}),
|
|
|
|
},
|
|
|
|
seek: 0,
|
|
|
|
expected: []chunks.Sample{sampleFunc(0), sampleFunc(1), sampleFunc(2), sampleFunc(3)},
|
2021-03-12 03:32:15 -08:00
|
|
|
},
|
2023-09-19 08:06:46 -07:00
|
|
|
} {
|
|
|
|
t.Run(sampleType+"/"+name, func(t *testing.T) {
|
|
|
|
merged := ChainSampleIteratorFromIterators(nil, tc.input)
|
|
|
|
actual := []chunks.Sample{}
|
|
|
|
switch merged.Seek(tc.seek) {
|
|
|
|
case chunkenc.ValFloat:
|
|
|
|
t, f := merged.At()
|
|
|
|
actual = append(actual, fSample{t, f})
|
|
|
|
case chunkenc.ValHistogram:
|
|
|
|
t, h := merged.AtHistogram()
|
|
|
|
actual = append(actual, hSample{t, h})
|
|
|
|
case chunkenc.ValFloatHistogram:
|
|
|
|
t, fh := merged.AtFloatHistogram()
|
|
|
|
actual = append(actual, fhSample{t, fh})
|
|
|
|
}
|
|
|
|
s, err := ExpandSamples(merged, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
actual = append(actual, s...)
|
|
|
|
require.Equal(t, tc.expected, actual)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-31 15:35:17 -07:00
|
|
|
func TestChainSampleIteratorSeekFailingIterator(t *testing.T) {
|
|
|
|
merged := ChainSampleIteratorFromIterators(nil, []chunkenc.Iterator{
|
|
|
|
NewListSeriesIterator(samples{fSample{0, 0.1}, fSample{1, 1.1}, fSample{2, 2.1}}),
|
|
|
|
errIterator{errors.New("something went wrong")},
|
|
|
|
})
|
|
|
|
|
|
|
|
require.Equal(t, chunkenc.ValNone, merged.Seek(0))
|
|
|
|
require.EqualError(t, merged.Err(), "something went wrong")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestChainSampleIteratorNextImmediatelyFailingIterator(t *testing.T) {
|
|
|
|
merged := ChainSampleIteratorFromIterators(nil, []chunkenc.Iterator{
|
|
|
|
NewListSeriesIterator(samples{fSample{0, 0.1}, fSample{1, 1.1}, fSample{2, 2.1}}),
|
|
|
|
errIterator{errors.New("something went wrong")},
|
|
|
|
})
|
|
|
|
|
|
|
|
require.Equal(t, chunkenc.ValNone, merged.Next())
|
|
|
|
require.EqualError(t, merged.Err(), "something went wrong")
|
|
|
|
|
|
|
|
// Next() does some special handling for the first iterator, so make sure it handles the first iterator returning an error too.
|
|
|
|
merged = ChainSampleIteratorFromIterators(nil, []chunkenc.Iterator{
|
|
|
|
errIterator{errors.New("something went wrong")},
|
|
|
|
NewListSeriesIterator(samples{fSample{0, 0.1}, fSample{1, 1.1}, fSample{2, 2.1}}),
|
|
|
|
})
|
|
|
|
|
|
|
|
require.Equal(t, chunkenc.ValNone, merged.Next())
|
|
|
|
require.EqualError(t, merged.Err(), "something went wrong")
|
|
|
|
}
|
|
|
|
|
2023-09-19 08:06:46 -07:00
|
|
|
func TestChainSampleIteratorSeekHistogramCounterResetHint(t *testing.T) {
|
|
|
|
for sampleType, sampleFunc := range map[string]func(int64, histogram.CounterResetHint) chunks.Sample{
|
|
|
|
"histogram": func(ts int64, hint histogram.CounterResetHint) chunks.Sample { return histogramSample(ts, hint) },
|
|
|
|
"float histogram": func(ts int64, hint histogram.CounterResetHint) chunks.Sample { return floatHistogramSample(ts, hint) },
|
2020-08-03 03:32:56 -07:00
|
|
|
} {
|
2023-09-19 08:06:46 -07:00
|
|
|
for name, tc := range map[string]struct {
|
|
|
|
input []chunkenc.Iterator
|
|
|
|
seek int64
|
|
|
|
expected []chunks.Sample
|
|
|
|
}{
|
|
|
|
"single iterator": {
|
|
|
|
input: []chunkenc.Iterator{
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0, cr), sampleFunc(1, cr), sampleFunc(2, uk)}),
|
|
|
|
},
|
|
|
|
seek: 1,
|
|
|
|
expected: []chunks.Sample{sampleFunc(1, uk), sampleFunc(2, uk)},
|
|
|
|
},
|
|
|
|
"non overlapping iterators": {
|
|
|
|
input: []chunkenc.Iterator{
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0, cr), sampleFunc(1, uk)}),
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(2, cr), sampleFunc(3, cr)}),
|
|
|
|
},
|
|
|
|
seek: 2,
|
|
|
|
expected: []chunks.Sample{sampleFunc(2, uk), sampleFunc(3, cr)},
|
|
|
|
},
|
|
|
|
"non overlapping iterators seek to internal reset": {
|
|
|
|
input: []chunkenc.Iterator{
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(0, cr), sampleFunc(1, uk)}),
|
|
|
|
NewListSeriesIterator(samples{sampleFunc(2, cr), sampleFunc(3, cr)}),
|
|
|
|
},
|
|
|
|
seek: 3,
|
|
|
|
expected: []chunks.Sample{sampleFunc(3, uk)},
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run(sampleType+"/"+name, func(t *testing.T) {
|
|
|
|
merged := ChainSampleIteratorFromIterators(nil, tc.input)
|
|
|
|
actual := []chunks.Sample{}
|
|
|
|
switch merged.Seek(tc.seek) {
|
|
|
|
case chunkenc.ValFloat:
|
|
|
|
t, f := merged.At()
|
|
|
|
actual = append(actual, fSample{t, f})
|
|
|
|
case chunkenc.ValHistogram:
|
|
|
|
t, h := merged.AtHistogram()
|
|
|
|
actual = append(actual, hSample{t, h})
|
|
|
|
case chunkenc.ValFloatHistogram:
|
|
|
|
t, fh := merged.AtFloatHistogram()
|
|
|
|
actual = append(actual, fhSample{t, fh})
|
|
|
|
}
|
|
|
|
s, err := ExpandSamples(merged, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
actual = append(actual, s...)
|
|
|
|
require.Equal(t, tc.expected, actual)
|
|
|
|
})
|
2020-08-03 03:32:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-21 03:56:44 -07:00
|
|
|
func makeSeries(numSeries, numSamples int) []Series {
|
2020-08-03 03:32:56 -07:00
|
|
|
series := []Series{}
|
|
|
|
for j := 0; j < numSeries; j++ {
|
2022-03-09 14:21:50 -08:00
|
|
|
labels := labels.FromStrings("foo", fmt.Sprintf("bar%d", j))
|
2023-08-24 06:21:17 -07:00
|
|
|
samples := []chunks.Sample{}
|
2020-08-03 03:32:56 -07:00
|
|
|
for k := 0; k < numSamples; k++ {
|
2022-12-08 04:31:08 -08:00
|
|
|
samples = append(samples, fSample{t: int64(k), f: float64(k)})
|
2020-08-03 03:32:56 -07:00
|
|
|
}
|
|
|
|
series = append(series, NewListSeries(labels, samples))
|
|
|
|
}
|
2022-09-21 03:56:44 -07:00
|
|
|
return series
|
2020-08-03 03:32:56 -07:00
|
|
|
}
|
|
|
|
|
2022-09-21 03:56:44 -07:00
|
|
|
func makeMergeSeriesSet(serieses [][]Series) SeriesSet {
|
|
|
|
seriesSets := make([]genericSeriesSet, len(serieses))
|
|
|
|
for i, s := range serieses {
|
|
|
|
seriesSets[i] = &genericSeriesSetAdapter{NewMockSeriesSet(s...)}
|
2020-08-03 03:32:56 -07:00
|
|
|
}
|
|
|
|
return &seriesSetAdapter{newGenericMergeSeriesSet(seriesSets, (&seriesMergerAdapter{VerticalSeriesMergeFunc: ChainedSeriesMerge}).Merge)}
|
|
|
|
}
|
|
|
|
|
2022-09-21 03:56:44 -07:00
|
|
|
func benchmarkDrain(b *testing.B, makeSeriesSet func() SeriesSet) {
|
2020-08-03 03:32:56 -07:00
|
|
|
var err error
|
2022-09-21 03:56:44 -07:00
|
|
|
var t int64
|
|
|
|
var v float64
|
2022-09-20 10:16:45 -07:00
|
|
|
var iter chunkenc.Iterator
|
2020-08-03 03:32:56 -07:00
|
|
|
for n := 0; n < b.N; n++ {
|
2022-09-21 03:56:44 -07:00
|
|
|
seriesSet := makeSeriesSet()
|
2020-08-03 03:32:56 -07:00
|
|
|
for seriesSet.Next() {
|
2022-09-20 10:16:45 -07:00
|
|
|
iter = seriesSet.At().Iterator(iter)
|
2022-09-21 03:56:44 -07:00
|
|
|
for iter.Next() == chunkenc.ValFloat {
|
|
|
|
t, v = iter.At()
|
|
|
|
}
|
|
|
|
err = iter.Err()
|
2020-08-03 03:32:56 -07:00
|
|
|
}
|
2022-09-21 03:56:44 -07:00
|
|
|
require.NoError(b, err)
|
|
|
|
require.NotEqual(b, t, v) // To ensure the inner loop doesn't get optimised away.
|
2020-08-03 03:32:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkNoMergeSeriesSet_100_100(b *testing.B) {
|
2022-09-21 03:56:44 -07:00
|
|
|
series := makeSeries(100, 100)
|
|
|
|
benchmarkDrain(b, func() SeriesSet { return NewMockSeriesSet(series...) })
|
2020-08-03 03:32:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkMergeSeriesSet(b *testing.B) {
|
|
|
|
for _, bm := range []struct {
|
|
|
|
numSeriesSets, numSeries, numSamples int
|
|
|
|
}{
|
|
|
|
{1, 100, 100},
|
|
|
|
{10, 100, 100},
|
|
|
|
{100, 100, 100},
|
|
|
|
} {
|
2022-09-21 03:56:44 -07:00
|
|
|
serieses := [][]Series{}
|
|
|
|
for i := 0; i < bm.numSeriesSets; i++ {
|
|
|
|
serieses = append(serieses, makeSeries(bm.numSeries, bm.numSamples))
|
|
|
|
}
|
2020-08-03 03:32:56 -07:00
|
|
|
b.Run(fmt.Sprintf("%d_%d_%d", bm.numSeriesSets, bm.numSeries, bm.numSamples), func(b *testing.B) {
|
2022-09-21 03:56:44 -07:00
|
|
|
benchmarkDrain(b, func() SeriesSet { return makeMergeSeriesSet(serieses) })
|
2020-08-03 03:32:56 -07:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type mockGenericQuerier struct {
|
|
|
|
mtx sync.Mutex
|
|
|
|
|
|
|
|
closed bool
|
|
|
|
labelNamesCalls int
|
2021-02-09 09:38:35 -08:00
|
|
|
labelNamesRequested []labelNameRequest
|
2020-08-03 03:32:56 -07:00
|
|
|
sortedSeriesRequested []bool
|
|
|
|
|
|
|
|
resp []string
|
2023-09-14 09:57:31 -07:00
|
|
|
warnings annotations.Annotations
|
2020-08-03 03:32:56 -07:00
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
2021-02-09 09:38:35 -08:00
|
|
|
type labelNameRequest struct {
|
|
|
|
name string
|
|
|
|
matchers []*labels.Matcher
|
|
|
|
}
|
|
|
|
|
2023-09-12 03:37:38 -07:00
|
|
|
func (m *mockGenericQuerier) Select(_ context.Context, b bool, _ *SelectHints, _ ...*labels.Matcher) genericSeriesSet {
|
2020-08-03 03:32:56 -07:00
|
|
|
m.mtx.Lock()
|
|
|
|
m.sortedSeriesRequested = append(m.sortedSeriesRequested, b)
|
|
|
|
m.mtx.Unlock()
|
|
|
|
return &mockGenericSeriesSet{resp: m.resp, warnings: m.warnings, err: m.err}
|
|
|
|
}
|
|
|
|
|
2023-09-14 09:57:31 -07:00
|
|
|
func (m *mockGenericQuerier) LabelValues(_ context.Context, name string, matchers ...*labels.Matcher) ([]string, annotations.Annotations, error) {
|
2020-08-03 03:32:56 -07:00
|
|
|
m.mtx.Lock()
|
2021-02-09 09:38:35 -08:00
|
|
|
m.labelNamesRequested = append(m.labelNamesRequested, labelNameRequest{
|
|
|
|
name: name,
|
|
|
|
matchers: matchers,
|
|
|
|
})
|
2020-08-03 03:32:56 -07:00
|
|
|
m.mtx.Unlock()
|
|
|
|
return m.resp, m.warnings, m.err
|
|
|
|
}
|
|
|
|
|
2023-09-14 09:57:31 -07:00
|
|
|
func (m *mockGenericQuerier) LabelNames(context.Context, ...*labels.Matcher) ([]string, annotations.Annotations, error) {
|
2020-08-03 03:32:56 -07:00
|
|
|
m.mtx.Lock()
|
|
|
|
m.labelNamesCalls++
|
|
|
|
m.mtx.Unlock()
|
|
|
|
return m.resp, m.warnings, m.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockGenericQuerier) Close() error {
|
|
|
|
m.closed = true
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type mockGenericSeriesSet struct {
|
|
|
|
resp []string
|
2023-09-14 09:57:31 -07:00
|
|
|
warnings annotations.Annotations
|
2020-08-03 03:32:56 -07:00
|
|
|
err error
|
|
|
|
|
|
|
|
curr int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockGenericSeriesSet) Next() bool {
|
|
|
|
if m.err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if m.curr >= len(m.resp) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
m.curr++
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2023-09-14 09:57:31 -07:00
|
|
|
func (m *mockGenericSeriesSet) Err() error { return m.err }
|
|
|
|
func (m *mockGenericSeriesSet) Warnings() annotations.Annotations { return m.warnings }
|
2020-08-03 03:32:56 -07:00
|
|
|
|
|
|
|
func (m *mockGenericSeriesSet) At() Labels {
|
|
|
|
return mockLabels(m.resp[m.curr-1])
|
|
|
|
}
|
|
|
|
|
|
|
|
type mockLabels string
|
|
|
|
|
|
|
|
func (l mockLabels) Labels() labels.Labels {
|
|
|
|
return labels.FromStrings("test", string(l))
|
|
|
|
}
|
|
|
|
|
|
|
|
func unwrapMockGenericQuerier(t *testing.T, qr genericQuerier) *mockGenericQuerier {
|
|
|
|
m, ok := qr.(*mockGenericQuerier)
|
|
|
|
if !ok {
|
|
|
|
s, ok := qr.(*secondaryQuerier)
|
2020-10-29 02:43:23 -07:00
|
|
|
require.True(t, ok, "expected secondaryQuerier got something else")
|
2020-08-03 03:32:56 -07:00
|
|
|
m, ok = s.genericQuerier.(*mockGenericQuerier)
|
2020-10-29 02:43:23 -07:00
|
|
|
require.True(t, ok, "expected mockGenericQuerier got something else")
|
2020-08-03 03:32:56 -07:00
|
|
|
}
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMergeGenericQuerierWithSecondaries_ErrorHandling(t *testing.T) {
|
|
|
|
var (
|
|
|
|
errStorage = errors.New("storage error")
|
|
|
|
warnStorage = errors.New("storage warning")
|
2023-09-14 01:39:51 -07:00
|
|
|
ctx = context.Background()
|
2020-08-03 03:32:56 -07:00
|
|
|
)
|
|
|
|
for _, tcase := range []struct {
|
|
|
|
name string
|
|
|
|
queriers []genericQuerier
|
|
|
|
|
|
|
|
expectedSelectsSeries []labels.Labels
|
|
|
|
expectedLabels []string
|
|
|
|
|
2023-09-14 09:57:31 -07:00
|
|
|
expectedWarnings annotations.Annotations
|
2021-02-09 09:38:35 -08:00
|
|
|
expectedErrs [4]error
|
2020-08-03 03:32:56 -07:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "one successful primary querier",
|
|
|
|
queriers: []genericQuerier{&mockGenericQuerier{resp: []string{"a", "b"}, warnings: nil, err: nil}},
|
|
|
|
expectedSelectsSeries: []labels.Labels{
|
|
|
|
labels.FromStrings("test", "a"),
|
|
|
|
labels.FromStrings("test", "b"),
|
|
|
|
},
|
|
|
|
expectedLabels: []string{"a", "b"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "multiple successful primary queriers",
|
|
|
|
queriers: []genericQuerier{
|
|
|
|
&mockGenericQuerier{resp: []string{"a", "b"}, warnings: nil, err: nil},
|
|
|
|
&mockGenericQuerier{resp: []string{"b", "c"}, warnings: nil, err: nil},
|
|
|
|
},
|
|
|
|
expectedSelectsSeries: []labels.Labels{
|
|
|
|
labels.FromStrings("test", "a"),
|
|
|
|
labels.FromStrings("test", "b"),
|
|
|
|
labels.FromStrings("test", "c"),
|
|
|
|
},
|
|
|
|
expectedLabels: []string{"a", "b", "c"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "one failed primary querier",
|
|
|
|
queriers: []genericQuerier{&mockGenericQuerier{warnings: nil, err: errStorage}},
|
2021-02-09 09:38:35 -08:00
|
|
|
expectedErrs: [4]error{errStorage, errStorage, errStorage, errStorage},
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "one successful primary querier with successful secondaries",
|
|
|
|
queriers: []genericQuerier{
|
|
|
|
&mockGenericQuerier{resp: []string{"a", "b"}, warnings: nil, err: nil},
|
|
|
|
&secondaryQuerier{genericQuerier: &mockGenericQuerier{resp: []string{"b"}, warnings: nil, err: nil}},
|
|
|
|
&secondaryQuerier{genericQuerier: &mockGenericQuerier{resp: []string{"c"}, warnings: nil, err: nil}},
|
|
|
|
},
|
|
|
|
expectedSelectsSeries: []labels.Labels{
|
|
|
|
labels.FromStrings("test", "a"),
|
|
|
|
labels.FromStrings("test", "b"),
|
|
|
|
labels.FromStrings("test", "c"),
|
|
|
|
},
|
|
|
|
expectedLabels: []string{"a", "b", "c"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "one successful primary querier with empty response and successful secondaries",
|
|
|
|
queriers: []genericQuerier{
|
|
|
|
&mockGenericQuerier{resp: []string{}, warnings: nil, err: nil},
|
|
|
|
&secondaryQuerier{genericQuerier: &mockGenericQuerier{resp: []string{"b"}, warnings: nil, err: nil}},
|
|
|
|
&secondaryQuerier{genericQuerier: &mockGenericQuerier{resp: []string{"c"}, warnings: nil, err: nil}},
|
|
|
|
},
|
|
|
|
expectedSelectsSeries: []labels.Labels{
|
|
|
|
labels.FromStrings("test", "b"),
|
|
|
|
labels.FromStrings("test", "c"),
|
|
|
|
},
|
|
|
|
expectedLabels: []string{"b", "c"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "one failed primary querier with successful secondaries",
|
|
|
|
queriers: []genericQuerier{
|
|
|
|
&mockGenericQuerier{warnings: nil, err: errStorage},
|
|
|
|
&secondaryQuerier{genericQuerier: &mockGenericQuerier{resp: []string{"b"}, warnings: nil, err: nil}},
|
|
|
|
&secondaryQuerier{genericQuerier: &mockGenericQuerier{resp: []string{"c"}, warnings: nil, err: nil}},
|
|
|
|
},
|
2021-02-09 09:38:35 -08:00
|
|
|
expectedErrs: [4]error{errStorage, errStorage, errStorage, errStorage},
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "one successful primary querier with failed secondaries",
|
|
|
|
queriers: []genericQuerier{
|
|
|
|
&mockGenericQuerier{resp: []string{"a"}, warnings: nil, err: nil},
|
|
|
|
&secondaryQuerier{genericQuerier: &mockGenericQuerier{resp: []string{"b"}, warnings: nil, err: errStorage}},
|
|
|
|
&secondaryQuerier{genericQuerier: &mockGenericQuerier{resp: []string{"c"}, warnings: nil, err: errStorage}},
|
|
|
|
},
|
|
|
|
expectedSelectsSeries: []labels.Labels{
|
|
|
|
labels.FromStrings("test", "a"),
|
|
|
|
},
|
2023-09-14 09:57:31 -07:00
|
|
|
expectedLabels: []string{"a"},
|
|
|
|
expectedWarnings: annotations.New().Add(errStorage),
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "successful queriers with warnings",
|
|
|
|
queriers: []genericQuerier{
|
2023-09-14 09:57:31 -07:00
|
|
|
&mockGenericQuerier{resp: []string{"a"}, warnings: annotations.New().Add(warnStorage), err: nil},
|
|
|
|
&secondaryQuerier{genericQuerier: &mockGenericQuerier{resp: []string{"b"}, warnings: annotations.New().Add(warnStorage), err: nil}},
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
|
|
|
expectedSelectsSeries: []labels.Labels{
|
|
|
|
labels.FromStrings("test", "a"),
|
|
|
|
labels.FromStrings("test", "b"),
|
|
|
|
},
|
2023-09-14 09:57:31 -07:00
|
|
|
expectedLabels: []string{"a", "b"},
|
|
|
|
expectedWarnings: annotations.New().Add(warnStorage),
|
2020-08-03 03:32:56 -07:00
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run(tcase.name, func(t *testing.T) {
|
|
|
|
q := &mergeGenericQuerier{
|
|
|
|
queriers: tcase.queriers,
|
|
|
|
mergeFn: func(l ...Labels) Labels { return l[0] },
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("Select", func(t *testing.T) {
|
2023-09-12 03:37:38 -07:00
|
|
|
res := q.Select(context.Background(), false, nil)
|
2020-08-03 03:32:56 -07:00
|
|
|
var lbls []labels.Labels
|
|
|
|
for res.Next() {
|
|
|
|
lbls = append(lbls, res.At().Labels())
|
|
|
|
}
|
2023-09-14 09:57:31 -07:00
|
|
|
require.Subset(t, tcase.expectedWarnings, res.Warnings())
|
2020-10-29 02:43:23 -07:00
|
|
|
require.Equal(t, tcase.expectedErrs[0], res.Err())
|
2023-12-07 03:35:01 -08:00
|
|
|
require.ErrorIs(t, res.Err(), tcase.expectedErrs[0], "expected error doesn't match")
|
2020-10-29 02:43:23 -07:00
|
|
|
require.Equal(t, tcase.expectedSelectsSeries, lbls)
|
2020-08-03 03:32:56 -07:00
|
|
|
|
|
|
|
for _, qr := range q.queriers {
|
|
|
|
m := unwrapMockGenericQuerier(t, qr)
|
|
|
|
|
|
|
|
exp := []bool{true}
|
|
|
|
if len(q.queriers) == 1 {
|
|
|
|
exp[0] = false
|
|
|
|
}
|
2020-10-29 02:43:23 -07:00
|
|
|
require.Equal(t, exp, m.sortedSeriesRequested)
|
2020-08-03 03:32:56 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("LabelNames", func(t *testing.T) {
|
2023-09-14 01:39:51 -07:00
|
|
|
res, w, err := q.LabelNames(ctx)
|
2023-09-14 09:57:31 -07:00
|
|
|
require.Subset(t, tcase.expectedWarnings, w)
|
2023-12-07 03:35:01 -08:00
|
|
|
require.ErrorIs(t, err, tcase.expectedErrs[1], "expected error doesn't match")
|
2020-10-29 02:43:23 -07:00
|
|
|
require.Equal(t, tcase.expectedLabels, res)
|
2020-08-03 03:32:56 -07:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, qr := range q.queriers {
|
|
|
|
m := unwrapMockGenericQuerier(t, qr)
|
|
|
|
|
2020-10-29 02:43:23 -07:00
|
|
|
require.Equal(t, 1, m.labelNamesCalls)
|
2020-08-03 03:32:56 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("LabelValues", func(t *testing.T) {
|
2023-09-14 07:02:04 -07:00
|
|
|
res, w, err := q.LabelValues(ctx, "test")
|
2023-09-14 09:57:31 -07:00
|
|
|
require.Subset(t, tcase.expectedWarnings, w)
|
2023-12-07 03:35:01 -08:00
|
|
|
require.ErrorIs(t, err, tcase.expectedErrs[2], "expected error doesn't match")
|
2020-10-29 02:43:23 -07:00
|
|
|
require.Equal(t, tcase.expectedLabels, res)
|
2020-08-03 03:32:56 -07:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, qr := range q.queriers {
|
|
|
|
m := unwrapMockGenericQuerier(t, qr)
|
|
|
|
|
2021-02-09 09:38:35 -08:00
|
|
|
require.Equal(t, []labelNameRequest{{name: "test"}}, m.labelNamesRequested)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("LabelValuesWithMatchers", func(t *testing.T) {
|
|
|
|
matcher := labels.MustNewMatcher(labels.MatchEqual, "otherLabel", "someValue")
|
2023-09-14 07:02:04 -07:00
|
|
|
res, w, err := q.LabelValues(ctx, "test2", matcher)
|
2023-09-14 09:57:31 -07:00
|
|
|
require.Subset(t, tcase.expectedWarnings, w)
|
2023-12-07 03:35:01 -08:00
|
|
|
require.ErrorIs(t, err, tcase.expectedErrs[3], "expected error doesn't match")
|
2021-02-09 09:38:35 -08:00
|
|
|
require.Equal(t, tcase.expectedLabels, res)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, qr := range q.queriers {
|
|
|
|
m := unwrapMockGenericQuerier(t, qr)
|
|
|
|
|
|
|
|
require.Equal(t, []labelNameRequest{
|
|
|
|
{name: "test"},
|
|
|
|
{name: "test2", matchers: []*labels.Matcher{matcher}},
|
|
|
|
}, m.labelNamesRequested)
|
2020-08-03 03:32:56 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-10-31 15:35:17 -07:00
|
|
|
|
|
|
|
type errIterator struct {
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e errIterator) Next() chunkenc.ValueType {
|
|
|
|
return chunkenc.ValNone
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e errIterator) Seek(t int64) chunkenc.ValueType {
|
|
|
|
return chunkenc.ValNone
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e errIterator) At() (int64, float64) {
|
|
|
|
return 0, 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e errIterator) AtHistogram() (int64, *histogram.Histogram) {
|
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e errIterator) AtFloatHistogram() (int64, *histogram.FloatHistogram) {
|
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e errIterator) AtT() int64 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e errIterator) Err() error {
|
|
|
|
return e.err
|
|
|
|
}
|