diff --git a/packages/grafana-data/src/types/datasource.ts b/packages/grafana-data/src/types/datasource.ts index 0a170ede626..157902aff58 100644 --- a/packages/grafana-data/src/types/datasource.ts +++ b/packages/grafana-data/src/types/datasource.ts @@ -482,7 +482,9 @@ export interface DataQueryRequest { rangeRaw?: RawTimeRange; timeInfo?: string; // The query time description (blue text in the upper right) panelId?: number; + /** @deprecate */ dashboardId?: number; + dashboardUID?: string; publicDashboardAccessToken?: string; // Request Timing diff --git a/public/app/features/dashboard/components/PanelEditor/PanelEditorTableView.tsx b/public/app/features/dashboard/components/PanelEditor/PanelEditorTableView.tsx index fd4958d10b4..633d75ceef7 100644 --- a/public/app/features/dashboard/components/PanelEditor/PanelEditorTableView.tsx +++ b/public/app/features/dashboard/components/PanelEditor/PanelEditorTableView.tsx @@ -33,7 +33,13 @@ export function PanelEditorTableView({ width, height, panel, dashboard }: Props) const timeData = applyPanelTimeOverrides(panel, timeSrv.timeRange()); const sub = panel.events.subscribe(RefreshEvent, () => { - panel.runAllPanelQueries(dashboard.id, dashboard.getTimezone(), timeData, width); + panel.runAllPanelQueries({ + dashboardId: dashboard.id, + dashboardUID: dashboard.uid, + dashboardTimezone: dashboard.getTimezone(), + timeData, + width, + }); }); return () => { sub.unsubscribe(); diff --git a/public/app/features/dashboard/dashgrid/PanelChrome.tsx b/public/app/features/dashboard/dashgrid/PanelChrome.tsx index 00f9c7faccc..c9da152b671 100644 --- a/public/app/features/dashboard/dashgrid/PanelChrome.tsx +++ b/public/app/features/dashboard/dashgrid/PanelChrome.tsx @@ -318,13 +318,14 @@ export class PanelChrome extends PureComponent { if (this.state.refreshWhenInView) { this.setState({ refreshWhenInView: false }); } - panel.runAllPanelQueries( - dashboard.id, - dashboard.getTimezone(), + panel.runAllPanelQueries({ + dashboardId: dashboard.id, + dashboardUID: dashboard.uid, + dashboardTimezone: dashboard.getTimezone(), + publicDashboardAccessToken: dashboard.meta.publicDashboardAccessToken, timeData, width, - dashboard.meta.publicDashboardAccessToken - ); + }); } else { // The panel should render on refresh as well if it doesn't have a query, like clock panel this.setState({ diff --git a/public/app/features/dashboard/state/PanelModel.test.ts b/public/app/features/dashboard/state/PanelModel.test.ts index f867d85d9f3..7b81d663725 100644 --- a/public/app/features/dashboard/state/PanelModel.test.ts +++ b/public/app/features/dashboard/state/PanelModel.test.ts @@ -492,6 +492,7 @@ describe('PanelModel', () => { run: jest.fn(), }); const dashboardId = 123; + const dashboardUID = 'ggHbN42mk'; const dashboardTimezone = 'browser'; const width = 860; const timeData = { @@ -506,7 +507,7 @@ describe('PanelModel', () => { } as TimeRange, } as TimeOverrideResult; - model.runAllPanelQueries(dashboardId, dashboardTimezone, timeData, width); + model.runAllPanelQueries({ dashboardId, dashboardUID, dashboardTimezone, timeData, width }); expect(model.getQueryRunner).toBeCalled(); }); diff --git a/public/app/features/dashboard/state/PanelModel.ts b/public/app/features/dashboard/state/PanelModel.ts index d5672ea97b1..48b8ebe051f 100644 --- a/public/app/features/dashboard/state/PanelModel.ts +++ b/public/app/features/dashboard/state/PanelModel.ts @@ -50,6 +50,15 @@ export interface GridPos { static?: boolean; } +type RunPanelQueryOptions = { + /** @deprecate */ + dashboardId: number; + dashboardUID: string; + dashboardTimezone: string; + timeData: TimeOverrideResult; + width: number; + publicDashboardAccessToken?: string; +}; const notPersistedProperties: { [str: string]: boolean } = { events: true, isViewing: true, @@ -323,18 +332,20 @@ export class PanelModel implements DataConfigSource, IPanelModel { } } - runAllPanelQueries( - dashboardId: number, - dashboardTimezone: string, - timeData: TimeOverrideResult, - width: number, - publicDashboardAccessToken?: string - ) { + runAllPanelQueries({ + dashboardId, + dashboardUID, + dashboardTimezone, + timeData, + width, + publicDashboardAccessToken, + }: RunPanelQueryOptions) { this.getQueryRunner().run({ datasource: this.datasource, queries: this.targets, panelId: this.id, dashboardId: dashboardId, + dashboardUID: dashboardUID, publicDashboardAccessToken, timezone: dashboardTimezone, timeRange: timeData.timeRange, diff --git a/public/app/features/query/state/PanelQueryRunner.ts b/public/app/features/query/state/PanelQueryRunner.ts index 931954f87f8..eab8561d175 100644 --- a/public/app/features/query/state/PanelQueryRunner.ts +++ b/public/app/features/query/state/PanelQueryRunner.ts @@ -46,7 +46,9 @@ export interface QueryRunnerOptions< datasource: DataSourceRef | DataSourceApi | null; queries: TQuery[]; panelId?: number; + /** @deprecate */ dashboardId?: number; + dashboardUID?: string; publicDashboardAccessToken?: string; timezone: TimeZone; timeRange: TimeRange; @@ -203,6 +205,7 @@ export class PanelQueryRunner { datasource, panelId, dashboardId, + dashboardUID, publicDashboardAccessToken, timeRange, timeInfo, @@ -223,6 +226,7 @@ export class PanelQueryRunner { timezone, panelId, dashboardId, + dashboardUID, publicDashboardAccessToken, range: timeRange, timeInfo, diff --git a/public/app/plugins/datasource/prometheus/datasource.test.ts b/public/app/plugins/datasource/prometheus/datasource.test.ts index de61312c84b..38a5196ab14 100644 --- a/public/app/plugins/datasource/prometheus/datasource.test.ts +++ b/public/app/plugins/datasource/prometheus/datasource.test.ts @@ -1790,16 +1790,17 @@ describe('PrometheusDatasource for POST', () => { }); }); - describe('When querying prometheus via check headers X-Dashboard-Id and X-Panel-Id', () => { - const options = { dashboardId: 1, panelId: 2 }; + describe('When querying prometheus via check headers X-Dashboard-Id X-Panel-Id and X-Dashboard-UID', () => { + const options = { dashboardId: 1, panelId: 2, dashboardUID: 'WFlOM-jM1' }; const httpOptions = { headers: {} as { [key: string]: number | undefined }, }; it('with proxy access tracing headers should be added', () => { ds._addTracingHeaders(httpOptions as any, options as any); - expect(httpOptions.headers['X-Dashboard-Id']).toBe(1); - expect(httpOptions.headers['X-Panel-Id']).toBe(2); + expect(httpOptions.headers['X-Dashboard-Id']).toBe(options.dashboardId); + expect(httpOptions.headers['X-Panel-Id']).toBe(options.panelId); + expect(httpOptions.headers['X-Dashboard-UID']).toBe(options.dashboardUID); }); it('with direct access tracing headers should not be added', () => { @@ -1811,6 +1812,7 @@ describe('PrometheusDatasource for POST', () => { mockDs._addTracingHeaders(httpOptions as any, options as any); expect(httpOptions.headers['X-Dashboard-Id']).toBe(undefined); expect(httpOptions.headers['X-Panel-Id']).toBe(undefined); + expect(httpOptions.headers['X-Dashboard-UID']).toBe(undefined); }); }); }); @@ -1877,6 +1879,7 @@ describe('prepareTargets', () => { expr: 'up', headers: { 'X-Dashboard-Id': undefined, + 'X-Dashboard-UID': undefined, 'X-Panel-Id': panelId, }, hinting: undefined, @@ -2038,6 +2041,7 @@ describe('prepareTargets', () => { expr: 'up', headers: { 'X-Dashboard-Id': undefined, + 'X-Dashboard-UID': undefined, 'X-Panel-Id': panelId, }, hinting: undefined, @@ -2059,6 +2063,7 @@ describe('prepareTargets', () => { expr: 'up', headers: { 'X-Dashboard-Id': undefined, + 'X-Dashboard-UID': undefined, 'X-Panel-Id': panelId, }, hinting: undefined, @@ -2099,6 +2104,7 @@ describe('prepareTargets', () => { expr: 'up', headers: { 'X-Dashboard-Id': undefined, + 'X-Dashboard-UID': undefined, 'X-Panel-Id': panelId, }, hinting: undefined, @@ -2135,6 +2141,7 @@ describe('prepareTargets', () => { expr: 'up', headers: { 'X-Dashboard-Id': undefined, + 'X-Dashboard-UID': undefined, 'X-Panel-Id': panelId, }, hinting: undefined, diff --git a/public/app/plugins/datasource/prometheus/datasource.tsx b/public/app/plugins/datasource/prometheus/datasource.tsx index 98b72c1bd46..473771061d2 100644 --- a/public/app/plugins/datasource/prometheus/datasource.tsx +++ b/public/app/plugins/datasource/prometheus/datasource.tsx @@ -146,6 +146,7 @@ export class PrometheusDatasource const proxyMode = !this.url.match(/^http/); if (proxyMode) { httpOptions.headers['X-Dashboard-Id'] = options.dashboardId; + httpOptions.headers['X-Dashboard-UID'] = options.dashboardUID; httpOptions.headers['X-Panel-Id'] = options.panelId; } }