diff --git a/app/vmalert-tool/unittest/recording.go b/app/vmalert-tool/unittest/recording.go index 5f275ead4..a47d104d6 100644 --- a/app/vmalert-tool/unittest/recording.go +++ b/app/vmalert-tool/unittest/recording.go @@ -6,6 +6,7 @@ import ( "net/url" "reflect" "sort" + "time" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/datasource" "github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils" @@ -29,7 +30,7 @@ func checkMetricsqlCase(cases []metricsqlTestCase, q datasource.QuerierBuilder) queries := q.BuildWithParams(datasource.QuerierParams{QueryParams: url.Values{"nocache": {"1"}, "latency_offset": {"1ms"}}, DataSourceType: "prometheus"}) Outer: for _, mt := range cases { - result, _, err := queries.Query(context.Background(), mt.Expr, mt.EvalTime.ParseTime()) + result, _, err := queries.Query(context.Background(), mt.Expr, durationToTime(mt.EvalTime)) if err != nil { checkErrs = append(checkErrs, fmt.Errorf(" expr: %q, time: %s, err: %w", mt.Expr, mt.EvalTime.Duration().String(), err)) @@ -90,3 +91,10 @@ Outer: } return } + +func durationToTime(pd *promutils.Duration) time.Time { + if pd == nil { + return time.Time{} + } + return time.UnixMilli(pd.Duration().Milliseconds()) +} diff --git a/lib/promutils/duration.go b/lib/promutils/duration.go index 565e592f1..2fc57c52e 100644 --- a/lib/promutils/duration.go +++ b/lib/promutils/duration.go @@ -53,11 +53,3 @@ func ParseDuration(s string) (time.Duration, error) { } return time.Duration(ms) * time.Millisecond, nil } - -// ParseTime returns time for pd. -func (pd *Duration) ParseTime() time.Time { - if pd == nil { - return time.Time{} - } - return time.UnixMilli(pd.Duration().Milliseconds()) -}