From 3e47fb1432c6985280466550ed62d2f767d709b6 Mon Sep 17 00:00:00 2001 From: Andrej Ocenas Date: Fri, 1 Oct 2021 09:45:37 +0200 Subject: [PATCH] CloudWatch Logs: Skip caching for Log queries (#39860) * Add x-skip-cache header to queries * Specify caching works for CW metrics --- docs/sources/enterprise/query-caching.md | 2 +- .../datasource/cloudwatch/datasource.ts | 42 +++++++++++++------ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/docs/sources/enterprise/query-caching.md b/docs/sources/enterprise/query-caching.md index a4ec257fcd3..a5cd8c244c5 100644 --- a/docs/sources/enterprise/query-caching.md +++ b/docs/sources/enterprise/query-caching.md @@ -31,7 +31,7 @@ You can make a panel retrieve fresh data more frequently by increasing the **Max Query caching works for all [Enterprise data sources](https://grafana.com/grafana/plugins/?type=datasource&enterprise=1), and it works for the following [built-in data sources]({{< relref "../datasources/_index.md" >}}): -- CloudWatch +- CloudWatch Metrics - Google Cloud Monitoring - InfluxDB - Microsoft SQL Server diff --git a/public/app/plugins/datasource/cloudwatch/datasource.ts b/public/app/plugins/datasource/cloudwatch/datasource.ts index 4ec2b47fb42..65d988a8d51 100644 --- a/public/app/plugins/datasource/cloudwatch/datasource.ts +++ b/public/app/plugins/datasource/cloudwatch/datasource.ts @@ -159,7 +159,10 @@ export class CloudWatchDatasource extends DataSourceWithBackend // This queries for the results this.logsQuery( @@ -258,7 +261,7 @@ export class CloudWatchDatasource extends DataSourceWithBackend this.makeLogActionRequest('GetQueryResults', queryParams)), + concatMap((_) => this.makeLogActionRequest('GetQueryResults', queryParams, { skipCache: true })), repeat(), share() ); @@ -337,8 +340,10 @@ export class CloudWatchDatasource extends DataSourceWithBackend ({ queryId: logQuery.id, region: logQuery.region })), - undefined, - false + { + makeReplacements: false, + skipCache: true, + } ).pipe( finalize(() => { this.logQueries = {}; @@ -511,8 +516,14 @@ export class CloudWatchDatasource extends DataSourceWithBackend { const range = this.timeSrv.timeRange(); @@ -530,26 +541,32 @@ export class CloudWatchDatasource extends DataSourceWithBackend { if (query.hasOwnProperty('queryString')) { - query.queryString = this.replace(query.queryString, scopedVars, true); + query.queryString = this.replace(query.queryString, options.scopedVars, true); } - query.region = this.replace(query.region, scopedVars, true, 'region'); + query.region = this.replace(query.region, options.scopedVars, true, 'region'); query.region = this.getActualRegion(query.region); // interpolate log groups if (query.logGroupNames) { query.logGroupNames = query.logGroupNames.map((logGroup: string) => - this.replace(logGroup, scopedVars, true, 'log groups') + this.replace(logGroup, options.scopedVars, true, 'log groups') ); } }); } const resultsToDataFrames = (val: any): DataFrame[] => toDataQueryResponse(val).data || []; + let headers = {}; + if (options.skipCache) { + headers = { + 'X-Cache-Skip': true, + }; + } - return this.awsRequest(DS_QUERY_ENDPOINT, requestParams).pipe( + return this.awsRequest(DS_QUERY_ENDPOINT, requestParams, headers).pipe( map((response) => resultsToDataFrames({ data: response })), catchError((err) => { if (err.data?.error) { @@ -794,11 +811,12 @@ export class CloudWatchDatasource extends DataSourceWithBackend { + awsRequest(url: string, data: MetricRequest, headers: Record = {}): Observable { const options = { method: 'POST', url, data, + headers, }; return getBackendSrv()