mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-23 20:37:12 +01:00
app/victoria-metrics/test: add a test for PopulateTimeTplString
This commit is contained in:
parent
195cefd81a
commit
cc21b31502
@ -1,5 +1,3 @@
|
|||||||
// +build integration
|
|
||||||
|
|
||||||
package test
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -19,8 +17,9 @@ func PopulateTimeTplString(s string, t time.Time) string {
|
|||||||
return string(PopulateTimeTpl([]byte(s), t))
|
return string(PopulateTimeTpl([]byte(s), t))
|
||||||
}
|
}
|
||||||
|
|
||||||
func PopulateTimeTpl(b []byte, t time.Time) []byte {
|
func PopulateTimeTpl(b []byte, tGlobal time.Time) []byte {
|
||||||
return parseTimeExpRegex.ReplaceAllFunc(b, func(repl []byte) []byte {
|
return parseTimeExpRegex.ReplaceAllFunc(b, func(repl []byte) []byte {
|
||||||
|
t := tGlobal
|
||||||
repl = extractRegex.FindSubmatch(repl)[1]
|
repl = extractRegex.FindSubmatch(repl)[1]
|
||||||
parts := strings.SplitN(string(repl), "-", 2)
|
parts := strings.SplitN(string(repl), "-", 2)
|
||||||
if len(parts) == 2 {
|
if len(parts) == 2 {
|
||||||
|
24
app/victoria-metrics/test/parser_test.go
Normal file
24
app/victoria-metrics/test/parser_test.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPopulateTimeTplString(t *testing.T) {
|
||||||
|
now, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error when parsing time: %s", err)
|
||||||
|
}
|
||||||
|
f := func(s, resultExpected string) {
|
||||||
|
t.Helper()
|
||||||
|
result := PopulateTimeTplString(s, now)
|
||||||
|
if result != resultExpected {
|
||||||
|
t.Fatalf("unexpected result; got %q; want %q", result, resultExpected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f("", "")
|
||||||
|
f("{TIME_S}", "1136214245")
|
||||||
|
f("now: {TIME_S}, past 30s: {TIME_MS-30s}, now: {TIME_S}", "now: 1136214245, past 30s: 1136214215000, now: 1136214245")
|
||||||
|
f("now: {TIME_MS}, past 30m: {TIME_MSZ-30m}, past 2h: {TIME_NS-2h}", "now: 1136214245000, past 30m: 1136212445000, past 2h: 1136207045000000000")
|
||||||
|
}
|
@ -3,12 +3,14 @@
|
|||||||
"issue": "https://github.com/VictoriaMetrics/VictoriaMetrics/issues/150",
|
"issue": "https://github.com/VictoriaMetrics/VictoriaMetrics/issues/150",
|
||||||
"data": [
|
"data": [
|
||||||
"not_nan_not_inf;item=x 1 {TIME_S-1m}",
|
"not_nan_not_inf;item=x 1 {TIME_S-1m}",
|
||||||
"not_nan_not_inf;item=x 2 {TIME_S-2m}",
|
"not_nan_not_inf;item=x 1 {TIME_S-2m}",
|
||||||
"not_nan_not_inf;item=y 1 {TIME_S-1m}",
|
"not_nan_not_inf;item=y 3 {TIME_S-1m}",
|
||||||
"not_nan_not_inf;item=y 2 {TIME_S-2m}"],
|
"not_nan_not_inf;item=y 1 {TIME_S-2m}"],
|
||||||
"query": ["/api/v1/query_range?query=1/(not_nan_not_inf-1)!=inf!=nan&start={TIME_S-2m}&end={TIME_S}&step=60"],
|
"query": ["/api/v1/query_range?query=1/(not_nan_not_inf-1)!=inf!=nan&start={TIME_S-3m}&end={TIME_S}&step=60"],
|
||||||
"result_query_range": {
|
"result_query_range": {
|
||||||
"status":"success",
|
"status":"success",
|
||||||
"data":{"resultType":"matrix",
|
"data":{"resultType":"matrix",
|
||||||
"result":[{"metric":{"item":"x"},"values":[["{TIME_S-2m}","1"]]},{"metric":{"item":"y"},"values":[["{TIME_S-2m}","1"]]}]}}
|
"result":[
|
||||||
|
{"metric":{"item":"y"},"values":[["{TIME_S-1m}","0.5"],["{TIME_S}","0.5"]]}
|
||||||
|
]}}
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,17 @@
|
|||||||
"name": "not-nan-as-missing-data",
|
"name": "not-nan-as-missing-data",
|
||||||
"issue": "https://github.com/VictoriaMetrics/VictoriaMetrics/issues/153",
|
"issue": "https://github.com/VictoriaMetrics/VictoriaMetrics/issues/153",
|
||||||
"data": [
|
"data": [
|
||||||
"not_nan_as_missing_data;item=x 1 {TIME_S-1m}",
|
|
||||||
"not_nan_as_missing_data;item=x 2 {TIME_S-2m}",
|
"not_nan_as_missing_data;item=x 2 {TIME_S-2m}",
|
||||||
"not_nan_as_missing_data;item=y 3 {TIME_S-1m}",
|
"not_nan_as_missing_data;item=x 1 {TIME_S-1m}",
|
||||||
"not_nan_as_missing_data;item=y 4 {TIME_S-2m}"],
|
"not_nan_as_missing_data;item=y 4 {TIME_S-2m}",
|
||||||
|
"not_nan_as_missing_data;item=y 3 {TIME_S-1m}"
|
||||||
|
],
|
||||||
"query": ["/api/v1/query_range?query=not_nan_as_missing_data>1&start={TIME_S-2m}&end={TIME_S}&step=60"],
|
"query": ["/api/v1/query_range?query=not_nan_as_missing_data>1&start={TIME_S-2m}&end={TIME_S}&step=60"],
|
||||||
"result_query_range": {
|
"result_query_range": {
|
||||||
"status":"success",
|
"status":"success",
|
||||||
"data":{"resultType":"matrix",
|
"data":{"resultType":"matrix",
|
||||||
"result":[{"metric":{"__name__":"not_nan_as_missing_data","item":"x"},"values":[["{TIME_S-2m}","2"]]},{"metric":{"__name__":"not_nan_as_missing_data","item":"y"},"values":[["{TIME_S-2m}","4"]]}]}}
|
"result":[
|
||||||
|
{"metric":{"__name__":"not_nan_as_missing_data","item":"x"},"values":[["{TIME_S-2m}","2"]]},
|
||||||
|
{"metric":{"__name__":"not_nan_as_missing_data","item":"y"},"values":[["{TIME_S-2m}","4"],["{TIME_S-1m}","3"],["{TIME_S}","3"]]}
|
||||||
|
]}}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user