From 629cb1dee030f4c3fb311e54ac6f08b6ff3e7144 Mon Sep 17 00:00:00 2001 From: Kevin Yu Date: Wed, 20 Aug 2025 09:41:17 -0700 Subject: [PATCH] CloudWatch: Fix logs query requestId to prevent setting undefined-logs as a requestId (#109930) --- .../query-runner/CloudWatchLogsQueryRunner.test.ts | 11 +++++++++++ .../query-runner/CloudWatchLogsQueryRunner.ts | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/public/app/plugins/datasource/cloudwatch/query-runner/CloudWatchLogsQueryRunner.test.ts b/public/app/plugins/datasource/cloudwatch/query-runner/CloudWatchLogsQueryRunner.test.ts index d6a40c4b89c..b38fd288633 100644 --- a/public/app/plugins/datasource/cloudwatch/query-runner/CloudWatchLogsQueryRunner.test.ts +++ b/public/app/plugins/datasource/cloudwatch/query-runner/CloudWatchLogsQueryRunner.test.ts @@ -76,6 +76,17 @@ describe('CloudWatchLogsQueryRunner', () => { }); }); + it('does not append -logs to the requestId if requestId is not provided', async () => { + const { runner, queryMock } = setupMockedLogsQueryRunner(); + + const request = { + ...LogsRequestMock, + }; + await expect(runner.handleLogQueries(LogsRequestMock.targets, request, queryMock)).toEmitValuesWith(() => { + expect(queryMock.mock.calls[0][0].requestId).toEqual(''); + }); + }); + it('should request to start each query and then request to get the query results', async () => { const { runner } = setupMockedLogsQueryRunner(); diff --git a/public/app/plugins/datasource/cloudwatch/query-runner/CloudWatchLogsQueryRunner.ts b/public/app/plugins/datasource/cloudwatch/query-runner/CloudWatchLogsQueryRunner.ts index 97ba156b287..0ccc22029c1 100644 --- a/public/app/plugins/datasource/cloudwatch/query-runner/CloudWatchLogsQueryRunner.ts +++ b/public/app/plugins/datasource/cloudwatch/query-runner/CloudWatchLogsQueryRunner.ts @@ -415,12 +415,14 @@ export class CloudWatchLogsQueryRunner extends CloudWatchRequest { options?: DataQueryRequest ): Observable { const range = options?.range || getDefaultTimeRange(); + // append -logs to prevent requestId from matching metric queries from the same panel + const requestId = options?.requestId ? `${options?.requestId}-logs` : ''; const requestParams: DataQueryRequest = { ...options, range, skipQueryCache: true, - requestId: options?.requestId + '-logs' || '', // adding -logs to prevent requestId from matching metric queries from the same panel + requestId, interval: options?.interval || '', // dummy intervalMs: options?.intervalMs || 1, // dummy scopedVars: options?.scopedVars || {}, // dummy