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', () => {
// wait a bit
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', () => {
......@@ -277,7 +277,6 @@ const expectThatRangeHasNotMutated = (ctx: ScenarioCtx) => {
// 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].error).not.toBeDefined();
expect(ctx.results[0].state).toBe(LoadingState.Done);
};
async function sleep(ms: number) {
......
......@@ -17,6 +17,7 @@ import {
guessFieldTypes,
LoadingState,
PanelData,
TimeRange,
toDataFrame,
} from '@grafana/data';
import { toDataQueryError } from '@grafana/runtime';
......@@ -45,16 +46,6 @@ export function processResponsePacket(packet: DataQueryResponse, state: RunningQ
let loadingState = packet.state || LoadingState.Done;
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 annotations: DataQueryResponseData[] = [];
......@@ -78,6 +69,8 @@ export function processResponsePacket(packet: DataQueryResponse, state: RunningQ
}
}
const timeRange = getRequestTimeRange(request, loadingState);
const panelData = {
state: loadingState,
series,
......@@ -90,6 +83,20 @@ export function processResponsePacket(packet: DataQueryResponse, state: RunningQ
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
* 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