From cf4786f34a37dbf503f0ebed7817f24399be2841 Mon Sep 17 00:00:00 2001 From: Artem Navoiev Date: Thu, 26 Sep 2019 12:35:22 +0300 Subject: [PATCH] add test for https://github.com/VictoriaMetrics/VictoriaMetrics/issues/161 --- app/victoria-metrics/main_test.go | 12 +++++++++--- app/victoria-metrics/testdata/prometheus/basic.json | 2 +- .../testdata/prometheus/case-sensitive-regex.json | 10 ++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 app/victoria-metrics/testdata/prometheus/case-sensitive-regex.json diff --git a/app/victoria-metrics/main_test.go b/app/victoria-metrics/main_test.go index a71f8dc83f..a463cfefff 100644 --- a/app/victoria-metrics/main_test.go +++ b/app/victoria-metrics/main_test.go @@ -52,6 +52,7 @@ const ( const ( tplWordTime = "{TIME}" + tplQuotedWordTime = `"{TIME}"` tplQuotedWordTimeSeconds = `"{TIME_S}"` tplQuotedWordTimeMillis = `"{TIME_MS}"` ) @@ -66,6 +67,7 @@ type test struct { Data string `json:"data"` Query string `json:"query"` Result []Row `json:"result"` + Issue string `json:"issue"` } type Row struct { @@ -239,7 +241,7 @@ func testRead(t *testing.T) { test := x t.Run(test.Name, func(t *testing.T) { t.Parallel() - rowContains(t, httpRead(t, testReadHTTPPath, test.Query), test.Result) + rowContains(t, httpRead(t, testReadHTTPPath, test.Query), test.Result, test.Issue) }) } }) @@ -258,6 +260,7 @@ func readIn(readFor string, t *testing.T, timeStr string) []test { s.noError(err) item := test{} s.noError(json.Unmarshal(b, &item)) + item.Data = strings.Replace(item.Data, tplQuotedWordTime, timeStr, -1) item.Data = strings.Replace(item.Data, tplWordTime, timeStr, -1) tt = append(tt, item) return nil @@ -304,13 +307,16 @@ func httpRead(t *testing.T, address, query string) []Row { return rows } -func rowContains(t *testing.T, rows, contains []Row) { +func rowContains(t *testing.T, rows, contains []Row, issue string) { t.Helper() for _, r := range rows { contains = removeIfFound(r, contains) } if len(contains) > 0 { - t.Fatalf("result rows %+v not found in %+v", contains, rows) + if issue != "" { + issue = "Regression in " + issue + } + t.Fatalf("result rows %+v not found in %+v.%s", contains, rows, issue) } } diff --git a/app/victoria-metrics/testdata/prometheus/basic.json b/app/victoria-metrics/testdata/prometheus/basic.json index 1f145117d5..4fc3c28504 100644 --- a/app/victoria-metrics/testdata/prometheus/basic.json +++ b/app/victoria-metrics/testdata/prometheus/basic.json @@ -1,7 +1,7 @@ { "name": "basic_insertion", "data": "[{\"labels\":[{\"name\":\"__name__\",\"value\":\"prometheus.bar\"},{\"name\":\"baz\",\"value\":\"qux\"}],\"samples\":[{\"value\":100000,\"timestamp\":{TIME}}]}]", - "query": "/api/v1/export?match={__name__!=\"\"}", + "query": "/api/v1/export?match={__name__!=''}", "result": [ {"metric":{"__name__":"prometheus.bar","baz":"qux"},"values":[100000], "timestamps": ["{TIME_MS}"]} ] diff --git a/app/victoria-metrics/testdata/prometheus/case-sensitive-regex.json b/app/victoria-metrics/testdata/prometheus/case-sensitive-regex.json new file mode 100644 index 0000000000..08fe370925 --- /dev/null +++ b/app/victoria-metrics/testdata/prometheus/case-sensitive-regex.json @@ -0,0 +1,10 @@ +{ + "name": "case-sensitive-regex", + "issue": "https://github.com/VictoriaMetrics/VictoriaMetrics/issues/161", + "data": "[{\"labels\":[{\"name\":\"__name__\",\"value\":\"prometheus.sensitiveRegex\"},{\"name\":\"label\",\"value\":\"sensitiveRegex\"}],\"samples\":[{\"value\":2,\"timestamp\":\"{TIME}\"}]},{\"labels\":[{\"name\":\"__name__\",\"value\":\"prometheus.sensitiveRegex\"},{\"name\":\"label\",\"value\":\"SensitiveRegex\"}],\"samples\":[{\"value\":1,\"timestamp\":\"{TIME}\"}]}]", + "query": "/api/v1/export?match={label=~'(?i)sensitiveregex'}", + "result": [ + {"metric":{"__name__":"prometheus.sensitiveRegex","label":"sensitiveRegex"},"values":[2], "timestamps": ["{TIME_MS}"]}, + {"metric":{"__name__":"prometheus.sensitiveRegex","label":"SensitiveRegex"},"values":[1], "timestamps": ["{TIME_MS}"]} + ] +}