From 64e0a4282ef57d0d3efdf989fec67d21fbeac524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 21 Feb 2024 09:38:42 +0100 Subject: [PATCH] DataQuery: Track panel plugin id not type (#83091) --- packages/grafana-data/src/types/datasource.ts | 2 +- packages/grafana-runtime/src/analytics/types.ts | 2 +- .../src/utils/DataSourceWithBackend.ts | 6 +++--- pkg/api/pluginproxy/ds_proxy.go | 4 ++-- .../clientmiddleware/tracing_header_middleware.go | 2 +- pkg/services/query/query.go | 14 +++++++------- .../dashboard-scene/scene/DashboardScene.test.tsx | 4 ++-- .../dashboard-scene/scene/DashboardScene.tsx | 2 +- public/app/features/dashboard/state/PanelModel.ts | 2 +- .../app/features/query/state/PanelQueryRunner.ts | 6 +++--- .../features/query/state/queryAnalytics.test.ts | 12 ++++++------ public/app/features/query/state/queryAnalytics.ts | 2 +- .../app/plugins/datasource/graphite/datasource.ts | 6 +++--- 13 files changed, 32 insertions(+), 32 deletions(-) diff --git a/packages/grafana-data/src/types/datasource.ts b/packages/grafana-data/src/types/datasource.ts index 82232b4991d..7f20cb9273d 100644 --- a/packages/grafana-data/src/types/datasource.ts +++ b/packages/grafana-data/src/types/datasource.ts @@ -555,7 +555,7 @@ export interface DataQueryRequest { rangeRaw?: RawTimeRange; timeInfo?: string; // The query time description (blue text in the upper right) panelId?: number; - panelPluginType?: string; + panelPluginId?: string; dashboardUID?: string; /** Filters to dynamically apply to all queries */ diff --git a/packages/grafana-runtime/src/analytics/types.ts b/packages/grafana-runtime/src/analytics/types.ts index 07cfd4756b6..b67b5ef3d27 100644 --- a/packages/grafana-runtime/src/analytics/types.ts +++ b/packages/grafana-runtime/src/analytics/types.ts @@ -29,7 +29,7 @@ export interface DataRequestInfo extends Partial { datasourceUid: string; datasourceType: string; panelId?: number; - panelPluginType?: string; + panelPluginId?: string; panelName?: string; duration: number; error?: string; diff --git a/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts b/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts index 65d80f78475..204fc4bec2c 100644 --- a/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts +++ b/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts @@ -80,7 +80,7 @@ enum PluginRequestHeaders { DatasourceUID = 'X-Datasource-Uid', // can be used for routing/ load balancing DashboardUID = 'X-Dashboard-Uid', // mainly useful for debugging slow queries PanelID = 'X-Panel-Id', // mainly useful for debugging slow queries - PanelPluginType = 'X-Panel-Plugin-Type', + PanelPluginId = 'X-Panel-Plugin-Id', QueryGroupID = 'X-Query-Group-Id', // mainly useful to find related queries with query splitting FromExpression = 'X-Grafana-From-Expr', // used by datasources to identify expression queries SkipQueryCache = 'X-Cache-Skip', // used by datasources to skip the query cache @@ -227,8 +227,8 @@ class DataSourceWithBackend< if (request.panelId) { headers[PluginRequestHeaders.PanelID] = `${request.panelId}`; } - if (request.panelPluginType) { - headers[PluginRequestHeaders.PanelPluginType] = `${request.panelPluginType}`; + if (request.panelPluginId) { + headers[PluginRequestHeaders.PanelPluginId] = `${request.panelPluginId}`; } if (request.queryGroupId) { headers[PluginRequestHeaders.QueryGroupID] = `${request.queryGroupId}`; diff --git a/pkg/api/pluginproxy/ds_proxy.go b/pkg/api/pluginproxy/ds_proxy.go index 651d61bb1ce..8037c79a123 100644 --- a/pkg/api/pluginproxy/ds_proxy.go +++ b/pkg/api/pluginproxy/ds_proxy.go @@ -344,7 +344,7 @@ func (proxy *DataSourceProxy) logRequest() { } } - panelPluginType := proxy.ctx.Req.Header.Get("X-Panel-Plugin-Type") + panelPluginId := proxy.ctx.Req.Header.Get("X-Panel-Plugin-Id") ctxLogger := logger.FromContext(proxy.ctx.Req.Context()) ctxLogger.Info("Proxying incoming request", @@ -354,7 +354,7 @@ func (proxy *DataSourceProxy) logRequest() { "datasource", proxy.ds.Type, "uri", proxy.ctx.Req.RequestURI, "method", proxy.ctx.Req.Method, - "panelPluginType", panelPluginType, + "panelPluginId", panelPluginId, "body", body) } diff --git a/pkg/services/pluginsintegration/clientmiddleware/tracing_header_middleware.go b/pkg/services/pluginsintegration/clientmiddleware/tracing_header_middleware.go index 9cfcd07b48c..06003fe502d 100644 --- a/pkg/services/pluginsintegration/clientmiddleware/tracing_header_middleware.go +++ b/pkg/services/pluginsintegration/clientmiddleware/tracing_header_middleware.go @@ -34,7 +34,7 @@ func (m *TracingHeaderMiddleware) applyHeaders(ctx context.Context, req backend. return } - var headersList = []string{query.HeaderQueryGroupID, query.HeaderPanelID, query.HeaderDashboardUID, query.HeaderDatasourceUID, query.HeaderFromExpression, `X-Grafana-Org-Id`, query.HeaderPanelPluginType} + var headersList = []string{query.HeaderQueryGroupID, query.HeaderPanelID, query.HeaderDashboardUID, query.HeaderDatasourceUID, query.HeaderFromExpression, `X-Grafana-Org-Id`, query.HeaderPanelPluginId} for _, headerName := range headersList { gotVal := reqCtx.Req.Header.Get(headerName) diff --git a/pkg/services/query/query.go b/pkg/services/query/query.go index 328d730db21..90b6c9eb892 100644 --- a/pkg/services/query/query.go +++ b/pkg/services/query/query.go @@ -28,13 +28,13 @@ import ( ) const ( - HeaderPluginID = "X-Plugin-Id" // can be used for routing - HeaderDatasourceUID = "X-Datasource-Uid" // can be used for routing/ load balancing - HeaderDashboardUID = "X-Dashboard-Uid" // mainly useful for debugging slow queries - HeaderPanelID = "X-Panel-Id" // mainly useful for debugging slow queries - HeaderPanelPluginType = "X-Panel-Plugin-Type" - HeaderQueryGroupID = "X-Query-Group-Id" // mainly useful for finding related queries with query chunking - HeaderFromExpression = "X-Grafana-From-Expr" // used by datasources to identify expression queries + HeaderPluginID = "X-Plugin-Id" // can be used for routing + HeaderDatasourceUID = "X-Datasource-Uid" // can be used for routing/ load balancing + HeaderDashboardUID = "X-Dashboard-Uid" // mainly useful for debugging slow queries + HeaderPanelID = "X-Panel-Id" // mainly useful for debugging slow queries + HeaderPanelPluginId = "X-Panel-Plugin-Id" + HeaderQueryGroupID = "X-Query-Group-Id" // mainly useful for finding related queries with query chunking + HeaderFromExpression = "X-Grafana-From-Expr" // used by datasources to identify expression queries ) func ProvideService( diff --git a/public/app/features/dashboard-scene/scene/DashboardScene.test.tsx b/public/app/features/dashboard-scene/scene/DashboardScene.test.tsx index ed36aba0442..0e6ea10a4ed 100644 --- a/public/app/features/dashboard-scene/scene/DashboardScene.test.tsx +++ b/public/app/features/dashboard-scene/scene/DashboardScene.test.tsx @@ -123,13 +123,13 @@ describe('DashboardScene', () => { scene.onEnterEditMode(); }); - it('Should add app, uid, panelId and panelPluginType', () => { + it('Should add app, uid, panelId and panelPluginId', () => { const queryRunner = sceneGraph.findObject(scene, (o) => o.state.key === 'data-query-runner')!; expect(scene.enrichDataRequest(queryRunner)).toEqual({ app: CoreApp.Dashboard, dashboardUID: 'dash-1', panelId: 1, - panelPluginType: 'table', + panelPluginId: 'table', }); }); diff --git a/public/app/features/dashboard-scene/scene/DashboardScene.tsx b/public/app/features/dashboard-scene/scene/DashboardScene.tsx index e78c453fa88..412448b1f58 100644 --- a/public/app/features/dashboard-scene/scene/DashboardScene.tsx +++ b/public/app/features/dashboard-scene/scene/DashboardScene.tsx @@ -555,7 +555,7 @@ export class DashboardScene extends SceneObjectBase { app: CoreApp.Dashboard, dashboardUID: this.state.uid, panelId, - panelPluginType: panel?.state.pluginId, + panelPluginId: panel?.state.pluginId, }; } diff --git a/public/app/features/dashboard/state/PanelModel.ts b/public/app/features/dashboard/state/PanelModel.ts index 2bf12614a0d..fcf1307a284 100644 --- a/public/app/features/dashboard/state/PanelModel.ts +++ b/public/app/features/dashboard/state/PanelModel.ts @@ -377,7 +377,7 @@ export class PanelModel implements DataConfigSource, IPanelModel { datasource: this.datasource, queries: this.targets, panelId: this.id, - panelPluginType: this.type, + panelPluginId: this.type, dashboardUID: dashboardUID, timezone: dashboardTimezone, timeRange: timeData.timeRange, diff --git a/public/app/features/query/state/PanelQueryRunner.ts b/public/app/features/query/state/PanelQueryRunner.ts index 5a79e3d0014..940894c0460 100644 --- a/public/app/features/query/state/PanelQueryRunner.ts +++ b/public/app/features/query/state/PanelQueryRunner.ts @@ -50,7 +50,7 @@ export interface QueryRunnerOptions< datasource: DataSourceRef | DataSourceApi | null; queries: TQuery[]; panelId?: number; - panelPluginType?: string; + panelPluginId?: string; dashboardUID?: string; timezone: TimeZone; timeRange: TimeRange; @@ -258,7 +258,7 @@ export class PanelQueryRunner { timezone, datasource, panelId, - panelPluginType, + panelPluginId, dashboardUID, timeRange, timeInfo, @@ -280,7 +280,7 @@ export class PanelQueryRunner { requestId: getNextRequestId(), timezone, panelId, - panelPluginType, + panelPluginId, dashboardUID, range: timeRange, timeInfo, diff --git a/public/app/features/query/state/queryAnalytics.test.ts b/public/app/features/query/state/queryAnalytics.test.ts index b71f3d893a4..2d0dadf99d8 100644 --- a/public/app/features/query/state/queryAnalytics.test.ts +++ b/public/app/features/query/state/queryAnalytics.test.ts @@ -103,7 +103,7 @@ function getTestData( scopedVars: {}, targets: [], timezone: 'utc', - panelPluginType: 'timeseries', + panelPluginId: 'timeseries', ...overrides, }, series: series || [], @@ -135,7 +135,7 @@ describe('emitDataRequestEvent', () => { duration: 1, totalQueries: 0, cachedQueries: 0, - panelPluginType: 'timeseries', + panelPluginId: 'timeseries', }) ); }); @@ -163,7 +163,7 @@ describe('emitDataRequestEvent', () => { duration: 1, totalQueries: 2, cachedQueries: 1, - panelPluginType: 'timeseries', + panelPluginId: 'timeseries', }) ); }); @@ -191,7 +191,7 @@ describe('emitDataRequestEvent', () => { duration: 1, totalQueries: 1, cachedQueries: 1, - panelPluginType: 'timeseries', + panelPluginId: 'timeseries', }) ); }); @@ -238,7 +238,7 @@ describe('emitDataRequestEvent', () => { dataSize: 0, duration: 1, totalQueries: 0, - panelPluginType: 'timeseries', + panelPluginId: 'timeseries', }) ); }); @@ -275,7 +275,7 @@ describe('emitDataRequestEvent', () => { dataSize: 0, duration: 1, totalQueries: 0, - panelPluginType: 'timeseries', + panelPluginId: 'timeseries', }) ); }); diff --git a/public/app/features/query/state/queryAnalytics.ts b/public/app/features/query/state/queryAnalytics.ts index f8bb3afae5c..337fe6d4b00 100644 --- a/public/app/features/query/state/queryAnalytics.ts +++ b/public/app/features/query/state/queryAnalytics.ts @@ -29,7 +29,7 @@ export function emitDataRequestEvent(datasource: DataSourceApi) { datasourceType: datasource.type, dataSize: 0, panelId: 0, - panelPluginType: data.request?.panelPluginType, + panelPluginId: data.request?.panelPluginId, duration: data.request.endTime! - data.request.startTime, }; diff --git a/public/app/plugins/datasource/graphite/datasource.ts b/public/app/plugins/datasource/graphite/datasource.ts index 34b8165641a..90ce33533e3 100644 --- a/public/app/plugins/datasource/graphite/datasource.ts +++ b/public/app/plugins/datasource/graphite/datasource.ts @@ -248,7 +248,7 @@ export class GraphiteDatasource addTracingHeaders( httpOptions: { headers: any }, - options: { dashboardId?: number; panelId?: number; panelPluginType?: string } + options: { dashboardId?: number; panelId?: number; panelPluginId?: string } ) { const proxyMode = !this.url.match(/^http/); if (proxyMode) { @@ -258,8 +258,8 @@ export class GraphiteDatasource if (options.panelId) { httpOptions.headers['X-Panel-Id'] = options.panelId; } - if (options.panelPluginType) { - httpOptions.headers['X-Panel-Plugin-Id'] = options.panelPluginType; + if (options.panelPluginId) { + httpOptions.headers['X-Panel-Plugin-Id'] = options.panelPluginId; } } }