From cc589a0d76339237bd04492b2b258aa537ead462 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Sun, 16 Feb 2020 05:12:40 -0800 Subject: [PATCH] Inspector: find the datasource from the refId, not the metadata (#22231) * remove datasource * get datasoure from refId * metrictank does not need to say the datasource --- packages/grafana-data/src/types/data.ts | 4 ---- .../components/Inspector/PanelInspector.tsx | 22 +++++++++++-------- .../plugins/datasource/graphite/datasource.ts | 1 - 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/grafana-data/src/types/data.ts b/packages/grafana-data/src/types/data.ts index 70f044b0c5e..59cbd95dc26 100644 --- a/packages/grafana-data/src/types/data.ts +++ b/packages/grafana-data/src/types/data.ts @@ -20,10 +20,6 @@ export interface QueryResultMeta { // Used in Explore to show limit applied to search result limit?: number; - // HACK: save the datassource name in the meta so we can load it from the response - // we should be able to find the datasource from the refId - datasource?: string; - // DatasSource Specific Values custom?: Record; } diff --git a/public/app/features/dashboard/components/Inspector/PanelInspector.tsx b/public/app/features/dashboard/components/Inspector/PanelInspector.tsx index d45ea9b4511..7f87cd5a4bc 100644 --- a/public/app/features/dashboard/components/Inspector/PanelInspector.tsx +++ b/public/app/features/dashboard/components/Inspector/PanelInspector.tsx @@ -16,6 +16,7 @@ import { toCSV, DataQueryError, PanelData, + DataQuery, } from '@grafana/data'; import { config } from 'app/core/config'; @@ -106,22 +107,25 @@ export class PanelInspector extends PureComponent { return; } - // Find the first DataSource wanting to show custom metadata let metaDS: DataSourceApi; const data = lastResult.series; const error = lastResult.error; - const targets = lastResult.request?.targets; + const targets = lastResult.request?.targets || []; const requestTime = lastResult.request?.endTime ? lastResult.request?.endTime - lastResult.request.startTime : -1; - const queries = targets ? targets.length : 0; - const dataSources = new Set(targets.map(t => t.datasource)).size; - if (data) { + // Find the first DataSource wanting to show custom metadata + if (data && targets.length) { + const queries: Record = {}; + for (const target of targets) { + queries[target.refId] = target; + } + for (const frame of data) { - const key = frame.meta?.datasource; - if (key) { - const dataSource = await getDataSourceSrv().get(key); + const q = queries[frame.refId]; + if (q && frame.meta.custom) { + const dataSource = await getDataSourceSrv().get(q.datasource); if (dataSource && dataSource.components?.MetadataInspector) { metaDS = dataSource; break; @@ -138,7 +142,7 @@ export class PanelInspector extends PureComponent { tab: error ? InspectTab.Error : prevState.tab, stats: { requestTime, - queries, + queries: targets.length, dataSources, }, })); diff --git a/public/app/plugins/datasource/graphite/datasource.ts b/public/app/plugins/datasource/graphite/datasource.ts index a2393085286..784d5ca849e 100644 --- a/public/app/plugins/datasource/graphite/datasource.ts +++ b/public/app/plugins/datasource/graphite/datasource.ts @@ -124,7 +124,6 @@ export class GraphiteDatasource extends DataSourceApi