mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
17278 prometheus step align utc (#17477)
* Update datasource.ts * Update datasource.test.ts * utcOffset reverse from moment docs, utcOffset "function returns the real offset from UTC, not the reverse offset" * add utcOffset() to DateTime interface method returns the UTC offset as a number of minutes * Fixed test
This commit is contained in:
@@ -367,7 +367,7 @@ export class PrometheusDatasource extends DataSourceApi<PromQuery, PromOptions>
|
||||
|
||||
// Align query interval with step to allow query caching and to ensure
|
||||
// that about-same-time query results look the same.
|
||||
const adjusted = alignRange(start, end, query.step);
|
||||
const adjusted = alignRange(start, end, query.step, this.timeSrv.timeRange().to.utcOffset() * 60);
|
||||
query.start = adjusted.start;
|
||||
query.end = adjusted.end;
|
||||
this._addTracingHeaders(query, options);
|
||||
@@ -694,10 +694,16 @@ export class PrometheusDatasource extends DataSourceApi<PromQuery, PromOptions>
|
||||
* @param start Timestamp marking the beginning of the range.
|
||||
* @param end Timestamp marking the end of the range.
|
||||
* @param step Interval to align start and end with.
|
||||
* @param utcOffsetSec Number of seconds current timezone is offset from UTC
|
||||
*/
|
||||
export function alignRange(start: number, end: number, step: number): { end: number; start: number } {
|
||||
const alignedEnd = Math.floor(end / step) * step;
|
||||
const alignedStart = Math.floor(start / step) * step;
|
||||
export function alignRange(
|
||||
start: number,
|
||||
end: number,
|
||||
step: number,
|
||||
utcOffsetSec: number
|
||||
): { end: number; start: number } {
|
||||
const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;
|
||||
const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;
|
||||
return {
|
||||
end: alignedEnd,
|
||||
start: alignedStart,
|
||||
|
||||
Reference in New Issue
Block a user