Skip to content

Commit

Permalink
add adjusting of grafana timeframe after query fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
MGJamJam committed Jul 25, 2024
1 parent b90a100 commit de92364
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export class DataSource extends DataSourceApi<
async query(options: DataQueryRequest<BitmovinAnalyticsDataQuery>): Promise<DataQueryResponse> {
const { range } = options;
const isRelativeRangeFrom = this.isRelativeRangeFrom(range.raw);
let momentTimeUnit = undefined;

//filter disabled queries
const enabledQueries = (options.targets = filter(options.targets, (t) => !t.hide));
Expand All @@ -104,7 +105,7 @@ export class DataSource extends DataSourceApi<
: undefined;

// create new moment object to not mutate the original grafana object with startOf() to not change
// the grafana graph as this would change the timeframe for all the following queries
// the grafana graph at this point as this would change the timeframe for all the following queries
let queryFrom = moment(range!.from.valueOf());
const queryTo = range!.to;

Expand All @@ -115,7 +116,7 @@ export class DataSource extends DataSourceApi<
// to allow higher granularity if interval is selected by user
flooringInterval = getSmallerInterval(interval, flooringInterval);
}
const momentTimeUnit = getMomentTimeUnitForQueryInterval(flooringInterval);
momentTimeUnit = getMomentTimeUnitForQueryInterval(flooringInterval);
if (momentTimeUnit != null) {
queryFrom.startOf(momentTimeUnit);
}
Expand Down Expand Up @@ -205,6 +206,11 @@ export class DataSource extends DataSourceApi<
});
});

// round down grafana start time to adjust the grafana graph and show first data point
if (momentTimeUnit != null) {
range.from.startOf(momentTimeUnit);
}

return Promise.all(promises).then((data) => ({ data }));
}

Expand Down

0 comments on commit de92364

Please sign in to comment.