Skip to content

Time range rounding seems wrong when looking small intervals #310

@lukester1975

Description

@lukester1975

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!

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestquestionGeneral question about project or functionality.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions