From 5bf35bd49ed011e7ccbdb6b5bbcc0034309881f1 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Thu, 23 Sep 2021 06:13:55 -0400 Subject: [PATCH] influxdb: flux: use more precise start and end timestamps (#39415) (#39520) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * influxdb: flux: use more precise start and end timestamps * added unit test (cherry picked from commit bf0dc3ef629298b97b8b7aa8387f796ecb987cf0) Co-authored-by: Gábor Farkas --- pkg/tsdb/influxdb/flux/macros.go | 4 ++-- pkg/tsdb/influxdb/flux/macros_test.go | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pkg/tsdb/influxdb/flux/macros.go b/pkg/tsdb/influxdb/flux/macros.go index 2db350c99fc..8962a5f6ac5 100644 --- a/pkg/tsdb/influxdb/flux/macros.go +++ b/pkg/tsdb/influxdb/flux/macros.go @@ -16,8 +16,8 @@ func interpolate(query queryModel) (string, error) { matches := variableFilterExp.FindAllStringSubmatch(flux, -1) if matches != nil { timeRange := query.TimeRange - from := timeRange.From.UTC().Format(time.RFC3339) - to := timeRange.To.UTC().Format(time.RFC3339) + from := timeRange.From.UTC().Format(time.RFC3339Nano) + to := timeRange.To.UTC().Format(time.RFC3339Nano) for _, match := range matches { switch match[2] { case "timeRangeStart": diff --git a/pkg/tsdb/influxdb/flux/macros_test.go b/pkg/tsdb/influxdb/flux/macros_test.go index 363c2cc41ed..c1f48102360 100644 --- a/pkg/tsdb/influxdb/flux/macros_test.go +++ b/pkg/tsdb/influxdb/flux/macros_test.go @@ -11,12 +11,9 @@ import ( ) func TestInterpolate(t *testing.T) { - // Unix sec: 1500376552 - // Unix ms: 1500376552001 - timeRange := backend.TimeRange{ - From: time.Unix(0, 0), - To: time.Unix(0, 0), + From: time.Unix(1632305571, 310985041), + To: time.Unix(1632309171, 310985042), } options := queryOptions{ @@ -33,7 +30,7 @@ func TestInterpolate(t *testing.T) { { name: "interpolate flux variables", before: `v.timeRangeStart, something.timeRangeStop, XYZ.bucket, uuUUu.defaultBucket, aBcDefG.organization, window.windowPeriod, a91{}.bucket`, - after: `1970-01-01T00:00:00Z, 1970-01-01T00:00:00Z, "grafana2", "grafana3", "grafana1", 1s, a91{}.bucket`, + after: `2021-09-22T10:12:51.310985041Z, 2021-09-22T11:12:51.310985042Z, "grafana2", "grafana3", "grafana1", 1s, a91{}.bucket`, }, } for _, tt := range tests {