From a2aea701004cb3fc42fced32ea976b33128d7593 Mon Sep 17 00:00:00 2001 From: Andrej Ocenas Date: Tue, 21 May 2024 13:12:27 +0200 Subject: [PATCH] Tempo: Don't modify the passed time range when using timeShiftEnabled (#87980) Don't modify the passed range --- .../datasource/tempo/datasource.test.ts | 20 ++++++++++++------- .../plugins/datasource/tempo/datasource.ts | 7 +++++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/public/app/plugins/datasource/tempo/datasource.test.ts b/public/app/plugins/datasource/tempo/datasource.test.ts index 957eefec24a..2cc8f39594e 100644 --- a/public/app/plugins/datasource/tempo/datasource.test.ts +++ b/public/app/plugins/datasource/tempo/datasource.test.ts @@ -386,6 +386,12 @@ describe('Tempo data source', () => { jsonData: { traceQuery: { timeShiftEnabled: true, spanStartTimeShift: '2m', spanEndTimeShift: '4m' } }, }); + const range = { + from: dateTime(new Date(2022, 8, 13, 16, 0, 0, 0)), + to: dateTime(new Date(2022, 8, 13, 16, 15, 0, 0)), + raw: { from: '15m', to: 'now' }, + }; + const request = ds.traceIdQueryRequest( { requestId: 'test', @@ -396,17 +402,17 @@ describe('Tempo data source', () => { timezone: '', app: '', startTime: 0, - range: { - from: dateTime(new Date(2022, 8, 13, 16, 0, 0, 0)), - to: dateTime(new Date(2022, 8, 13, 16, 15, 0, 0)), - raw: { from: '15m', to: 'now' }, - }, + range, }, [{ refId: 'refid1', queryType: 'traceql', query: '' } as TempoQuery] ); - expect(request.range.from.unix()).toBe(dateTime(new Date(2022, 8, 13, 15, 58, 0, 0)).unix()); - expect(request.range.to.unix()).toBe(dateTime(new Date(2022, 8, 13, 16, 19, 0, 0)).unix()); + expect(request.range.from.valueOf()).toBe(new Date(2022, 8, 13, 15, 58, 0, 0).valueOf()); + expect(request.range.to.valueOf()).toBe(new Date(2022, 8, 13, 16, 19, 0, 0).valueOf()); + + // Making sure we don't modify the original range + expect(range.from.valueOf()).toBe(new Date(2022, 8, 13, 16, 0, 0, 0).valueOf()); + expect(range.to.valueOf()).toBe(new Date(2022, 8, 13, 16, 15, 0, 0).valueOf()); }); it('should not include time shift when querying for traceID and time shift config is off', () => { diff --git a/public/app/plugins/datasource/tempo/datasource.ts b/public/app/plugins/datasource/tempo/datasource.ts index e69237518c0..2f48b0abdd1 100644 --- a/public/app/plugins/datasource/tempo/datasource.ts +++ b/public/app/plugins/datasource/tempo/datasource.ts @@ -669,11 +669,14 @@ export class TempoDatasource extends DataSourceWithBackend