added dashboard uid when tracing header in browsermode (#53232)

This commit is contained in:
Leo
2022-08-10 10:36:19 +02:00
committed by GitHub
parent aa484a60c9
commit c4984854b6
8 changed files with 51 additions and 18 deletions

View File

@@ -482,7 +482,9 @@ export interface DataQueryRequest<TQuery extends DataQuery = DataQuery> {
rangeRaw?: RawTimeRange; rangeRaw?: RawTimeRange;
timeInfo?: string; // The query time description (blue text in the upper right) timeInfo?: string; // The query time description (blue text in the upper right)
panelId?: number; panelId?: number;
/** @deprecate */
dashboardId?: number; dashboardId?: number;
dashboardUID?: string;
publicDashboardAccessToken?: string; publicDashboardAccessToken?: string;
// Request Timing // Request Timing

View File

@@ -33,7 +33,13 @@ export function PanelEditorTableView({ width, height, panel, dashboard }: Props)
const timeData = applyPanelTimeOverrides(panel, timeSrv.timeRange()); const timeData = applyPanelTimeOverrides(panel, timeSrv.timeRange());
const sub = panel.events.subscribe(RefreshEvent, () => { 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 () => { return () => {
sub.unsubscribe(); sub.unsubscribe();

View File

@@ -318,13 +318,14 @@ export class PanelChrome extends PureComponent<Props, State> {
if (this.state.refreshWhenInView) { if (this.state.refreshWhenInView) {
this.setState({ refreshWhenInView: false }); this.setState({ refreshWhenInView: false });
} }
panel.runAllPanelQueries( panel.runAllPanelQueries({
dashboard.id, dashboardId: dashboard.id,
dashboard.getTimezone(), dashboardUID: dashboard.uid,
dashboardTimezone: dashboard.getTimezone(),
publicDashboardAccessToken: dashboard.meta.publicDashboardAccessToken,
timeData, timeData,
width, width,
dashboard.meta.publicDashboardAccessToken });
);
} else { } else {
// The panel should render on refresh as well if it doesn't have a query, like clock panel // The panel should render on refresh as well if it doesn't have a query, like clock panel
this.setState({ this.setState({

View File

@@ -492,6 +492,7 @@ describe('PanelModel', () => {
run: jest.fn(), run: jest.fn(),
}); });
const dashboardId = 123; const dashboardId = 123;
const dashboardUID = 'ggHbN42mk';
const dashboardTimezone = 'browser'; const dashboardTimezone = 'browser';
const width = 860; const width = 860;
const timeData = { const timeData = {
@@ -506,7 +507,7 @@ describe('PanelModel', () => {
} as TimeRange, } as TimeRange,
} as TimeOverrideResult; } as TimeOverrideResult;
model.runAllPanelQueries(dashboardId, dashboardTimezone, timeData, width); model.runAllPanelQueries({ dashboardId, dashboardUID, dashboardTimezone, timeData, width });
expect(model.getQueryRunner).toBeCalled(); expect(model.getQueryRunner).toBeCalled();
}); });

View File

@@ -50,6 +50,15 @@ export interface GridPos {
static?: boolean; static?: boolean;
} }
type RunPanelQueryOptions = {
/** @deprecate */
dashboardId: number;
dashboardUID: string;
dashboardTimezone: string;
timeData: TimeOverrideResult;
width: number;
publicDashboardAccessToken?: string;
};
const notPersistedProperties: { [str: string]: boolean } = { const notPersistedProperties: { [str: string]: boolean } = {
events: true, events: true,
isViewing: true, isViewing: true,
@@ -323,18 +332,20 @@ export class PanelModel implements DataConfigSource, IPanelModel {
} }
} }
runAllPanelQueries( runAllPanelQueries({
dashboardId: number, dashboardId,
dashboardTimezone: string, dashboardUID,
timeData: TimeOverrideResult, dashboardTimezone,
width: number, timeData,
publicDashboardAccessToken?: string width,
) { publicDashboardAccessToken,
}: RunPanelQueryOptions) {
this.getQueryRunner().run({ this.getQueryRunner().run({
datasource: this.datasource, datasource: this.datasource,
queries: this.targets, queries: this.targets,
panelId: this.id, panelId: this.id,
dashboardId: dashboardId, dashboardId: dashboardId,
dashboardUID: dashboardUID,
publicDashboardAccessToken, publicDashboardAccessToken,
timezone: dashboardTimezone, timezone: dashboardTimezone,
timeRange: timeData.timeRange, timeRange: timeData.timeRange,

View File

@@ -46,7 +46,9 @@ export interface QueryRunnerOptions<
datasource: DataSourceRef | DataSourceApi<TQuery, TOptions> | null; datasource: DataSourceRef | DataSourceApi<TQuery, TOptions> | null;
queries: TQuery[]; queries: TQuery[];
panelId?: number; panelId?: number;
/** @deprecate */
dashboardId?: number; dashboardId?: number;
dashboardUID?: string;
publicDashboardAccessToken?: string; publicDashboardAccessToken?: string;
timezone: TimeZone; timezone: TimeZone;
timeRange: TimeRange; timeRange: TimeRange;
@@ -203,6 +205,7 @@ export class PanelQueryRunner {
datasource, datasource,
panelId, panelId,
dashboardId, dashboardId,
dashboardUID,
publicDashboardAccessToken, publicDashboardAccessToken,
timeRange, timeRange,
timeInfo, timeInfo,
@@ -223,6 +226,7 @@ export class PanelQueryRunner {
timezone, timezone,
panelId, panelId,
dashboardId, dashboardId,
dashboardUID,
publicDashboardAccessToken, publicDashboardAccessToken,
range: timeRange, range: timeRange,
timeInfo, timeInfo,

View File

@@ -1790,16 +1790,17 @@ describe('PrometheusDatasource for POST', () => {
}); });
}); });
describe('When querying prometheus via check headers X-Dashboard-Id and X-Panel-Id', () => { describe('When querying prometheus via check headers X-Dashboard-Id X-Panel-Id and X-Dashboard-UID', () => {
const options = { dashboardId: 1, panelId: 2 }; const options = { dashboardId: 1, panelId: 2, dashboardUID: 'WFlOM-jM1' };
const httpOptions = { const httpOptions = {
headers: {} as { [key: string]: number | undefined }, headers: {} as { [key: string]: number | undefined },
}; };
it('with proxy access tracing headers should be added', () => { it('with proxy access tracing headers should be added', () => {
ds._addTracingHeaders(httpOptions as any, options as any); ds._addTracingHeaders(httpOptions as any, options as any);
expect(httpOptions.headers['X-Dashboard-Id']).toBe(1); expect(httpOptions.headers['X-Dashboard-Id']).toBe(options.dashboardId);
expect(httpOptions.headers['X-Panel-Id']).toBe(2); 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', () => { 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); mockDs._addTracingHeaders(httpOptions as any, options as any);
expect(httpOptions.headers['X-Dashboard-Id']).toBe(undefined); expect(httpOptions.headers['X-Dashboard-Id']).toBe(undefined);
expect(httpOptions.headers['X-Panel-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', expr: 'up',
headers: { headers: {
'X-Dashboard-Id': undefined, 'X-Dashboard-Id': undefined,
'X-Dashboard-UID': undefined,
'X-Panel-Id': panelId, 'X-Panel-Id': panelId,
}, },
hinting: undefined, hinting: undefined,
@@ -2038,6 +2041,7 @@ describe('prepareTargets', () => {
expr: 'up', expr: 'up',
headers: { headers: {
'X-Dashboard-Id': undefined, 'X-Dashboard-Id': undefined,
'X-Dashboard-UID': undefined,
'X-Panel-Id': panelId, 'X-Panel-Id': panelId,
}, },
hinting: undefined, hinting: undefined,
@@ -2059,6 +2063,7 @@ describe('prepareTargets', () => {
expr: 'up', expr: 'up',
headers: { headers: {
'X-Dashboard-Id': undefined, 'X-Dashboard-Id': undefined,
'X-Dashboard-UID': undefined,
'X-Panel-Id': panelId, 'X-Panel-Id': panelId,
}, },
hinting: undefined, hinting: undefined,
@@ -2099,6 +2104,7 @@ describe('prepareTargets', () => {
expr: 'up', expr: 'up',
headers: { headers: {
'X-Dashboard-Id': undefined, 'X-Dashboard-Id': undefined,
'X-Dashboard-UID': undefined,
'X-Panel-Id': panelId, 'X-Panel-Id': panelId,
}, },
hinting: undefined, hinting: undefined,
@@ -2135,6 +2141,7 @@ describe('prepareTargets', () => {
expr: 'up', expr: 'up',
headers: { headers: {
'X-Dashboard-Id': undefined, 'X-Dashboard-Id': undefined,
'X-Dashboard-UID': undefined,
'X-Panel-Id': panelId, 'X-Panel-Id': panelId,
}, },
hinting: undefined, hinting: undefined,

View File

@@ -146,6 +146,7 @@ export class PrometheusDatasource
const proxyMode = !this.url.match(/^http/); const proxyMode = !this.url.match(/^http/);
if (proxyMode) { if (proxyMode) {
httpOptions.headers['X-Dashboard-Id'] = options.dashboardId; httpOptions.headers['X-Dashboard-Id'] = options.dashboardId;
httpOptions.headers['X-Dashboard-UID'] = options.dashboardUID;
httpOptions.headers['X-Panel-Id'] = options.panelId; httpOptions.headers['X-Panel-Id'] = options.panelId;
} }
} }