Artem Navoiev 2019-09-26 12:35:22 +03:00
parent 3e67862676
commit cf4786f34a
3 changed files with 20 additions and 4 deletions

View File

@ -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)
}
}

View File

@ -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}"]}
]

View File

@ -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}"]}
]
}