mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
tsdb: in tests use labels.FromStrings
Replacing code which assumes the internal structure of `Labels`. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
0437dd7cee
commit
176fa38e76
|
@ -202,10 +202,10 @@ func TestLabelValuesWithMatchers(t *testing.T) {
|
|||
|
||||
var seriesEntries []storage.Series
|
||||
for i := 0; i < 100; i++ {
|
||||
seriesEntries = append(seriesEntries, storage.NewListSeries(labels.Labels{
|
||||
{Name: "tens", Value: fmt.Sprintf("value%d", i/10)},
|
||||
{Name: "unique", Value: fmt.Sprintf("value%d", i)},
|
||||
}, []tsdbutil.Sample{sample{100, 0}}))
|
||||
seriesEntries = append(seriesEntries, storage.NewListSeries(labels.FromStrings(
|
||||
"tens", fmt.Sprintf("value%d", i/10),
|
||||
"unique", fmt.Sprintf("value%d", i),
|
||||
), []tsdbutil.Sample{sample{100, 0}}))
|
||||
}
|
||||
|
||||
blockDir := createBlock(t, tmpdir, seriesEntries)
|
||||
|
@ -357,13 +357,11 @@ func BenchmarkLabelValuesWithMatchers(b *testing.B) {
|
|||
var seriesEntries []storage.Series
|
||||
metricCount := 1000000
|
||||
for i := 0; i < metricCount; i++ {
|
||||
// Note these series are not created in sort order: 'value2' sorts after 'value10'.
|
||||
// This makes a big difference to the benchmark timing.
|
||||
seriesEntries = append(seriesEntries, storage.NewListSeries(labels.Labels{
|
||||
{Name: "a_unique", Value: fmt.Sprintf("value%d", i)},
|
||||
{Name: "b_tens", Value: fmt.Sprintf("value%d", i/(metricCount/10))},
|
||||
{Name: "c_ninety", Value: fmt.Sprintf("value%d", i/(metricCount/10)/9)}, // "0" for the first 90%, then "1"
|
||||
}, []tsdbutil.Sample{sample{100, 0}}))
|
||||
seriesEntries = append(seriesEntries, storage.NewListSeries(labels.FromStrings(
|
||||
"a_unique", fmt.Sprintf("value%d", i),
|
||||
"b_tens", fmt.Sprintf("value%d", i/(metricCount/10)),
|
||||
"c_ninety", fmt.Sprintf("value%d", i/(metricCount/10)/9), // "0" for the first 90%, then "1"
|
||||
), []tsdbutil.Sample{sample{100, 0}}))
|
||||
}
|
||||
|
||||
blockDir := createBlock(b, tmpdir, seriesEntries)
|
||||
|
@ -397,23 +395,23 @@ func TestLabelNamesWithMatchers(t *testing.T) {
|
|||
|
||||
var seriesEntries []storage.Series
|
||||
for i := 0; i < 100; i++ {
|
||||
seriesEntries = append(seriesEntries, storage.NewListSeries(labels.Labels{
|
||||
{Name: "unique", Value: fmt.Sprintf("value%d", i)},
|
||||
}, []tsdbutil.Sample{sample{100, 0}}))
|
||||
seriesEntries = append(seriesEntries, storage.NewListSeries(labels.FromStrings(
|
||||
"unique", fmt.Sprintf("value%d", i),
|
||||
), []tsdbutil.Sample{sample{100, 0}}))
|
||||
|
||||
if i%10 == 0 {
|
||||
seriesEntries = append(seriesEntries, storage.NewListSeries(labels.Labels{
|
||||
{Name: "tens", Value: fmt.Sprintf("value%d", i/10)},
|
||||
{Name: "unique", Value: fmt.Sprintf("value%d", i)},
|
||||
}, []tsdbutil.Sample{sample{100, 0}}))
|
||||
seriesEntries = append(seriesEntries, storage.NewListSeries(labels.FromStrings(
|
||||
"tens", fmt.Sprintf("value%d", i/10),
|
||||
"unique", fmt.Sprintf("value%d", i),
|
||||
), []tsdbutil.Sample{sample{100, 0}}))
|
||||
}
|
||||
|
||||
if i%20 == 0 {
|
||||
seriesEntries = append(seriesEntries, storage.NewListSeries(labels.Labels{
|
||||
{Name: "tens", Value: fmt.Sprintf("value%d", i/10)},
|
||||
{Name: "twenties", Value: fmt.Sprintf("value%d", i/20)},
|
||||
{Name: "unique", Value: fmt.Sprintf("value%d", i)},
|
||||
}, []tsdbutil.Sample{sample{100, 0}}))
|
||||
seriesEntries = append(seriesEntries, storage.NewListSeries(labels.FromStrings(
|
||||
"tens", fmt.Sprintf("value%d", i/10),
|
||||
"twenties", fmt.Sprintf("value%d", i/20),
|
||||
"unique", fmt.Sprintf("value%d", i),
|
||||
), []tsdbutil.Sample{sample{100, 0}}))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,10 +35,10 @@ func TestBlockWriter(t *testing.T) {
|
|||
// Add some series.
|
||||
app := w.Appender(ctx)
|
||||
ts1, v1 := int64(44), float64(7)
|
||||
_, err = app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, ts1, v1)
|
||||
_, err = app.Append(0, labels.FromStrings("a", "b"), ts1, v1)
|
||||
require.NoError(t, err)
|
||||
ts2, v2 := int64(55), float64(12)
|
||||
_, err = app.Append(0, labels.Labels{{Name: "c", Value: "d"}}, ts2, v2)
|
||||
_, err = app.Append(0, labels.FromStrings("c", "d"), ts2, v2)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, app.Commit())
|
||||
id, err := w.Flush(ctx)
|
||||
|
|
|
@ -290,7 +290,7 @@ func TestDBAppenderAddRef(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
// Reference should already work before commit.
|
||||
ref2, err := app1.Append(ref1, nil, 124, 1)
|
||||
ref2, err := app1.Append(ref1, labels.EmptyLabels(), 124, 1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, ref1, ref2)
|
||||
|
||||
|
@ -300,7 +300,7 @@ func TestDBAppenderAddRef(t *testing.T) {
|
|||
app2 := db.Appender(ctx)
|
||||
|
||||
// first ref should already work in next transaction.
|
||||
ref3, err := app2.Append(ref1, nil, 125, 0)
|
||||
ref3, err := app2.Append(ref1, labels.EmptyLabels(), 125, 0)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, ref1, ref3)
|
||||
|
||||
|
@ -309,12 +309,12 @@ func TestDBAppenderAddRef(t *testing.T) {
|
|||
require.Equal(t, ref1, ref4)
|
||||
|
||||
// Reference must be valid to add another sample.
|
||||
ref5, err := app2.Append(ref2, nil, 143, 2)
|
||||
ref5, err := app2.Append(ref2, labels.EmptyLabels(), 143, 2)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, ref1, ref5)
|
||||
|
||||
// Missing labels & invalid refs should fail.
|
||||
_, err = app2.Append(9999999, nil, 1, 1)
|
||||
_, err = app2.Append(9999999, labels.EmptyLabels(), 1, 1)
|
||||
require.Equal(t, ErrInvalidSample, errors.Cause(err))
|
||||
|
||||
require.NoError(t, app2.Commit())
|
||||
|
@ -347,8 +347,8 @@ func TestAppendEmptyLabelsIgnored(t *testing.T) {
|
|||
ref1, err := app1.Append(0, labels.FromStrings("a", "b"), 123, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Construct labels manually so there is an empty label.
|
||||
ref2, err := app1.Append(0, labels.Labels{labels.Label{Name: "a", Value: "b"}, labels.Label{Name: "c", Value: ""}}, 124, 0)
|
||||
// Add with empty label.
|
||||
ref2, err := app1.Append(0, labels.FromStrings("a", "b", "c", ""), 124, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Should be the same series.
|
||||
|
@ -400,7 +400,7 @@ Outer:
|
|||
smpls := make([]float64, numSamples)
|
||||
for i := int64(0); i < numSamples; i++ {
|
||||
smpls[i] = rand.Float64()
|
||||
app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, i, smpls[i])
|
||||
app.Append(0, labels.FromStrings("a", "b"), i, smpls[i])
|
||||
}
|
||||
|
||||
require.NoError(t, app.Commit())
|
||||
|
@ -456,12 +456,12 @@ func TestAmendDatapointCausesError(t *testing.T) {
|
|||
|
||||
ctx := context.Background()
|
||||
app := db.Appender(ctx)
|
||||
_, err := app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, 0, 0)
|
||||
_, err := app.Append(0, labels.FromStrings("a", "b"), 0, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, app.Commit())
|
||||
|
||||
app = db.Appender(ctx)
|
||||
_, err = app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, 0, 1)
|
||||
_, err = app.Append(0, labels.FromStrings("a", "b"), 0, 1)
|
||||
require.Equal(t, storage.ErrDuplicateSampleForTimestamp, err)
|
||||
require.NoError(t, app.Rollback())
|
||||
}
|
||||
|
@ -474,12 +474,12 @@ func TestDuplicateNaNDatapointNoAmendError(t *testing.T) {
|
|||
|
||||
ctx := context.Background()
|
||||
app := db.Appender(ctx)
|
||||
_, err := app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, 0, math.NaN())
|
||||
_, err := app.Append(0, labels.FromStrings("a", "b"), 0, math.NaN())
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, app.Commit())
|
||||
|
||||
app = db.Appender(ctx)
|
||||
_, err = app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, 0, math.NaN())
|
||||
_, err = app.Append(0, labels.FromStrings("a", "b"), 0, math.NaN())
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
@ -491,12 +491,12 @@ func TestNonDuplicateNaNDatapointsCausesAmendError(t *testing.T) {
|
|||
|
||||
ctx := context.Background()
|
||||
app := db.Appender(ctx)
|
||||
_, err := app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, 0, math.Float64frombits(0x7ff0000000000001))
|
||||
_, err := app.Append(0, labels.FromStrings("a", "b"), 0, math.Float64frombits(0x7ff0000000000001))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, app.Commit())
|
||||
|
||||
app = db.Appender(ctx)
|
||||
_, err = app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, 0, math.Float64frombits(0x7ff0000000000002))
|
||||
_, err = app.Append(0, labels.FromStrings("a", "b"), 0, math.Float64frombits(0x7ff0000000000002))
|
||||
require.Equal(t, storage.ErrDuplicateSampleForTimestamp, err)
|
||||
}
|
||||
|
||||
|
@ -522,9 +522,9 @@ func TestSkippingInvalidValuesInSameTxn(t *testing.T) {
|
|||
// Append AmendedValue.
|
||||
ctx := context.Background()
|
||||
app := db.Appender(ctx)
|
||||
_, err := app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, 0, 1)
|
||||
_, err := app.Append(0, labels.FromStrings("a", "b"), 0, 1)
|
||||
require.NoError(t, err)
|
||||
_, err = app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, 0, 2)
|
||||
_, err = app.Append(0, labels.FromStrings("a", "b"), 0, 2)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, app.Commit())
|
||||
|
||||
|
@ -540,9 +540,9 @@ func TestSkippingInvalidValuesInSameTxn(t *testing.T) {
|
|||
|
||||
// Append Out of Order Value.
|
||||
app = db.Appender(ctx)
|
||||
_, err = app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, 10, 3)
|
||||
_, err = app.Append(0, labels.FromStrings("a", "b"), 10, 3)
|
||||
require.NoError(t, err)
|
||||
_, err = app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, 7, 5)
|
||||
_, err = app.Append(0, labels.FromStrings("a", "b"), 7, 5)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, app.Commit())
|
||||
|
||||
|
@ -661,7 +661,7 @@ func TestDB_SnapshotWithDelete(t *testing.T) {
|
|||
smpls := make([]float64, numSamples)
|
||||
for i := int64(0); i < numSamples; i++ {
|
||||
smpls[i] = rand.Float64()
|
||||
app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, i, smpls[i])
|
||||
app.Append(0, labels.FromStrings("a", "b"), i, smpls[i])
|
||||
}
|
||||
|
||||
require.NoError(t, app.Commit())
|
||||
|
@ -743,7 +743,7 @@ func TestDB_e2e(t *testing.T) {
|
|||
timeInterval = int64(3)
|
||||
)
|
||||
// Create 8 series with 1000 data-points of different ranges and run queries.
|
||||
lbls := []labels.Labels{
|
||||
lbls := [][]labels.Label{
|
||||
{
|
||||
{Name: "a", Value: "b"},
|
||||
{Name: "instance", Value: "localhost:9090"},
|
||||
|
@ -845,8 +845,9 @@ func TestDB_e2e(t *testing.T) {
|
|||
|
||||
for _, qry := range queries {
|
||||
matched := labels.Slice{}
|
||||
for _, ls := range lbls {
|
||||
for _, l := range lbls {
|
||||
s := labels.Selector(qry.ms)
|
||||
ls := labels.New(l...)
|
||||
if s.Matches(ls) {
|
||||
matched = append(matched, ls)
|
||||
}
|
||||
|
@ -899,7 +900,7 @@ func TestWALFlushedOnDBClose(t *testing.T) {
|
|||
|
||||
dirDb := db.Dir()
|
||||
|
||||
lbls := labels.Labels{labels.Label{Name: "labelname", Value: "labelvalue"}}
|
||||
lbls := labels.FromStrings("labelname", "labelvalue")
|
||||
|
||||
ctx := context.Background()
|
||||
app := db.Appender(ctx)
|
||||
|
@ -981,10 +982,10 @@ func TestWALSegmentSizeOptions(t *testing.T) {
|
|||
|
||||
for i := int64(0); i < 155; i++ {
|
||||
app := db.Appender(context.Background())
|
||||
ref, err := app.Append(0, labels.Labels{labels.Label{Name: "wal" + fmt.Sprintf("%d", i), Value: "size"}}, i, rand.Float64())
|
||||
ref, err := app.Append(0, labels.FromStrings("wal"+fmt.Sprintf("%d", i), "size"), i, rand.Float64())
|
||||
require.NoError(t, err)
|
||||
for j := int64(1); j <= 78; j++ {
|
||||
_, err := app.Append(ref, nil, i+j, rand.Float64())
|
||||
_, err := app.Append(ref, labels.EmptyLabels(), i+j, rand.Float64())
|
||||
require.NoError(t, err)
|
||||
}
|
||||
require.NoError(t, app.Commit())
|
||||
|
@ -1094,7 +1095,7 @@ func TestTombstoneClean(t *testing.T) {
|
|||
smpls := make([]float64, numSamples)
|
||||
for i := int64(0); i < numSamples; i++ {
|
||||
smpls[i] = rand.Float64()
|
||||
app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, i, smpls[i])
|
||||
app.Append(0, labels.FromStrings("a", "b"), i, smpls[i])
|
||||
}
|
||||
|
||||
require.NoError(t, app.Commit())
|
||||
|
@ -1188,7 +1189,7 @@ func TestTombstoneCleanResultEmptyBlock(t *testing.T) {
|
|||
smpls := make([]float64, numSamples)
|
||||
for i := int64(0); i < numSamples; i++ {
|
||||
smpls[i] = rand.Float64()
|
||||
app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, i, smpls[i])
|
||||
app.Append(0, labels.FromStrings("a", "b"), i, smpls[i])
|
||||
}
|
||||
|
||||
require.NoError(t, app.Commit())
|
||||
|
@ -2134,8 +2135,9 @@ func TestCorrectNumTombstones(t *testing.T) {
|
|||
}()
|
||||
|
||||
blockRange := db.compactor.(*LeveledCompactor).ranges[0]
|
||||
defaultLabel := labels.FromStrings("foo", "bar")
|
||||
defaultMatcher := labels.MustNewMatcher(labels.MatchEqual, defaultLabel[0].Name, defaultLabel[0].Value)
|
||||
name, value := "foo", "bar"
|
||||
defaultLabel := labels.FromStrings(name, value)
|
||||
defaultMatcher := labels.MustNewMatcher(labels.MatchEqual, name, value)
|
||||
|
||||
ctx := context.Background()
|
||||
app := db.Appender(ctx)
|
||||
|
@ -2192,7 +2194,7 @@ func TestBlockRanges(t *testing.T) {
|
|||
rangeToTriggerCompaction := db.compactor.(*LeveledCompactor).ranges[0]/2*3 + 1
|
||||
|
||||
app := db.Appender(ctx)
|
||||
lbl := labels.Labels{{Name: "a", Value: "b"}}
|
||||
lbl := labels.FromStrings("a", "b")
|
||||
_, err = app.Append(0, lbl, firstBlockMaxT-1, rand.Float64())
|
||||
if err == nil {
|
||||
t.Fatalf("appending a sample with a timestamp covered by a previous block shouldn't be possible")
|
||||
|
@ -3042,7 +3044,7 @@ func TestOneCheckpointPerCompactCall(t *testing.T) {
|
|||
|
||||
// Case 1: Lot's of uncompacted data in Head.
|
||||
|
||||
lbls := labels.Labels{labels.Label{Name: "foo_d", Value: "choco_bar"}}
|
||||
lbls := labels.FromStrings("foo_d", "choco_bar")
|
||||
// Append samples spanning 59 block ranges.
|
||||
app := db.Appender(context.Background())
|
||||
for i := int64(0); i < 60; i++ {
|
||||
|
@ -3199,7 +3201,7 @@ func testQuerierShouldNotPanicIfHeadChunkIsTruncatedWhileReadingQueriedChunks(t
|
|||
// Generate the metrics we're going to append.
|
||||
metrics := make([]labels.Labels, 0, numSeries)
|
||||
for i := 0; i < numSeries; i++ {
|
||||
metrics = append(metrics, labels.Labels{{Name: labels.MetricName, Value: fmt.Sprintf("test_%d", i)}})
|
||||
metrics = append(metrics, labels.FromStrings(labels.MetricName, fmt.Sprintf("test_%d", i)))
|
||||
}
|
||||
|
||||
// Push 1 sample every 15s for 2x the block duration period.
|
||||
|
@ -3335,7 +3337,7 @@ func testChunkQuerierShouldNotPanicIfHeadChunkIsTruncatedWhileReadingQueriedChun
|
|||
// Generate the metrics we're going to append.
|
||||
metrics := make([]labels.Labels, 0, numSeries)
|
||||
for i := 0; i < numSeries; i++ {
|
||||
metrics = append(metrics, labels.Labels{{Name: labels.MetricName, Value: fmt.Sprintf("test_%d", i)}})
|
||||
metrics = append(metrics, labels.FromStrings(labels.MetricName, fmt.Sprintf("test_%d", i)))
|
||||
}
|
||||
|
||||
// Push 1 sample every 15s for 2x the block duration period.
|
||||
|
|
|
@ -38,16 +38,9 @@ func TestValidateExemplar(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
es := exs.(*CircularExemplarStorage)
|
||||
|
||||
l := labels.Labels{
|
||||
{Name: "service", Value: "asdf"},
|
||||
}
|
||||
l := labels.FromStrings("service", "asdf")
|
||||
e := exemplar.Exemplar{
|
||||
Labels: labels.Labels{
|
||||
labels.Label{
|
||||
Name: "traceID",
|
||||
Value: "qwerty",
|
||||
},
|
||||
},
|
||||
Labels: labels.FromStrings("traceID", "qwerty"),
|
||||
Value: 0.1,
|
||||
Ts: 1,
|
||||
}
|
||||
|
@ -56,12 +49,7 @@ func TestValidateExemplar(t *testing.T) {
|
|||
require.NoError(t, es.AddExemplar(l, e))
|
||||
|
||||
e2 := exemplar.Exemplar{
|
||||
Labels: labels.Labels{
|
||||
labels.Label{
|
||||
Name: "traceID",
|
||||
Value: "zxcvb",
|
||||
},
|
||||
},
|
||||
Labels: labels.FromStrings("traceID", "zxcvb"),
|
||||
Value: 0.1,
|
||||
Ts: 2,
|
||||
}
|
||||
|
@ -80,12 +68,7 @@ func TestValidateExemplar(t *testing.T) {
|
|||
require.Equal(t, es.ValidateExemplar(l, e3), storage.ErrOutOfOrderExemplar)
|
||||
|
||||
e4 := exemplar.Exemplar{
|
||||
Labels: labels.Labels{
|
||||
labels.Label{
|
||||
Name: "a",
|
||||
Value: strings.Repeat("b", exemplar.ExemplarMaxLabelSetLength),
|
||||
},
|
||||
},
|
||||
Labels: labels.FromStrings("a", strings.Repeat("b", exemplar.ExemplarMaxLabelSetLength)),
|
||||
Value: 0.1,
|
||||
Ts: 2,
|
||||
}
|
||||
|
@ -97,16 +80,9 @@ func TestAddExemplar(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
es := exs.(*CircularExemplarStorage)
|
||||
|
||||
l := labels.Labels{
|
||||
{Name: "service", Value: "asdf"},
|
||||
}
|
||||
l := labels.FromStrings("service", "asdf")
|
||||
e := exemplar.Exemplar{
|
||||
Labels: labels.Labels{
|
||||
labels.Label{
|
||||
Name: "traceID",
|
||||
Value: "qwerty",
|
||||
},
|
||||
},
|
||||
Labels: labels.FromStrings("traceID", "qwerty"),
|
||||
Value: 0.1,
|
||||
Ts: 1,
|
||||
}
|
||||
|
@ -115,12 +91,7 @@ func TestAddExemplar(t *testing.T) {
|
|||
require.Equal(t, es.index[string(l.Bytes(nil))].newest, 0, "exemplar was not stored correctly")
|
||||
|
||||
e2 := exemplar.Exemplar{
|
||||
Labels: labels.Labels{
|
||||
labels.Label{
|
||||
Name: "traceID",
|
||||
Value: "zxcvb",
|
||||
},
|
||||
},
|
||||
Labels: labels.FromStrings("traceID", "zxcvb"),
|
||||
Value: 0.1,
|
||||
Ts: 2,
|
||||
}
|
||||
|
@ -140,12 +111,7 @@ func TestAddExemplar(t *testing.T) {
|
|||
require.Equal(t, storage.ErrOutOfOrderExemplar, es.AddExemplar(l, e3))
|
||||
|
||||
e4 := exemplar.Exemplar{
|
||||
Labels: labels.Labels{
|
||||
labels.Label{
|
||||
Name: "a",
|
||||
Value: strings.Repeat("b", exemplar.ExemplarMaxLabelSetLength),
|
||||
},
|
||||
},
|
||||
Labels: labels.FromStrings("a", strings.Repeat("b", exemplar.ExemplarMaxLabelSetLength)),
|
||||
Value: 0.1,
|
||||
Ts: 2,
|
||||
}
|
||||
|
@ -160,19 +126,13 @@ func TestStorageOverflow(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
es := exs.(*CircularExemplarStorage)
|
||||
|
||||
l := labels.Labels{
|
||||
{Name: "service", Value: "asdf"},
|
||||
}
|
||||
lName, lValue := "service", "asdf"
|
||||
l := labels.FromStrings(lName, lValue)
|
||||
|
||||
var eList []exemplar.Exemplar
|
||||
for i := 0; i < len(es.exemplars)+1; i++ {
|
||||
e := exemplar.Exemplar{
|
||||
Labels: labels.Labels{
|
||||
labels.Label{
|
||||
Name: "traceID",
|
||||
Value: "a",
|
||||
},
|
||||
},
|
||||
Labels: labels.FromStrings("traceID", "a"),
|
||||
Value: float64(i+1) / 10,
|
||||
Ts: int64(101 + i),
|
||||
}
|
||||
|
@ -181,7 +141,7 @@ func TestStorageOverflow(t *testing.T) {
|
|||
}
|
||||
require.True(t, (es.exemplars[0].exemplar.Ts == 106), "exemplar was not stored correctly")
|
||||
|
||||
m, err := labels.NewMatcher(labels.MatchEqual, l[0].Name, l[0].Value)
|
||||
m, err := labels.NewMatcher(labels.MatchEqual, lName, lValue)
|
||||
require.NoError(t, err, "error creating label matcher for exemplar query")
|
||||
ret, err := es.Select(100, 110, []*labels.Matcher{m})
|
||||
require.NoError(t, err)
|
||||
|
@ -195,14 +155,10 @@ func TestSelectExemplar(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
es := exs.(*CircularExemplarStorage)
|
||||
|
||||
l := labels.Labels{{Name: "service", Value: "asdf"}}
|
||||
lName, lValue := "service", "asdf"
|
||||
l := labels.FromStrings(lName, lValue)
|
||||
e := exemplar.Exemplar{
|
||||
Labels: labels.Labels{
|
||||
labels.Label{
|
||||
Name: "traceID",
|
||||
Value: "qwerty",
|
||||
},
|
||||
},
|
||||
Labels: labels.FromStrings("traceID", "querty"),
|
||||
Value: 0.1,
|
||||
Ts: 12,
|
||||
}
|
||||
|
@ -211,7 +167,7 @@ func TestSelectExemplar(t *testing.T) {
|
|||
require.NoError(t, err, "adding exemplar failed")
|
||||
require.True(t, reflect.DeepEqual(es.exemplars[0].exemplar, e), "exemplar was not stored correctly")
|
||||
|
||||
m, err := labels.NewMatcher(labels.MatchEqual, l[0].Name, l[0].Value)
|
||||
m, err := labels.NewMatcher(labels.MatchEqual, lName, lValue)
|
||||
require.NoError(t, err, "error creating label matcher for exemplar query")
|
||||
ret, err := es.Select(0, 100, []*labels.Matcher{m})
|
||||
require.NoError(t, err)
|
||||
|
@ -226,23 +182,14 @@ func TestSelectExemplar_MultiSeries(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
es := exs.(*CircularExemplarStorage)
|
||||
|
||||
l1 := labels.Labels{
|
||||
{Name: "__name__", Value: "test_metric"},
|
||||
{Name: "service", Value: "asdf"},
|
||||
}
|
||||
l2 := labels.Labels{
|
||||
{Name: "__name__", Value: "test_metric2"},
|
||||
{Name: "service", Value: "qwer"},
|
||||
}
|
||||
l1Name := "test_metric"
|
||||
l1 := labels.FromStrings(labels.MetricName, l1Name, "service", "asdf")
|
||||
l2Name := "test_metric2"
|
||||
l2 := labels.FromStrings(labels.MetricName, l2Name, "service", "qwer")
|
||||
|
||||
for i := 0; i < len(es.exemplars); i++ {
|
||||
e1 := exemplar.Exemplar{
|
||||
Labels: labels.Labels{
|
||||
labels.Label{
|
||||
Name: "traceID",
|
||||
Value: "a",
|
||||
},
|
||||
},
|
||||
Labels: labels.FromStrings("traceID", "a"),
|
||||
Value: float64(i+1) / 10,
|
||||
Ts: int64(101 + i),
|
||||
}
|
||||
|
@ -250,12 +197,7 @@ func TestSelectExemplar_MultiSeries(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
e2 := exemplar.Exemplar{
|
||||
Labels: labels.Labels{
|
||||
labels.Label{
|
||||
Name: "traceID",
|
||||
Value: "b",
|
||||
},
|
||||
},
|
||||
Labels: labels.FromStrings("traceID", "b"),
|
||||
Value: float64(i+1) / 10,
|
||||
Ts: int64(101 + i),
|
||||
}
|
||||
|
@ -263,14 +205,14 @@ func TestSelectExemplar_MultiSeries(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
m, err := labels.NewMatcher(labels.MatchEqual, l2[0].Name, l2[0].Value)
|
||||
m, err := labels.NewMatcher(labels.MatchEqual, labels.MetricName, l2Name)
|
||||
require.NoError(t, err, "error creating label matcher for exemplar query")
|
||||
ret, err := es.Select(100, 200, []*labels.Matcher{m})
|
||||
require.NoError(t, err)
|
||||
require.True(t, len(ret) == 1, "select should have returned samples for a single series only")
|
||||
require.True(t, len(ret[0].Exemplars) == 3, "didn't get expected 8 exemplars, got %d", len(ret[0].Exemplars))
|
||||
|
||||
m, err = labels.NewMatcher(labels.MatchEqual, l1[0].Name, l1[0].Value)
|
||||
m, err = labels.NewMatcher(labels.MatchEqual, labels.MetricName, l1Name)
|
||||
require.NoError(t, err, "error creating label matcher for exemplar query")
|
||||
ret, err = es.Select(100, 200, []*labels.Matcher{m})
|
||||
require.NoError(t, err)
|
||||
|
@ -284,18 +226,12 @@ func TestSelectExemplar_TimeRange(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
es := exs.(*CircularExemplarStorage)
|
||||
|
||||
l := labels.Labels{
|
||||
{Name: "service", Value: "asdf"},
|
||||
}
|
||||
lName, lValue := "service", "asdf"
|
||||
l := labels.FromStrings(lName, lValue)
|
||||
|
||||
for i := 0; int64(i) < lenEs; i++ {
|
||||
err := es.AddExemplar(l, exemplar.Exemplar{
|
||||
Labels: labels.Labels{
|
||||
labels.Label{
|
||||
Name: "traceID",
|
||||
Value: strconv.Itoa(i),
|
||||
},
|
||||
},
|
||||
Labels: labels.FromStrings("traceID", strconv.Itoa(i)),
|
||||
Value: 0.1,
|
||||
Ts: int64(101 + i),
|
||||
})
|
||||
|
@ -303,7 +239,7 @@ func TestSelectExemplar_TimeRange(t *testing.T) {
|
|||
require.Equal(t, es.index[string(l.Bytes(nil))].newest, i, "exemplar was not stored correctly")
|
||||
}
|
||||
|
||||
m, err := labels.NewMatcher(labels.MatchEqual, l[0].Name, l[0].Value)
|
||||
m, err := labels.NewMatcher(labels.MatchEqual, lName, lValue)
|
||||
require.NoError(t, err, "error creating label matcher for exemplar query")
|
||||
ret, err := es.Select(102, 104, []*labels.Matcher{m})
|
||||
require.NoError(t, err)
|
||||
|
@ -319,29 +255,23 @@ func TestSelectExemplar_DuplicateSeries(t *testing.T) {
|
|||
es := exs.(*CircularExemplarStorage)
|
||||
|
||||
e := exemplar.Exemplar{
|
||||
Labels: labels.Labels{
|
||||
labels.Label{
|
||||
Name: "traceID",
|
||||
Value: "qwerty",
|
||||
},
|
||||
},
|
||||
Labels: labels.FromStrings("traceID", "qwerty"),
|
||||
Value: 0.1,
|
||||
Ts: 12,
|
||||
}
|
||||
|
||||
l := labels.Labels{
|
||||
{Name: "cluster", Value: "us-central1"},
|
||||
{Name: "service", Value: "asdf"},
|
||||
}
|
||||
lName0, lValue0 := "service", "asdf"
|
||||
lName1, lValue1 := "cluster", "us-central1"
|
||||
l := labels.FromStrings(lName0, lValue0, lName1, lValue1)
|
||||
|
||||
// Lets just assume somehow the PromQL expression generated two separate lists of matchers,
|
||||
// both of which can select this particular series.
|
||||
m := [][]*labels.Matcher{
|
||||
{
|
||||
labels.MustNewMatcher(labels.MatchEqual, l[0].Name, l[0].Value),
|
||||
labels.MustNewMatcher(labels.MatchEqual, lName0, lValue0),
|
||||
},
|
||||
{
|
||||
labels.MustNewMatcher(labels.MatchEqual, l[1].Name, l[1].Value),
|
||||
labels.MustNewMatcher(labels.MatchEqual, lName1, lValue1),
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -359,13 +289,8 @@ func TestIndexOverwrite(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
es := exs.(*CircularExemplarStorage)
|
||||
|
||||
l1 := labels.Labels{
|
||||
{Name: "service", Value: "asdf"},
|
||||
}
|
||||
|
||||
l2 := labels.Labels{
|
||||
{Name: "service", Value: "qwer"},
|
||||
}
|
||||
l1 := labels.FromStrings("service", "asdf")
|
||||
l2 := labels.FromStrings("service", "qwer")
|
||||
|
||||
err = es.AddExemplar(l1, exemplar.Exemplar{Value: 1, Ts: 1})
|
||||
require.NoError(t, err)
|
||||
|
@ -488,7 +413,7 @@ func TestResize(t *testing.T) {
|
|||
func BenchmarkAddExemplar(b *testing.B) {
|
||||
// We need to include these labels since we do length calculation
|
||||
// before adding.
|
||||
exLabels := labels.Labels{{Name: "traceID", Value: "89620921"}}
|
||||
exLabels := labels.FromStrings("traceID", "89620921")
|
||||
|
||||
for _, n := range []int{10000, 100000, 1000000} {
|
||||
b.Run(fmt.Sprintf("%d", n), func(b *testing.B) {
|
||||
|
@ -497,12 +422,12 @@ func BenchmarkAddExemplar(b *testing.B) {
|
|||
exs, err := NewCircularExemplarStorage(int64(n), eMetrics)
|
||||
require.NoError(b, err)
|
||||
es := exs.(*CircularExemplarStorage)
|
||||
l := labels.Labels{{Name: "service", Value: strconv.Itoa(0)}}
|
||||
var l labels.Labels
|
||||
b.StartTimer()
|
||||
|
||||
for i := 0; i < n; i++ {
|
||||
if i%100 == 0 {
|
||||
l = labels.Labels{{Name: "service", Value: strconv.Itoa(i)}}
|
||||
l = labels.FromStrings("service", strconv.Itoa(i))
|
||||
}
|
||||
err = es.AddExemplar(l, exemplar.Exemplar{Value: float64(i), Ts: int64(i), Labels: exLabels})
|
||||
if err != nil {
|
||||
|
|
|
@ -813,6 +813,7 @@ func TestHeadDeleteSimple(t *testing.T) {
|
|||
}
|
||||
smplsAll := buildSmpls([]int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9})
|
||||
lblDefault := labels.Label{Name: "a", Value: "b"}
|
||||
lblsDefault := labels.FromStrings("a", "b")
|
||||
|
||||
cases := []struct {
|
||||
dranges tombstones.Intervals
|
||||
|
@ -860,7 +861,7 @@ func TestHeadDeleteSimple(t *testing.T) {
|
|||
|
||||
app := head.Appender(context.Background())
|
||||
for _, smpl := range smplsAll {
|
||||
_, err := app.Append(0, labels.Labels{lblDefault}, smpl.t, smpl.v)
|
||||
_, err := app.Append(0, lblsDefault, smpl.t, smpl.v)
|
||||
require.NoError(t, err)
|
||||
|
||||
}
|
||||
|
@ -874,7 +875,7 @@ func TestHeadDeleteSimple(t *testing.T) {
|
|||
// Add more samples.
|
||||
app = head.Appender(context.Background())
|
||||
for _, smpl := range c.addSamples {
|
||||
_, err := app.Append(0, labels.Labels{lblDefault}, smpl.t, smpl.v)
|
||||
_, err := app.Append(0, lblsDefault, smpl.t, smpl.v)
|
||||
require.NoError(t, err)
|
||||
|
||||
}
|
||||
|
@ -898,7 +899,7 @@ func TestHeadDeleteSimple(t *testing.T) {
|
|||
actSeriesSet := q.Select(false, nil, labels.MustNewMatcher(labels.MatchEqual, lblDefault.Name, lblDefault.Value))
|
||||
require.NoError(t, q.Close())
|
||||
expSeriesSet := newMockSeriesSet([]storage.Series{
|
||||
storage.NewListSeries(labels.Labels{lblDefault}, func() []tsdbutil.Sample {
|
||||
storage.NewListSeries(lblsDefault, func() []tsdbutil.Sample {
|
||||
ss := make([]tsdbutil.Sample, 0, len(c.smplsExp))
|
||||
for _, s := range c.smplsExp {
|
||||
ss = append(ss, s)
|
||||
|
@ -946,7 +947,7 @@ func TestDeleteUntilCurMax(t *testing.T) {
|
|||
smpls := make([]float64, numSamples)
|
||||
for i := int64(0); i < numSamples; i++ {
|
||||
smpls[i] = rand.Float64()
|
||||
_, err := app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, i, smpls[i])
|
||||
_, err := app.Append(0, labels.FromStrings("a", "b"), i, smpls[i])
|
||||
require.NoError(t, err)
|
||||
}
|
||||
require.NoError(t, app.Commit())
|
||||
|
@ -967,7 +968,7 @@ func TestDeleteUntilCurMax(t *testing.T) {
|
|||
|
||||
// Add again and test for presence.
|
||||
app = hb.Appender(context.Background())
|
||||
_, err = app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, 11, 1)
|
||||
_, err = app.Append(0, labels.FromStrings("a", "b"), 11, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, app.Commit())
|
||||
q, err = NewBlockQuerier(hb, 0, 100000)
|
||||
|
@ -993,7 +994,7 @@ func TestDeletedSamplesAndSeriesStillInWALAfterCheckpoint(t *testing.T) {
|
|||
|
||||
for i := 0; i < numSamples; i++ {
|
||||
app := hb.Appender(context.Background())
|
||||
_, err := app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, int64(i), 0)
|
||||
_, err := app.Append(0, labels.FromStrings("a", "b"), int64(i), 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, app.Commit())
|
||||
}
|
||||
|
@ -1392,9 +1393,7 @@ func TestGCChunkAccess(t *testing.T) {
|
|||
)
|
||||
require.NoError(t, idx.Series(1, &lset, &chunks))
|
||||
|
||||
require.Equal(t, labels.Labels{{
|
||||
Name: "a", Value: "1",
|
||||
}}, lset)
|
||||
require.Equal(t, labels.FromStrings("a", "1"), lset)
|
||||
require.Equal(t, 2, len(chunks))
|
||||
|
||||
cr, err := h.chunksRange(0, 1500, nil)
|
||||
|
@ -1446,9 +1445,7 @@ func TestGCSeriesAccess(t *testing.T) {
|
|||
)
|
||||
require.NoError(t, idx.Series(1, &lset, &chunks))
|
||||
|
||||
require.Equal(t, labels.Labels{{
|
||||
Name: "a", Value: "1",
|
||||
}}, lset)
|
||||
require.Equal(t, labels.FromStrings("a", "1"), lset)
|
||||
require.Equal(t, 2, len(chunks))
|
||||
|
||||
cr, err := h.chunksRange(0, 2000, nil)
|
||||
|
@ -1724,7 +1721,7 @@ func TestNewWalSegmentOnTruncate(t *testing.T) {
|
|||
}()
|
||||
add := func(ts int64) {
|
||||
app := h.Appender(context.Background())
|
||||
_, err := app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, ts, 0)
|
||||
_, err := app.Append(0, labels.FromStrings("a", "b"), ts, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, app.Commit())
|
||||
}
|
||||
|
@ -1760,9 +1757,9 @@ func TestAddDuplicateLabelName(t *testing.T) {
|
|||
require.Equal(t, fmt.Sprintf(`label name "%s" is not unique: invalid sample`, labelName), err.Error())
|
||||
}
|
||||
|
||||
add(labels.Labels{{Name: "a", Value: "c"}, {Name: "a", Value: "b"}}, "a")
|
||||
add(labels.Labels{{Name: "a", Value: "c"}, {Name: "a", Value: "c"}}, "a")
|
||||
add(labels.Labels{{Name: "__name__", Value: "up"}, {Name: "job", Value: "prometheus"}, {Name: "le", Value: "500"}, {Name: "le", Value: "400"}, {Name: "unit", Value: "s"}}, "le")
|
||||
add(labels.FromStrings("a", "c", "a", "b"), "a")
|
||||
add(labels.FromStrings("a", "c", "a", "c"), "a")
|
||||
add(labels.FromStrings("__name__", "up", "job", "prometheus", "le", "500", "le", "400", "unit", "s"), "le")
|
||||
}
|
||||
|
||||
func TestMemSeriesIsolation(t *testing.T) {
|
||||
|
@ -2144,7 +2141,7 @@ func testHeadSeriesChunkRace(t *testing.T) {
|
|||
s2, err := app.Append(0, labels.FromStrings("foo2", "bar"), 5, 0)
|
||||
require.NoError(t, err)
|
||||
for ts := int64(6); ts < 11; ts++ {
|
||||
_, err = app.Append(s2, nil, ts, 0)
|
||||
_, err = app.Append(s2, labels.EmptyLabels(), ts, 0)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
require.NoError(t, app.Commit())
|
||||
|
@ -2191,7 +2188,7 @@ func TestHeadLabelNamesValuesWithMinMaxRange(t *testing.T) {
|
|||
|
||||
app := head.Appender(context.Background())
|
||||
for i, name := range expectedLabelNames {
|
||||
_, err := app.Append(0, labels.Labels{{Name: name, Value: expectedLabelValues[i]}}, seriesTimestamps[i], 0)
|
||||
_, err := app.Append(0, labels.FromStrings(name, expectedLabelValues[i]), seriesTimestamps[i], 0)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
require.NoError(t, app.Commit())
|
||||
|
@ -2234,10 +2231,10 @@ func TestHeadLabelValuesWithMatchers(t *testing.T) {
|
|||
|
||||
app := head.Appender(context.Background())
|
||||
for i := 0; i < 100; i++ {
|
||||
_, err := app.Append(0, labels.Labels{
|
||||
{Name: "tens", Value: fmt.Sprintf("value%d", i/10)},
|
||||
{Name: "unique", Value: fmt.Sprintf("value%d", i)},
|
||||
}, 100, 0)
|
||||
_, err := app.Append(0, labels.FromStrings(
|
||||
"tens", fmt.Sprintf("value%d", i/10),
|
||||
"unique", fmt.Sprintf("value%d", i),
|
||||
), 100, 0)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
require.NoError(t, app.Commit())
|
||||
|
@ -2295,25 +2292,25 @@ func TestHeadLabelNamesWithMatchers(t *testing.T) {
|
|||
|
||||
app := head.Appender(context.Background())
|
||||
for i := 0; i < 100; i++ {
|
||||
_, err := app.Append(0, labels.Labels{
|
||||
{Name: "unique", Value: fmt.Sprintf("value%d", i)},
|
||||
}, 100, 0)
|
||||
_, err := app.Append(0, labels.FromStrings(
|
||||
"unique", fmt.Sprintf("value%d", i),
|
||||
), 100, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
if i%10 == 0 {
|
||||
_, err := app.Append(0, labels.Labels{
|
||||
{Name: "tens", Value: fmt.Sprintf("value%d", i/10)},
|
||||
{Name: "unique", Value: fmt.Sprintf("value%d", i)},
|
||||
}, 100, 0)
|
||||
_, err := app.Append(0, labels.FromStrings(
|
||||
"tens", fmt.Sprintf("value%d", i/10),
|
||||
"unique", fmt.Sprintf("value%d", i),
|
||||
), 100, 0)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
if i%20 == 0 {
|
||||
_, err := app.Append(0, labels.Labels{
|
||||
{Name: "tens", Value: fmt.Sprintf("value%d", i/10)},
|
||||
{Name: "twenties", Value: fmt.Sprintf("value%d", i/20)},
|
||||
{Name: "unique", Value: fmt.Sprintf("value%d", i)},
|
||||
}, 100, 0)
|
||||
_, err := app.Append(0, labels.FromStrings(
|
||||
"tens", fmt.Sprintf("value%d", i/10),
|
||||
"twenties", fmt.Sprintf("value%d", i/20),
|
||||
"unique", fmt.Sprintf("value%d", i),
|
||||
), 100, 0)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
@ -2362,28 +2359,28 @@ func TestErrReuseAppender(t *testing.T) {
|
|||
}()
|
||||
|
||||
app := head.Appender(context.Background())
|
||||
_, err := app.Append(0, labels.Labels{{Name: "test", Value: "test"}}, 0, 0)
|
||||
_, err := app.Append(0, labels.FromStrings("test", "test"), 0, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, app.Commit())
|
||||
require.Error(t, app.Commit())
|
||||
require.Error(t, app.Rollback())
|
||||
|
||||
app = head.Appender(context.Background())
|
||||
_, err = app.Append(0, labels.Labels{{Name: "test", Value: "test"}}, 1, 0)
|
||||
_, err = app.Append(0, labels.FromStrings("test", "test"), 1, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, app.Rollback())
|
||||
require.Error(t, app.Rollback())
|
||||
require.Error(t, app.Commit())
|
||||
|
||||
app = head.Appender(context.Background())
|
||||
_, err = app.Append(0, labels.Labels{{Name: "test", Value: "test"}}, 2, 0)
|
||||
_, err = app.Append(0, labels.FromStrings("test", "test"), 2, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, app.Commit())
|
||||
require.Error(t, app.Rollback())
|
||||
require.Error(t, app.Commit())
|
||||
|
||||
app = head.Appender(context.Background())
|
||||
_, err = app.Append(0, labels.Labels{{Name: "test", Value: "test"}}, 3, 0)
|
||||
_, err = app.Append(0, labels.FromStrings("test", "test"), 3, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, app.Rollback())
|
||||
require.Error(t, app.Commit())
|
||||
|
@ -2395,11 +2392,11 @@ func TestHeadMintAfterTruncation(t *testing.T) {
|
|||
head, _ := newTestHead(t, chunkRange, false)
|
||||
|
||||
app := head.Appender(context.Background())
|
||||
_, err := app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, 100, 100)
|
||||
_, err := app.Append(0, labels.FromStrings("a", "b"), 100, 100)
|
||||
require.NoError(t, err)
|
||||
_, err = app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, 4000, 200)
|
||||
_, err = app.Append(0, labels.FromStrings("a", "b"), 4000, 200)
|
||||
require.NoError(t, err)
|
||||
_, err = app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, 8000, 300)
|
||||
_, err = app.Append(0, labels.FromStrings("a", "b"), 8000, 300)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, app.Commit())
|
||||
|
||||
|
@ -2433,7 +2430,7 @@ func TestHeadExemplars(t *testing.T) {
|
|||
// It is perfectly valid to add Exemplars before the current start time -
|
||||
// histogram buckets that haven't been update in a while could still be
|
||||
// exported exemplars from an hour ago.
|
||||
ref, err := app.Append(0, labels.Labels{{Name: "a", Value: "b"}}, 100, 100)
|
||||
ref, err := app.Append(0, labels.FromStrings("a", "b"), 100, 100)
|
||||
require.NoError(t, err)
|
||||
_, err = app.AppendExemplar(ref, l, exemplar.Exemplar{
|
||||
Labels: l,
|
||||
|
@ -2455,13 +2452,11 @@ func BenchmarkHeadLabelValuesWithMatchers(b *testing.B) {
|
|||
|
||||
metricCount := 1000000
|
||||
for i := 0; i < metricCount; i++ {
|
||||
// Note these series are not created in sort order: 'value2' sorts after 'value10'.
|
||||
// This makes a big difference to the benchmark timing.
|
||||
_, err := app.Append(0, labels.Labels{
|
||||
{Name: "a_unique", Value: fmt.Sprintf("value%d", i)},
|
||||
{Name: "b_tens", Value: fmt.Sprintf("value%d", i/(metricCount/10))},
|
||||
{Name: "c_ninety", Value: fmt.Sprintf("value%d", i/(metricCount/10)/9)}, // "0" for the first 90%, then "1"
|
||||
}, 100, 0)
|
||||
_, err := app.Append(0, labels.FromStrings(
|
||||
"a_unique", fmt.Sprintf("value%d", i),
|
||||
"b_tens", fmt.Sprintf("value%d", i/(metricCount/10)),
|
||||
"c_ninety", fmt.Sprintf("value%d", i/(metricCount/10)/9), // "0" for the first 90%, then "1"
|
||||
), 100, 0)
|
||||
require.NoError(b, err)
|
||||
}
|
||||
require.NoError(b, app.Commit())
|
||||
|
@ -2779,7 +2774,7 @@ func TestChunkSnapshot(t *testing.T) {
|
|||
e := ex{
|
||||
seriesLabels: lbls,
|
||||
e: exemplar.Exemplar{
|
||||
Labels: labels.Labels{{Name: "traceID", Value: fmt.Sprintf("%d", rand.Int())}},
|
||||
Labels: labels.FromStrings("traceID", fmt.Sprintf("%d", rand.Int())),
|
||||
Value: rand.Float64(),
|
||||
Ts: ts,
|
||||
},
|
||||
|
@ -2851,7 +2846,7 @@ func TestChunkSnapshot(t *testing.T) {
|
|||
// Add some initial samples with >=1 m-map chunk.
|
||||
app := head.Appender(context.Background())
|
||||
for i := 1; i <= numSeries; i++ {
|
||||
lbls := labels.Labels{labels.Label{Name: "foo", Value: fmt.Sprintf("bar%d", i)}}
|
||||
lbls := labels.FromStrings("foo", fmt.Sprintf("bar%d", i))
|
||||
lblStr := lbls.String()
|
||||
// Should m-map at least 1 chunk.
|
||||
for ts := int64(1); ts <= 200; ts++ {
|
||||
|
@ -2912,7 +2907,7 @@ func TestChunkSnapshot(t *testing.T) {
|
|||
// Add more samples.
|
||||
app := head.Appender(context.Background())
|
||||
for i := 1; i <= numSeries; i++ {
|
||||
lbls := labels.Labels{labels.Label{Name: "foo", Value: fmt.Sprintf("bar%d", i)}}
|
||||
lbls := labels.FromStrings("foo", fmt.Sprintf("bar%d", i))
|
||||
lblStr := lbls.String()
|
||||
// Should m-map at least 1 chunk.
|
||||
for ts := int64(201); ts <= 400; ts++ {
|
||||
|
@ -3009,7 +3004,7 @@ func TestSnapshotError(t *testing.T) {
|
|||
|
||||
// Add a sample.
|
||||
app := head.Appender(context.Background())
|
||||
lbls := labels.Labels{labels.Label{Name: "foo", Value: "bar"}}
|
||||
lbls := labels.FromStrings("foo", "bar")
|
||||
_, err := app.Append(0, lbls, 99, 99)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, app.Commit())
|
||||
|
@ -3078,11 +3073,11 @@ func TestChunkSnapshotReplayBug(t *testing.T) {
|
|||
}
|
||||
seriesRec := record.RefSeries{
|
||||
Ref: ref,
|
||||
Labels: labels.Labels{
|
||||
{Name: "__name__", Value: "request_duration"},
|
||||
{Name: "status_code", Value: "200"},
|
||||
{Name: "foo", Value: fmt.Sprintf("baz%d", rand.Int())},
|
||||
},
|
||||
Labels: labels.FromStrings(
|
||||
"__name__", "request_duration",
|
||||
"status_code", "200",
|
||||
"foo", fmt.Sprintf("baz%d", rand.Int()),
|
||||
),
|
||||
}
|
||||
// Add a sample so that the series is not garbage collected.
|
||||
samplesRec := record.RefSample{Ref: ref, T: 1000, V: 1000}
|
||||
|
@ -3149,7 +3144,7 @@ func TestChunkSnapshotTakenAfterIncompleteSnapshot(t *testing.T) {
|
|||
|
||||
// Add some samples for the snapshot.
|
||||
app := head.Appender(context.Background())
|
||||
_, err = app.Append(0, labels.Labels{{Name: "foo", Value: "bar"}}, 10, 10)
|
||||
_, err = app.Append(0, labels.FromStrings("foo", "bar"), 10, 10)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, app.Commit())
|
||||
|
||||
|
|
|
@ -275,24 +275,24 @@ func TestBlockQuerier(t *testing.T) {
|
|||
maxt: math.MaxInt64,
|
||||
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "a", ".*")},
|
||||
exp: newMockSeriesSet([]storage.Series{
|
||||
storage.NewListSeries(labels.Labels{{Name: "a", Value: "a"}},
|
||||
storage.NewListSeries(labels.FromStrings("a", "a"),
|
||||
[]tsdbutil.Sample{sample{1, 2}, sample{2, 3}, sample{3, 4}, sample{5, 2}, sample{6, 3}, sample{7, 4}},
|
||||
),
|
||||
storage.NewListSeries(labels.Labels{{Name: "a", Value: "a"}, {Name: "b", Value: "b"}},
|
||||
storage.NewListSeries(labels.FromStrings("a", "a", "b", "b"),
|
||||
[]tsdbutil.Sample{sample{1, 1}, sample{2, 2}, sample{3, 3}, sample{5, 3}, sample{6, 6}},
|
||||
),
|
||||
storage.NewListSeries(labels.Labels{{Name: "b", Value: "b"}},
|
||||
storage.NewListSeries(labels.FromStrings("b", "b"),
|
||||
[]tsdbutil.Sample{sample{1, 3}, sample{2, 2}, sample{3, 6}, sample{5, 1}, sample{6, 7}, sample{7, 2}},
|
||||
),
|
||||
}),
|
||||
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{
|
||||
storage.NewListChunkSeriesFromSamples(labels.Labels{{Name: "a", Value: "a"}},
|
||||
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a"),
|
||||
[]tsdbutil.Sample{sample{1, 2}, sample{2, 3}, sample{3, 4}}, []tsdbutil.Sample{sample{5, 2}, sample{6, 3}, sample{7, 4}},
|
||||
),
|
||||
storage.NewListChunkSeriesFromSamples(labels.Labels{{Name: "a", Value: "a"}, {Name: "b", Value: "b"}},
|
||||
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a", "b", "b"),
|
||||
[]tsdbutil.Sample{sample{1, 1}, sample{2, 2}, sample{3, 3}}, []tsdbutil.Sample{sample{5, 3}, sample{6, 6}},
|
||||
),
|
||||
storage.NewListChunkSeriesFromSamples(labels.Labels{{Name: "b", Value: "b"}},
|
||||
storage.NewListChunkSeriesFromSamples(labels.FromStrings("b", "b"),
|
||||
[]tsdbutil.Sample{sample{1, 3}, sample{2, 2}, sample{3, 6}}, []tsdbutil.Sample{sample{5, 1}, sample{6, 7}, sample{7, 2}},
|
||||
),
|
||||
}),
|
||||
|
@ -302,18 +302,18 @@ func TestBlockQuerier(t *testing.T) {
|
|||
maxt: 6,
|
||||
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "a", "a")},
|
||||
exp: newMockSeriesSet([]storage.Series{
|
||||
storage.NewListSeries(labels.Labels{{Name: "a", Value: "a"}},
|
||||
storage.NewListSeries(labels.FromStrings("a", "a"),
|
||||
[]tsdbutil.Sample{sample{2, 3}, sample{3, 4}, sample{5, 2}, sample{6, 3}},
|
||||
),
|
||||
storage.NewListSeries(labels.Labels{{Name: "a", Value: "a"}, {Name: "b", Value: "b"}},
|
||||
storage.NewListSeries(labels.FromStrings("a", "a", "b", "b"),
|
||||
[]tsdbutil.Sample{sample{2, 2}, sample{3, 3}, sample{5, 3}, sample{6, 6}},
|
||||
),
|
||||
}),
|
||||
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{
|
||||
storage.NewListChunkSeriesFromSamples(labels.Labels{{Name: "a", Value: "a"}},
|
||||
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a"),
|
||||
[]tsdbutil.Sample{sample{2, 3}, sample{3, 4}}, []tsdbutil.Sample{sample{5, 2}, sample{6, 3}},
|
||||
),
|
||||
storage.NewListChunkSeriesFromSamples(labels.Labels{{Name: "a", Value: "a"}, {Name: "b", Value: "b"}},
|
||||
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a", "b", "b"),
|
||||
[]tsdbutil.Sample{sample{2, 2}, sample{3, 3}}, []tsdbutil.Sample{sample{5, 3}, sample{6, 6}},
|
||||
),
|
||||
}),
|
||||
|
@ -326,19 +326,19 @@ func TestBlockQuerier(t *testing.T) {
|
|||
hints: &storage.SelectHints{Start: 2, End: 6, DisableTrimming: true},
|
||||
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "a", "a")},
|
||||
exp: newMockSeriesSet([]storage.Series{
|
||||
storage.NewListSeries(labels.Labels{{Name: "a", Value: "a"}},
|
||||
storage.NewListSeries(labels.FromStrings("a", "a"),
|
||||
[]tsdbutil.Sample{sample{1, 2}, sample{2, 3}, sample{3, 4}, sample{5, 2}, sample{6, 3}, sample{7, 4}},
|
||||
),
|
||||
storage.NewListSeries(labels.Labels{{Name: "a", Value: "a"}, {Name: "b", Value: "b"}},
|
||||
storage.NewListSeries(labels.FromStrings("a", "a", "b", "b"),
|
||||
[]tsdbutil.Sample{sample{1, 1}, sample{2, 2}, sample{3, 3}, sample{5, 3}, sample{6, 6}},
|
||||
),
|
||||
}),
|
||||
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{
|
||||
storage.NewListChunkSeriesFromSamples(labels.Labels{{Name: "a", Value: "a"}},
|
||||
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a"),
|
||||
[]tsdbutil.Sample{sample{1, 2}, sample{2, 3}, sample{3, 4}},
|
||||
[]tsdbutil.Sample{sample{5, 2}, sample{6, 3}, sample{7, 4}},
|
||||
),
|
||||
storage.NewListChunkSeriesFromSamples(labels.Labels{{Name: "a", Value: "a"}, {Name: "b", Value: "b"}},
|
||||
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a", "b", "b"),
|
||||
[]tsdbutil.Sample{sample{1, 1}, sample{2, 2}, sample{3, 3}},
|
||||
[]tsdbutil.Sample{sample{5, 3}, sample{6, 6}},
|
||||
),
|
||||
|
@ -352,18 +352,18 @@ func TestBlockQuerier(t *testing.T) {
|
|||
hints: &storage.SelectHints{Start: 5, End: 6, DisableTrimming: true},
|
||||
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "a", "a")},
|
||||
exp: newMockSeriesSet([]storage.Series{
|
||||
storage.NewListSeries(labels.Labels{{Name: "a", Value: "a"}},
|
||||
storage.NewListSeries(labels.FromStrings("a", "a"),
|
||||
[]tsdbutil.Sample{sample{5, 2}, sample{6, 3}, sample{7, 4}},
|
||||
),
|
||||
storage.NewListSeries(labels.Labels{{Name: "a", Value: "a"}, {Name: "b", Value: "b"}},
|
||||
storage.NewListSeries(labels.FromStrings("a", "a", "b", "b"),
|
||||
[]tsdbutil.Sample{sample{5, 3}, sample{6, 6}},
|
||||
),
|
||||
}),
|
||||
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{
|
||||
storage.NewListChunkSeriesFromSamples(labels.Labels{{Name: "a", Value: "a"}},
|
||||
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a"),
|
||||
[]tsdbutil.Sample{sample{5, 2}, sample{6, 3}, sample{7, 4}},
|
||||
),
|
||||
storage.NewListChunkSeriesFromSamples(labels.Labels{{Name: "a", Value: "a"}, {Name: "b", Value: "b"}},
|
||||
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a", "b", "b"),
|
||||
[]tsdbutil.Sample{sample{5, 3}, sample{6, 6}},
|
||||
),
|
||||
}),
|
||||
|
@ -411,24 +411,24 @@ func TestBlockQuerier_AgainstHeadWithOpenChunks(t *testing.T) {
|
|||
maxt: math.MaxInt64,
|
||||
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "a", ".*")},
|
||||
exp: newMockSeriesSet([]storage.Series{
|
||||
storage.NewListSeries(labels.Labels{{Name: "a", Value: "a"}},
|
||||
storage.NewListSeries(labels.FromStrings("a", "a"),
|
||||
[]tsdbutil.Sample{sample{1, 2}, sample{2, 3}, sample{3, 4}, sample{5, 2}, sample{6, 3}, sample{7, 4}},
|
||||
),
|
||||
storage.NewListSeries(labels.Labels{{Name: "a", Value: "a"}, {Name: "b", Value: "b"}},
|
||||
storage.NewListSeries(labels.FromStrings("a", "a", "b", "b"),
|
||||
[]tsdbutil.Sample{sample{1, 1}, sample{2, 2}, sample{3, 3}, sample{5, 3}, sample{6, 6}},
|
||||
),
|
||||
storage.NewListSeries(labels.Labels{{Name: "b", Value: "b"}},
|
||||
storage.NewListSeries(labels.FromStrings("b", "b"),
|
||||
[]tsdbutil.Sample{sample{1, 3}, sample{2, 2}, sample{3, 6}, sample{5, 1}, sample{6, 7}, sample{7, 2}},
|
||||
),
|
||||
}),
|
||||
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{
|
||||
storage.NewListChunkSeriesFromSamples(labels.Labels{{Name: "a", Value: "a"}},
|
||||
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a"),
|
||||
[]tsdbutil.Sample{sample{1, 2}, sample{2, 3}, sample{3, 4}, sample{5, 2}, sample{6, 3}, sample{7, 4}},
|
||||
),
|
||||
storage.NewListChunkSeriesFromSamples(labels.Labels{{Name: "a", Value: "a"}, {Name: "b", Value: "b"}},
|
||||
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a", "b", "b"),
|
||||
[]tsdbutil.Sample{sample{1, 1}, sample{2, 2}, sample{3, 3}, sample{5, 3}, sample{6, 6}},
|
||||
),
|
||||
storage.NewListChunkSeriesFromSamples(labels.Labels{{Name: "b", Value: "b"}},
|
||||
storage.NewListChunkSeriesFromSamples(labels.FromStrings("b", "b"),
|
||||
[]tsdbutil.Sample{sample{1, 3}, sample{2, 2}, sample{3, 6}, sample{5, 1}, sample{6, 7}, sample{7, 2}},
|
||||
),
|
||||
}),
|
||||
|
@ -438,18 +438,18 @@ func TestBlockQuerier_AgainstHeadWithOpenChunks(t *testing.T) {
|
|||
maxt: 6,
|
||||
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "a", "a")},
|
||||
exp: newMockSeriesSet([]storage.Series{
|
||||
storage.NewListSeries(labels.Labels{{Name: "a", Value: "a"}},
|
||||
storage.NewListSeries(labels.FromStrings("a", "a"),
|
||||
[]tsdbutil.Sample{sample{2, 3}, sample{3, 4}, sample{5, 2}, sample{6, 3}},
|
||||
),
|
||||
storage.NewListSeries(labels.Labels{{Name: "a", Value: "a"}, {Name: "b", Value: "b"}},
|
||||
storage.NewListSeries(labels.FromStrings("a", "a", "b", "b"),
|
||||
[]tsdbutil.Sample{sample{2, 2}, sample{3, 3}, sample{5, 3}, sample{6, 6}},
|
||||
),
|
||||
}),
|
||||
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{
|
||||
storage.NewListChunkSeriesFromSamples(labels.Labels{{Name: "a", Value: "a"}},
|
||||
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a"),
|
||||
[]tsdbutil.Sample{sample{2, 3}, sample{3, 4}, sample{5, 2}, sample{6, 3}},
|
||||
),
|
||||
storage.NewListChunkSeriesFromSamples(labels.Labels{{Name: "a", Value: "a"}, {Name: "b", Value: "b"}},
|
||||
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a", "b", "b"),
|
||||
[]tsdbutil.Sample{sample{2, 2}, sample{3, 3}, sample{5, 3}, sample{6, 6}},
|
||||
),
|
||||
}),
|
||||
|
@ -552,24 +552,24 @@ func TestBlockQuerierDelete(t *testing.T) {
|
|||
maxt: math.MaxInt64,
|
||||
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "a", ".*")},
|
||||
exp: newMockSeriesSet([]storage.Series{
|
||||
storage.NewListSeries(labels.Labels{{Name: "a", Value: "a"}},
|
||||
storage.NewListSeries(labels.FromStrings("a", "a"),
|
||||
[]tsdbutil.Sample{sample{5, 2}, sample{6, 3}, sample{7, 4}},
|
||||
),
|
||||
storage.NewListSeries(labels.Labels{{Name: "a", Value: "a"}, {Name: "b", Value: "b"}},
|
||||
storage.NewListSeries(labels.FromStrings("a", "a", "b", "b"),
|
||||
[]tsdbutil.Sample{sample{5, 3}},
|
||||
),
|
||||
storage.NewListSeries(labels.Labels{{Name: "b", Value: "b"}},
|
||||
storage.NewListSeries(labels.FromStrings("b", "b"),
|
||||
[]tsdbutil.Sample{sample{1, 3}, sample{2, 2}, sample{3, 6}, sample{5, 1}},
|
||||
),
|
||||
}),
|
||||
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{
|
||||
storage.NewListChunkSeriesFromSamples(labels.Labels{{Name: "a", Value: "a"}},
|
||||
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a"),
|
||||
[]tsdbutil.Sample{sample{5, 2}, sample{6, 3}, sample{7, 4}},
|
||||
),
|
||||
storage.NewListChunkSeriesFromSamples(labels.Labels{{Name: "a", Value: "a"}, {Name: "b", Value: "b"}},
|
||||
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a", "b", "b"),
|
||||
[]tsdbutil.Sample{sample{5, 3}},
|
||||
),
|
||||
storage.NewListChunkSeriesFromSamples(labels.Labels{{Name: "b", Value: "b"}},
|
||||
storage.NewListChunkSeriesFromSamples(labels.FromStrings("b", "b"),
|
||||
[]tsdbutil.Sample{sample{1, 3}, sample{2, 2}, sample{3, 6}}, []tsdbutil.Sample{sample{5, 1}},
|
||||
),
|
||||
}),
|
||||
|
@ -579,18 +579,18 @@ func TestBlockQuerierDelete(t *testing.T) {
|
|||
maxt: 6,
|
||||
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "a", "a")},
|
||||
exp: newMockSeriesSet([]storage.Series{
|
||||
storage.NewListSeries(labels.Labels{{Name: "a", Value: "a"}},
|
||||
storage.NewListSeries(labels.FromStrings("a", "a"),
|
||||
[]tsdbutil.Sample{sample{5, 2}, sample{6, 3}},
|
||||
),
|
||||
storage.NewListSeries(labels.Labels{{Name: "a", Value: "a"}, {Name: "b", Value: "b"}},
|
||||
storage.NewListSeries(labels.FromStrings("a", "a", "b", "b"),
|
||||
[]tsdbutil.Sample{sample{5, 3}},
|
||||
),
|
||||
}),
|
||||
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{
|
||||
storage.NewListChunkSeriesFromSamples(labels.Labels{{Name: "a", Value: "a"}},
|
||||
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a"),
|
||||
[]tsdbutil.Sample{sample{5, 2}, sample{6, 3}},
|
||||
),
|
||||
storage.NewListChunkSeriesFromSamples(labels.Labels{{Name: "a", Value: "a"}, {Name: "b", Value: "b"}},
|
||||
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a", "b", "b"),
|
||||
[]tsdbutil.Sample{sample{5, 3}},
|
||||
),
|
||||
}),
|
||||
|
|
|
@ -112,8 +112,8 @@ func TestRepairBadIndexVersion(t *testing.T) {
|
|||
|
||||
require.NoError(t, p.Err())
|
||||
require.Equal(t, []labels.Labels{
|
||||
{{Name: "a", Value: "1"}, {Name: "b", Value: "1"}},
|
||||
{{Name: "a", Value: "2"}, {Name: "b", Value: "1"}},
|
||||
labels.FromStrings("a", "1", "b", "1"),
|
||||
labels.FromStrings("a", "2", "b", "1"),
|
||||
}, res)
|
||||
|
||||
meta, _, err := readMetaFile(tmpDbDir)
|
||||
|
|
Loading…
Reference in a new issue