influxdata / flux

Flux is a lightweight scripting language for querying databases (like InfluxDB) and working with data. It's part of InfluxDB 1.7 and 2.0, but can be run independently of those.
https://influxdata.com
MIT License
769 stars 153 forks source link

Wrong actual duration when using relative duration -1mo or -1y in range function #5504

Closed friebi closed 1 month ago

friebi commented 3 months ago

Issue originally posted here https://github.com/influxdata/influxdb/issues/24458, but it is not being progressed. Maybe it better belongs here to the flux repository. The issue is still present with latest release and latest Debian Bookworm updates.

Steps to reproduce:

  1. I'm monitoring my power meter which sends serial data current power draw and current meter reading every couple of seconds via infrared.
  2. I want to show the usage of electric power within the last month and year, respectively.
  3. For that I'm doing the following very simple queries:
    
    import "timezone"

option location = timezone.location(name: "Europe/Berlin")

from(bucket: "power_meter") |> range(start: -1mo) |> filter(fn: (r) => r._field == "cnt") |> spread()

The issue only occurs using `-1mo` and `-1y`. Every relative duration using `-1w` or smaller works just fine.

__Expected behaviour:__
table | _start* | _stop* | _field* | _measurement* | _value
-- | -- | -- | -- | -- | --
0 | 2023-10-**12T12**:17:32.776900207Z | 2023-11-12T13:17:32.776900207Z | cnt | power_meter | 136.85080000000016

I can achieve the expected result by importing the `date` package and substituting `-1mo` by `date.sub(d: 1mo, from: now())` in the `range` function call:

import "date" import "timezone"

option location = timezone.location(name: "Europe/Berlin")

from(bucket: "power_meter") |> range(start: date.sub(d: 1mo, from: now())) |> filter(fn: (r) => r._field == "cnt") |> spread()



__Actual behaviour:__
I'm getting the following response where the start time is off by 14 hours, which is wrong.
table | _start* | _stop* | _field* | _measurement* | _value
-- | -- | -- | -- | -- | --
0 | 2023-10-**13T02**:49:29.5669658Z | 2023-11-12T13:19:29.5669658Z | cnt | power_meter | 135.09250000000065

Using a relative duration of `-1y` also provides a faulty result, but there the start time offset is "just" 6 hours wrong. Again using the `date.sub` workaround I'm getting correct results.

__Environment info:__

* InfluxDB 2 installed from official repository: `apt list --installed influxdb2` => `influxdb2/unknown,now 2.7.10-1 arm64`
* `uname -srm` => `Linux 6.6.31+rpt-rpi-v8 aarch64`
* Running on Raspberry Pi 4 with latest Raspberry Pi OS bookworm with all updates installed.

__Config:__
No changes in default config except adapted log level to `error`.

<!-- The following sections are only required if relevant. -->

__Logs:__
I can't find any relevant info in the logs even when setting log-level to `debug`.
github-actions[bot] commented 1 month ago

This issue has had no recent activity and will be closed soon.