Skip to content

better timegroup-macro handling for sub-second intervals #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2024

Conversation

gabor
Copy link

@gabor gabor commented May 21, 2024

(fixes #257)

the $__timeGroup(col, '5s') macro creates roughly this: TIMESTAMP_SECONDS(DIV(UNIX_SECONDS(col), 5) * 5)

this works fine, but if the interval is smaller than 1second, for example 50 milliseconds, it becomes this:
TIMESTAMP_SECONDS(DIV(UNIX_SECONDS(col), 0.05) * 0.05).

the problem is the DIV(.... , 0.05) part. it does not work with non-integer values.

the solution is to switch from seconds to milliseconds. it's what this PR does. (thanks @MatinF for looking into this!)

@gabor gabor requested a review from a team as a code owner May 21, 2024 10:21
@gabor gabor requested review from yesoreyeram, zoltanbedi and gwdawson and removed request for a team May 21, 2024 10:21
@gabor gabor force-pushed the gabor/timegroup-ms branch from 8798476 to 3e80cfe Compare May 21, 2024 10:48
Copy link
Member

@zoltanbedi zoltanbedi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link

@yesoreyeram yesoreyeram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't this break existing queries? ( If I understand correctly, this new one return milliseconds instead of seconds?? 🤔 )

@MatinF
Copy link

MatinF commented May 21, 2024

I guess it is a valid point that if users are today parsing it as below, it would be a problem to update this directly:

  $__timeGroup(t,$__interval) 

Basically, users would then have to shift to $__interval_ms for it to work properly.

A softer transition may be to create a new macro and explain it in the documentation, e.g. call it as below:

  $__timeGroupMs(t,$__interval_ms)  

It is of course more clean to just have one option, but it will be an abrupt transition for existing users.

@gabor
Copy link
Author

gabor commented May 21, 2024

@yesoreyeram thanks for raising this point.. but, after some more thinking, it should be still fine. the reason is this:
let's say $__interval is 2s (2 seconds).

  • in the current (seconds-based approach), this will become: TIMESTAMP_SECONDS(DIV(UNIX_SECONDS(col), 2) * 2), because the code:
  • in the PR, this will become: TIMESTAMP_MILLIS(DIV(UNIX_MILLIS(f1), 2000) * 2000), because the code:
    • parses 2s into a time.Duration (no change here)
    • then calls.Milliseconds() on the time.Duration:
      return fmt.Sprintf("TIMESTAMP_MILLIS(DIV(UNIX_MILLIS(%s), %v) * %v)", timeVar, interval.Milliseconds(), interval.Milliseconds()), nil

so i think it should be ok. WDYT?

@gabor gabor requested a review from yesoreyeram May 22, 2024 07:04
Copy link

@yesoreyeram yesoreyeram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense Gabor. Thanks for claryfying.

@gabor gabor merged commit 8339583 into main May 23, 2024
3 checks passed
@gabor gabor deleted the gabor/timegroup-ms branch May 23, 2024 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

$__timeGroup(t,$__interval) fails for millisecond intervals
4 participants