From f27199df88aa104672f0c3fa0caf245f08243820 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Mon, 8 Aug 2022 14:22:47 -0400 Subject: [PATCH] Graphite Plugin: fix annotation migration regression with ref-ids (#53361) (#53420) * fix regression with ref-ids * remove duplicate check for annotations in fix (cherry picked from commit 85db523dd52437ec6371a705a3c7cb7f685ad884) Co-authored-by: Brendan O'Handley --- .../plugins/datasource/graphite/datasource.ts | 80 +++++++++---------- 1 file changed, 38 insertions(+), 42 deletions(-) diff --git a/public/app/plugins/datasource/graphite/datasource.ts b/public/app/plugins/datasource/graphite/datasource.ts index e529c9290cb..d974a5f3f51 100644 --- a/public/app/plugins/datasource/graphite/datasource.ts +++ b/public/app/plugins/datasource/graphite/datasource.ts @@ -189,11 +189,10 @@ export class GraphiteDatasource } query(options: DataQueryRequest): Observable { - const streams: Array> = []; + if (options.targets.some((target: GraphiteQuery) => target.fromAnnotations)) { + const streams: Array> = []; - for (const target of options.targets) { - // hiding target is handled in buildGraphiteParams - if (target.fromAnnotations) { + for (const target of options.targets) { streams.push( new Observable((subscriber) => { this.annotationEvents(options.range, target) @@ -202,49 +201,46 @@ export class GraphiteDatasource .finally(() => subscriber.complete()); }) ); - } else { - // handle the queries here - const graphOptions = { - from: this.translateTime(options.range.from, false, options.timezone), - until: this.translateTime(options.range.to, true, options.timezone), - targets: options.targets, - format: (options as GraphiteQueryRequest).format, - cacheTimeout: options.cacheTimeout || this.cacheTimeout, - maxDataPoints: options.maxDataPoints, - }; - - const params = this.buildGraphiteParams(graphOptions, options.scopedVars); - if (params.length === 0) { - return of({ data: [] }); - } - - if (this.isMetricTank) { - params.push('meta=true'); - } - - const httpOptions: any = { - method: 'POST', - url: '/render', - data: params.join('&'), - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - }, - }; - - this.addTracingHeaders(httpOptions, options); - - if (options.panelId) { - httpOptions.requestId = this.name + '.panelId.' + options.panelId; - } - - streams.push(this.doGraphiteRequest(httpOptions).pipe(map(this.convertResponseToDataFrames))); } + + return merge(...streams); } - if (streams.length === 0) { + // handle the queries here + const graphOptions = { + from: this.translateTime(options.range.from, false, options.timezone), + until: this.translateTime(options.range.to, true, options.timezone), + targets: options.targets, + format: (options as GraphiteQueryRequest).format, + cacheTimeout: options.cacheTimeout || this.cacheTimeout, + maxDataPoints: options.maxDataPoints, + }; + + const params = this.buildGraphiteParams(graphOptions, options.scopedVars); + if (params.length === 0) { return of({ data: [] }); } - return merge(...streams); + + if (this.isMetricTank) { + params.push('meta=true'); + } + + const httpOptions: any = { + method: 'POST', + url: '/render', + data: params.join('&'), + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + }; + + this.addTracingHeaders(httpOptions, options); + + if (options.panelId) { + httpOptions.requestId = this.name + '.panelId.' + options.panelId; + } + + return this.doGraphiteRequest(httpOptions).pipe(map(this.convertResponseToDataFrames)); } addTracingHeaders(httpOptions: { headers: any }, options: { dashboardId?: number; panelId?: number }) {