Commit b52f9fed by Torkel Ödegaard Committed by GitHub

runRequest: Fixes issue with request time range and time range returned to…

runRequest: Fixes issue with request time range and time range returned to panels are off causing data points to be cut off (outside) (#30227)

* runRequest: Fixes issue with request time range and time range returned to panels are off causing data points to be cut off (outside)

* Updated test
parent d8b4ed3a
...@@ -218,7 +218,7 @@ describe('runRequest', () => { ...@@ -218,7 +218,7 @@ describe('runRequest', () => {
// wait a bit // wait a bit
await sleep(20); await sleep(20);
ctx.emitPacket({ data: [{ name: 'DataB-1' } as DataFrame] }); ctx.emitPacket({ data: [{ name: 'DataB-1' } as DataFrame], state: LoadingState.Streaming });
}); });
it('should add the correct timeRange property and the request range should not be mutated', () => { it('should add the correct timeRange property and the request range should not be mutated', () => {
...@@ -277,7 +277,6 @@ const expectThatRangeHasNotMutated = (ctx: ScenarioCtx) => { ...@@ -277,7 +277,6 @@ const expectThatRangeHasNotMutated = (ctx: ScenarioCtx) => {
// Make sure that the range for request is not changed and that deepfreeze hasn't thrown // Make sure that the range for request is not changed and that deepfreeze hasn't thrown
expect(ctx.results[0].request?.range?.to.valueOf()).toBe(ctx.toStartTime.valueOf()); expect(ctx.results[0].request?.range?.to.valueOf()).toBe(ctx.toStartTime.valueOf());
expect(ctx.results[0].error).not.toBeDefined(); expect(ctx.results[0].error).not.toBeDefined();
expect(ctx.results[0].state).toBe(LoadingState.Done);
}; };
async function sleep(ms: number) { async function sleep(ms: number) {
......
...@@ -17,6 +17,7 @@ import { ...@@ -17,6 +17,7 @@ import {
guessFieldTypes, guessFieldTypes,
LoadingState, LoadingState,
PanelData, PanelData,
TimeRange,
toDataFrame, toDataFrame,
} from '@grafana/data'; } from '@grafana/data';
import { toDataQueryError } from '@grafana/runtime'; import { toDataQueryError } from '@grafana/runtime';
...@@ -45,16 +46,6 @@ export function processResponsePacket(packet: DataQueryResponse, state: RunningQ ...@@ -45,16 +46,6 @@ export function processResponsePacket(packet: DataQueryResponse, state: RunningQ
let loadingState = packet.state || LoadingState.Done; let loadingState = packet.state || LoadingState.Done;
let error: DataQueryError | undefined = undefined; let error: DataQueryError | undefined = undefined;
// Update the time range
const range = { ...request.range };
const timeRange = isString(range.raw.from)
? {
from: dateMath.parse(range.raw.from, false)!,
to: dateMath.parse(range.raw.to, true)!,
raw: range.raw,
}
: range;
const series: DataQueryResponseData[] = []; const series: DataQueryResponseData[] = [];
const annotations: DataQueryResponseData[] = []; const annotations: DataQueryResponseData[] = [];
...@@ -78,6 +69,8 @@ export function processResponsePacket(packet: DataQueryResponse, state: RunningQ ...@@ -78,6 +69,8 @@ export function processResponsePacket(packet: DataQueryResponse, state: RunningQ
} }
} }
const timeRange = getRequestTimeRange(request, loadingState);
const panelData = { const panelData = {
state: loadingState, state: loadingState,
series, series,
...@@ -90,6 +83,20 @@ export function processResponsePacket(packet: DataQueryResponse, state: RunningQ ...@@ -90,6 +83,20 @@ export function processResponsePacket(packet: DataQueryResponse, state: RunningQ
return { packets, panelData }; return { packets, panelData };
} }
function getRequestTimeRange(request: DataQueryRequest, loadingState: LoadingState): TimeRange {
const range = request.range;
if (!isString(range.raw.from) || loadingState !== LoadingState.Streaming) {
return range;
}
return {
...range,
from: dateMath.parse(range.raw.from, false)!,
to: dateMath.parse(range.raw.to, true)!,
};
}
/** /**
* This function handles the execution of requests & and processes the single or multiple response packets into * This function handles the execution of requests & and processes the single or multiple response packets into
* a combined PanelData response. It will * a combined PanelData response. It will
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment