stores/series tests: use abstractions over Labels (#9613)

**What this PR does / why we need it**:

Stop assuming `labels.Labels` is a slice.

**Special notes for your reviewer:**

This PR only touches tests.

Upstream Prometheus is using a different implementation of
`labels.Labels`, so I plan to create a series of PRs which make Loki
compatible with that. #9532 was the first.

**Checklist**
- [x] Reviewed the
[`CONTRIBUTING.md`](https://github.com/grafana/loki/blob/main/CONTRIBUTING.md)
guide (**required**)
- NA Documentation added
- [x] Tests updated
- NA `CHANGELOG.md` updated
- NA Changes that require user attention or interaction to upgrade are
documented in `docs/sources/upgrading/_index.md`
- NA For Helm chart changes bump the Helm chart version in
`production/helm/loki/Chart.yaml` and update
`production/helm/loki/CHANGELOG.md` and
`production/helm/loki/README.md`. [Example
PR](d10549e3ec)
pull/9725/head
Bryan Boreham 2 years ago committed by GitHub
parent 904ea0586a
commit 695ea32226
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 215
      pkg/storage/stores/series/series_store_test.go

@ -101,33 +101,28 @@ func newTestChunkStoreConfigWithMockStorage(t require.TestingT, schemaCfg config
func TestChunkStore_LabelValuesForMetricName(t *testing.T) { func TestChunkStore_LabelValuesForMetricName(t *testing.T) {
now := model.Now() now := model.Now()
fooMetric1 := labels.Labels{ fooMetric1 := labels.FromStrings(labels.MetricName, "foo",
{Name: labels.MetricName, Value: "foo"}, "bar", "baz",
{Name: "bar", Value: "baz"}, "flip", "flop",
{Name: "flip", Value: "flop"}, "toms", "code",
{Name: "toms", Value: "code"}, )
} fooMetric2 := labels.FromStrings(labels.MetricName, "foo",
fooMetric2 := labels.Labels{ "bar", "beep",
{Name: labels.MetricName, Value: "foo"}, "toms", "code",
{Name: "bar", Value: "beep"}, )
{Name: "toms", Value: "code"}, fooMetric3 := labels.FromStrings(labels.MetricName, "foo",
} "bar", "bop",
fooMetric3 := labels.Labels{ "flip", "flap",
{Name: labels.MetricName, Value: "foo"}, )
{Name: "bar", Value: "bop"},
{Name: "flip", Value: "flap"},
}
// barMetric1 is a subset of barMetric2 to test over-matching bug. // barMetric1 is a subset of barMetric2 to test over-matching bug.
barMetric1 := labels.Labels{ barMetric1 := labels.FromStrings(labels.MetricName, "bar",
{Name: labels.MetricName, Value: "bar"}, "bar", "baz",
{Name: "bar", Value: "baz"}, )
} barMetric2 := labels.FromStrings(labels.MetricName, "bar",
barMetric2 := labels.Labels{ "bar", "baz",
{Name: labels.MetricName, Value: "bar"}, "toms", "code",
{Name: "bar", Value: "baz"}, )
{Name: "toms", Value: "code"},
}
fooChunk1 := dummyChunkFor(now, fooMetric1) fooChunk1 := dummyChunkFor(now, fooMetric1)
fooChunk2 := dummyChunkFor(now, fooMetric2) fooChunk2 := dummyChunkFor(now, fooMetric2)
@ -224,33 +219,28 @@ func TestChunkStore_LabelValuesForMetricName(t *testing.T) {
func TestChunkStore_LabelNamesForMetricName(t *testing.T) { func TestChunkStore_LabelNamesForMetricName(t *testing.T) {
now := model.Now() now := model.Now()
fooMetric1 := labels.Labels{ fooMetric1 := labels.FromStrings(labels.MetricName, "foo",
{Name: labels.MetricName, Value: "foo"}, "bar", "baz",
{Name: "bar", Value: "baz"}, "flip", "flop",
{Name: "flip", Value: "flop"}, "toms", "code",
{Name: "toms", Value: "code"}, )
} fooMetric2 := labels.FromStrings(labels.MetricName, "foo",
fooMetric2 := labels.Labels{ "bar", "beep",
{Name: labels.MetricName, Value: "foo"}, "toms", "code",
{Name: "bar", Value: "beep"}, )
{Name: "toms", Value: "code"}, fooMetric3 := labels.FromStrings(labels.MetricName, "foo",
} "bar", "bop",
fooMetric3 := labels.Labels{ "flip", "flap",
{Name: labels.MetricName, Value: "foo"}, )
{Name: "bar", Value: "bop"},
{Name: "flip", Value: "flap"},
}
// barMetric1 is a subset of barMetric2 to test over-matching bug. // barMetric1 is a subset of barMetric2 to test over-matching bug.
barMetric1 := labels.Labels{ barMetric1 := labels.FromStrings(labels.MetricName, "bar",
{Name: labels.MetricName, Value: "bar"}, "bar", "baz",
{Name: "bar", Value: "baz"}, )
} barMetric2 := labels.FromStrings(labels.MetricName, "bar",
barMetric2 := labels.Labels{ "bar", "baz",
{Name: labels.MetricName, Value: "bar"}, "toms", "code",
{Name: "bar", Value: "baz"}, )
{Name: "toms", Value: "code"},
}
fooChunk1 := dummyChunkFor(now, fooMetric1) fooChunk1 := dummyChunkFor(now, fooMetric1)
fooChunk2 := dummyChunkFor(now, fooMetric2) fooChunk2 := dummyChunkFor(now, fooMetric2)
@ -324,17 +314,15 @@ func TestChunkStore_LabelNamesForMetricName(t *testing.T) {
// TestChunkStore_getMetricNameChunks tests if chunks are fetched correctly when we have the metric name // TestChunkStore_getMetricNameChunks tests if chunks are fetched correctly when we have the metric name
func TestChunkStore_getMetricNameChunks(t *testing.T) { func TestChunkStore_getMetricNameChunks(t *testing.T) {
now := model.Now() now := model.Now()
chunk1 := dummyChunkFor(now, labels.Labels{ chunk1 := dummyChunkFor(now, labels.FromStrings(labels.MetricName, "foo",
{Name: labels.MetricName, Value: "foo"}, "bar", "baz",
{Name: "bar", Value: "baz"}, "flip", "flop",
{Name: "flip", Value: "flop"}, "toms", "code",
{Name: "toms", Value: "code"}, ))
}) chunk2 := dummyChunkFor(now, labels.FromStrings(labels.MetricName, "foo",
chunk2 := dummyChunkFor(now, labels.Labels{ "bar", "beep",
{Name: labels.MetricName, Value: "foo"}, "toms", "code",
{Name: "bar", Value: "beep"}, ))
{Name: "toms", Value: "code"},
})
testCases := []struct { testCases := []struct {
query string query string
@ -448,18 +436,16 @@ func TestChunkStore_getMetricNameChunks(t *testing.T) {
func Test_GetSeries(t *testing.T) { func Test_GetSeries(t *testing.T) {
now := model.Now() now := model.Now()
ch1lbs := labels.Labels{ ch1lbs := labels.FromStrings(labels.MetricName, "foo",
{Name: labels.MetricName, Value: "foo"}, "bar", "baz",
{Name: "bar", Value: "baz"}, "flip", "flop",
{Name: "flip", Value: "flop"}, "toms", "code",
{Name: "toms", Value: "code"}, )
}
chunk1 := dummyChunkFor(now, ch1lbs) chunk1 := dummyChunkFor(now, ch1lbs)
ch2lbs := labels.Labels{ ch2lbs := labels.FromStrings(labels.MetricName, "foo",
{Name: labels.MetricName, Value: "foo"}, "bar", "beep",
{Name: "bar", Value: "beep"}, "toms", "code",
{Name: "toms", Value: "code"}, )
}
chunk2 := dummyChunkFor(now, ch2lbs) chunk2 := dummyChunkFor(now, ch2lbs)
testCases := []struct { testCases := []struct {
@ -549,18 +535,16 @@ func Test_GetSeries(t *testing.T) {
func Test_GetSeriesShard(t *testing.T) { func Test_GetSeriesShard(t *testing.T) {
now := model.Now() now := model.Now()
ch1lbs := labels.Labels{ ch1lbs := labels.FromStrings(labels.MetricName, "foo",
{Name: labels.MetricName, Value: "foo"}, "bar", "baz",
{Name: "bar", Value: "baz"}, "flip", "flop",
{Name: "flip", Value: "flop"}, "toms", "code",
{Name: "toms", Value: "code"}, )
}
chunk1 := dummyChunkFor(now, ch1lbs) chunk1 := dummyChunkFor(now, ch1lbs)
ch2lbs := labels.Labels{ ch2lbs := labels.FromStrings(labels.MetricName, "foo",
{Name: labels.MetricName, Value: "foo"}, "bar", "beep",
{Name: "bar", Value: "beep"}, "toms", "code",
{Name: "toms", Value: "code"}, )
}
chunk2 := dummyChunkFor(now, ch2lbs) chunk2 := dummyChunkFor(now, ch2lbs)
testCases := []struct { testCases := []struct {
@ -676,21 +660,19 @@ func TestChunkStoreError(t *testing.T) {
func TestSeriesStore_LabelValuesForMetricName(t *testing.T) { func TestSeriesStore_LabelValuesForMetricName(t *testing.T) {
now := model.Now() now := model.Now()
fooMetric1 := labels.Labels{ fooMetric1 := labels.FromStrings(labels.MetricName, "foo",
{Name: labels.MetricName, Value: "foo"}, "bar", "baz",
{Name: "bar", Value: "baz"}, "flip", "flop",
{Name: "flip", Value: "flop"}, "toms", "code",
{Name: "toms", Value: "code"}, "env", "dev",
{Name: "env", Value: "dev"}, "class", "not-secret",
{Name: "class", Value: "not-secret"}, )
} fooMetric2 := labels.FromStrings(labels.MetricName, "foo",
fooMetric2 := labels.Labels{ "bar", "beep",
{Name: labels.MetricName, Value: "foo"}, "toms", "code",
{Name: "bar", Value: "beep"}, "env", "prod",
{Name: "toms", Value: "code"}, "class", "secret",
{Name: "env", Value: "prod"}, )
{Name: "class", Value: "secret"},
}
fooChunk1 := dummyChunkFor(now, fooMetric1) fooChunk1 := dummyChunkFor(now, fooMetric1)
fooChunk2 := dummyChunkFor(now, fooMetric2) fooChunk2 := dummyChunkFor(now, fooMetric2)
@ -787,22 +769,21 @@ func dummyChunkFor(now model.Time, metric labels.Labels) chunk.Chunk {
} }
// BenchmarkLabels is a real example from Kubernetes' embedded cAdvisor metrics, lightly obfuscated // BenchmarkLabels is a real example from Kubernetes' embedded cAdvisor metrics, lightly obfuscated
var BenchmarkLabels = labels.Labels{ var BenchmarkLabels = labels.FromStrings(model.MetricNameLabel, "container_cpu_usage_seconds_total",
{Name: model.MetricNameLabel, Value: "container_cpu_usage_seconds_total"}, "beta_kubernetes_io_arch", "amd64",
{Name: "beta_kubernetes_io_arch", Value: "amd64"}, "beta_kubernetes_io_instance_type", "c3.somesize",
{Name: "beta_kubernetes_io_instance_type", Value: "c3.somesize"}, "beta_kubernetes_io_os", "linux",
{Name: "beta_kubernetes_io_os", Value: "linux"}, "container_name", "some-name",
{Name: "container_name", Value: "some-name"}, "cpu", "cpu01",
{Name: "cpu", Value: "cpu01"}, "failure_domain_beta_kubernetes_io_region", "somewhere-1",
{Name: "failure_domain_beta_kubernetes_io_region", Value: "somewhere-1"}, "failure_domain_beta_kubernetes_io_zone", "somewhere-1b",
{Name: "failure_domain_beta_kubernetes_io_zone", Value: "somewhere-1b"}, "id", "/kubepods/burstable/pod6e91c467-e4c5-11e7-ace3-0a97ed59c75e/a3c8498918bd6866349fed5a6f8c643b77c91836427fb6327913276ebc6bde28",
{Name: "id", Value: "/kubepods/burstable/pod6e91c467-e4c5-11e7-ace3-0a97ed59c75e/a3c8498918bd6866349fed5a6f8c643b77c91836427fb6327913276ebc6bde28"}, "image", "registry/organisation/name@sha256:dca3d877a80008b45d71d7edc4fd2e44c0c8c8e7102ba5cbabec63a374d1d506",
{Name: "image", Value: "registry/organisation/name@sha256:dca3d877a80008b45d71d7edc4fd2e44c0c8c8e7102ba5cbabec63a374d1d506"}, "instance", "ip-111-11-1-11.ec2.internal",
{Name: "instance", Value: "ip-111-11-1-11.ec2.internal"}, "job", "kubernetes-cadvisor",
{Name: "job", Value: "kubernetes-cadvisor"}, "kubernetes_io_hostname", "ip-111-11-1-11",
{Name: "kubernetes_io_hostname", Value: "ip-111-11-1-11"}, "monitor", "prod",
{Name: "monitor", Value: "prod"}, "name", "k8s_some-name_some-other-name-5j8s8_kube-system_6e91c467-e4c5-11e7-ace3-0a97ed59c75e_0",
{Name: "name", Value: "k8s_some-name_some-other-name-5j8s8_kube-system_6e91c467-e4c5-11e7-ace3-0a97ed59c75e_0"}, "namespace", "kube-system",
{Name: "namespace", Value: "kube-system"}, "pod_name", "some-other-name-5j8s8",
{Name: "pod_name", Value: "some-other-name-5j8s8"}, )
}

Loading…
Cancel
Save