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;
timeInfo?: string; // The query time description (blue text in the upper right)
panelId?: number;
/** @deprecate */
dashboardId?: number;
dashboardUID?: string;
publicDashboardAccessToken?: string;
// Request Timing

View File

@@ -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();

View File

@@ -318,13 +318,14 @@ export class PanelChrome extends PureComponent<Props, State> {
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({

View File

@@ -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();
});

View File

@@ -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,

View File

@@ -46,7 +46,9 @@ export interface QueryRunnerOptions<
datasource: DataSourceRef | DataSourceApi<TQuery, TOptions> | 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,

View File

@@ -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,

View File

@@ -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;
}
}