Skip to content

Time range rounding seems wrong when looking small intervals #310

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

Open
lukester1975 opened this issue Apr 15, 2025 · 0 comments
Open

Time range rounding seems wrong when looking small intervals #310

lukester1975 opened this issue Apr 15, 2025 · 0 comments

Comments

@lukester1975
Copy link

Hi

Very small time period can miss data points, due to the data source rounding up the from time in getPrometheusTime(). E.g. for a range requested as from=2025-04-14T17:41:49.517Z&to=2025-04-14T17:41:50.503Z can look like:

Image

Using the prometheus data source doesn't exhibit the same behaviour, though I haven't looked in to why (not sure if it sends sub-second timestamps, or rounds differently).

Anyway, a trivial fix still using seconds is to use ceil/floor as appropriate:

  getPrometheusTime(date: string | DateTime, roundUp: boolean) {
    if (typeof date === 'string') {
      date = dateMath.parse(date, roundUp)!;
    }

    if (roundUp) {
      return Math.ceil(date.valueOf() / 1000);
    } else {
      return Math.floor(date.valueOf() / 1000);
    }
  }

Which looks better:

Image

Happy to make a PR but I've no idea if this is the best approach. It was just an obviously quick workaround once I realised where the rounding was happening.

Thanks!

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

No branches or pull requests

1 participant