From 6c0a5b121efb4a7dc86962a8a825b52b8384d8a1 Mon Sep 17 00:00:00 2001 From: Adam Simpson Date: Mon, 25 Apr 2022 13:59:52 -0400 Subject: [PATCH] CloudWatch: prevent log groups from being removed on query change. (#47994) * CloudWatch: prevent log groups from being removed on query change. Previously when a query was changed the existing log groups for that query were "dropped". The fix is to combine the new query with the existing query object in memory to preserve the log groups. fixes #33626 * CloudWatch: fix typos in runWithRetry documentation * chore: fix eslint issue --- packages/grafana-data/src/types/datasource.ts | 1 + .../app/features/query/components/QueryEditorRow.tsx | 1 + .../cloudwatch/components/LogsCheatSheet.tsx | 11 +++++++++-- .../plugins/datasource/cloudwatch/utils/logsRetry.ts | 4 ++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/grafana-data/src/types/datasource.ts b/packages/grafana-data/src/types/datasource.ts index c3bf11b2ef2..d05fc6985e6 100644 --- a/packages/grafana-data/src/types/datasource.ts +++ b/packages/grafana-data/src/types/datasource.ts @@ -416,6 +416,7 @@ export type ExploreQueryFieldProps< export interface QueryEditorHelpProps { datasource: DataSourceApi; + query: TQuery; onClickExample: (query: TQuery) => void; exploreId?: any; } diff --git a/public/app/features/query/components/QueryEditorRow.tsx b/public/app/features/query/components/QueryEditorRow.tsx index 4ed1185e9a2..f545f04c29b 100644 --- a/public/app/features/query/components/QueryEditorRow.tsx +++ b/public/app/features/query/components/QueryEditorRow.tsx @@ -416,6 +416,7 @@ export class QueryEditorRow extends PureComponent this.onClickExample(query)} + query={this.props.query} datasource={datasource} /> diff --git a/public/app/plugins/datasource/cloudwatch/components/LogsCheatSheet.tsx b/public/app/plugins/datasource/cloudwatch/components/LogsCheatSheet.tsx index 87aa2ae1df7..697720b3c35 100644 --- a/public/app/plugins/datasource/cloudwatch/components/LogsCheatSheet.tsx +++ b/public/app/plugins/datasource/cloudwatch/components/LogsCheatSheet.tsx @@ -229,8 +229,15 @@ export default class LogsCheatSheet extends PureComponent<
- this.onClickExample({ refId: 'A', expression: expr, queryMode: 'Logs', region: 'default', id: 'A' }) + onClick={() => + this.onClickExample({ + refId: this.props.query.refId ?? 'A', + expression: expr, + queryMode: 'Logs', + region: this.props.query.region, + id: this.props.query.refId ?? 'A', + logGroupNames: 'logGroupNames' in this.props.query ? this.props.query.logGroupNames : [], + }) } >
{renderHighlightedMarkup(expr, keyPrefix)}
diff --git a/public/app/plugins/datasource/cloudwatch/utils/logsRetry.ts b/public/app/plugins/datasource/cloudwatch/utils/logsRetry.ts index 9ff34b37737..eea4b7c2077 100644 --- a/public/app/plugins/datasource/cloudwatch/utils/logsRetry.ts +++ b/public/app/plugins/datasource/cloudwatch/utils/logsRetry.ts @@ -10,9 +10,9 @@ type Result = { frames: DataFrameJSON[]; error?: string }; /** * A retry strategy specifically for cloud watch logs query. Cloud watch logs queries need first starting the query * and the polling for the results. The start query can fail because of the concurrent queries rate limit, - * and so we hove to retry the start query call if there is already lot of queries running. + * and so we have to retry the start query call if there is already lot of queries running. * - * As we send multiple queries in single request some can fail and some can succeed and we have to also handle those + * As we send multiple queries in a single request some can fail and some can succeed and we have to also handle those * cases by only retrying the failed queries. We retry the failed queries until we hit the time limit or all queries * succeed and only then we pass the data forward. This means we wait longer but makes the code a bit simpler as we * can treat starting the query and polling as steps in a pipeline.