From b01d29cf9ec44d313aa543f4948af2d46fd80d1b Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Thu, 21 Jul 2022 16:23:30 +0000 Subject: [PATCH] promql: in tests use labels.FromStrings And a few cases of `EmptyLabels()`. Replacing code which assumes the internal structure of `Labels`. Signed-off-by: Bryan Boreham --- promql/engine_test.go | 38 ++++++++++++++++++------------------- promql/parser/parse_test.go | 2 +- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/promql/engine_test.go b/promql/engine_test.go index 9784ac22a..366c4a65d 100644 --- a/promql/engine_test.go +++ b/promql/engine_test.go @@ -1439,7 +1439,7 @@ load 1ms ref, err := app.Append(0, lblsneg, -1000000, 1000) require.NoError(t, err) for ts := int64(-1000000 + 1000); ts <= 0; ts += 1000 { - _, err := app.Append(ref, nil, ts, -float64(ts/1000)+1) + _, err := app.Append(ref, labels.EmptyLabels(), ts, -float64(ts/1000)+1) require.NoError(t, err) } @@ -1608,7 +1608,7 @@ load 1ms {V: 3600, T: 6 * 60 * 1000}, {V: 3600, T: 7 * 60 * 1000}, }, - Metric: labels.Labels{}, + Metric: labels.EmptyLabels(), }, }, }, @@ -1909,7 +1909,7 @@ func TestSubquerySelector(t *testing.T) { Matrix{ Series{ Points: []Point{{V: 270, T: 90000}, {V: 300, T: 100000}, {V: 330, T: 110000}, {V: 360, T: 120000}}, - Metric: labels.Labels{}, + Metric: labels.EmptyLabels(), }, }, nil, @@ -1923,7 +1923,7 @@ func TestSubquerySelector(t *testing.T) { Matrix{ Series{ Points: []Point{{V: 800, T: 80000}, {V: 900, T: 90000}, {V: 1000, T: 100000}, {V: 1100, T: 110000}, {V: 1200, T: 120000}}, - Metric: labels.Labels{}, + Metric: labels.EmptyLabels(), }, }, nil, @@ -1937,7 +1937,7 @@ func TestSubquerySelector(t *testing.T) { Matrix{ Series{ Points: []Point{{V: 1000, T: 100000}, {V: 1000, T: 105000}, {V: 1100, T: 110000}, {V: 1100, T: 115000}, {V: 1200, T: 120000}}, - Metric: labels.Labels{}, + Metric: labels.EmptyLabels(), }, }, nil, @@ -2993,7 +2993,7 @@ func TestRangeQuery(t *testing.T) { Result: Matrix{ Series{ Points: []Point{{V: 0, T: 0}, {V: 11, T: 60000}, {V: 1100, T: 120000}}, - Metric: labels.Labels{}, + Metric: labels.EmptyLabels(), }, }, Start: time.Unix(0, 0), @@ -3008,7 +3008,7 @@ func TestRangeQuery(t *testing.T) { Result: Matrix{ Series{ Points: []Point{{V: 0, T: 0}, {V: 11, T: 60000}, {V: 1100, T: 120000}}, - Metric: labels.Labels{}, + Metric: labels.EmptyLabels(), }, }, Start: time.Unix(0, 0), @@ -3023,7 +3023,7 @@ func TestRangeQuery(t *testing.T) { Result: Matrix{ Series{ Points: []Point{{V: 0, T: 0}, {V: 11, T: 60000}, {V: 1100, T: 120000}, {V: 110000, T: 180000}, {V: 11000000, T: 240000}}, - Metric: labels.Labels{}, + Metric: labels.EmptyLabels(), }, }, Start: time.Unix(0, 0), @@ -3038,7 +3038,7 @@ func TestRangeQuery(t *testing.T) { Result: Matrix{ Series{ Points: []Point{{V: 5, T: 0}, {V: 59, T: 60000}, {V: 9, T: 120000}, {V: 956, T: 180000}}, - Metric: labels.Labels{}, + Metric: labels.EmptyLabels(), }, }, Start: time.Unix(0, 0), @@ -3053,7 +3053,7 @@ func TestRangeQuery(t *testing.T) { Result: Matrix{ Series{ Points: []Point{{V: 1, T: 0}, {V: 3, T: 60000}, {V: 5, T: 120000}}, - Metric: labels.Labels{labels.Label{Name: "__name__", Value: "metric"}}, + Metric: labels.FromStrings("__name__", "metric"), }, }, Start: time.Unix(0, 0), @@ -3068,7 +3068,7 @@ func TestRangeQuery(t *testing.T) { Result: Matrix{ Series{ Points: []Point{{V: 1, T: 0}, {V: 3, T: 60000}, {V: 5, T: 120000}}, - Metric: labels.Labels{labels.Label{Name: "__name__", Value: "metric"}}, + Metric: labels.FromStrings("__name__", "metric"), }, }, Start: time.Unix(0, 0), @@ -3084,17 +3084,17 @@ func TestRangeQuery(t *testing.T) { Result: Matrix{ Series{ Points: []Point{{V: 1, T: 0}, {V: 3, T: 60000}, {V: 5, T: 120000}}, - Metric: labels.Labels{ - labels.Label{Name: "__name__", Value: "bar"}, - labels.Label{Name: "job", Value: "2"}, - }, + Metric: labels.FromStrings( + "__name__", "bar", + "job", "2", + ), }, Series{ Points: []Point{{V: 3, T: 60000}, {V: 5, T: 120000}}, - Metric: labels.Labels{ - labels.Label{Name: "__name__", Value: "foo"}, - labels.Label{Name: "job", Value: "1"}, - }, + Metric: labels.FromStrings( + "__name__", "foo", + "job", "1", + ), }, }, Start: time.Unix(0, 0), diff --git a/promql/parser/parse_test.go b/promql/parser/parse_test.go index 548fb5aa9..511d2d26e 100644 --- a/promql/parser/parse_test.go +++ b/promql/parser/parse_test.go @@ -3603,7 +3603,7 @@ var testSeries = []struct { }{ { input: `{} 1 2 3`, - expectedMetric: labels.Labels{}, + expectedMetric: labels.EmptyLabels(), expectedValues: newSeq(1, 2, 3), }, { input: `{a="b"} -1 2 3`,