DataSourceWithBackend: Add queryGroupId to find correlated/related queries (#64587)

* add `correlationId` to queries

* trace correlation id in backend

* add correlation id to loki's span

* add correlation id to query chunks

* fix test

* fix DataSourceWithBackend test

* change to `queryGroupId`

* remove empty line

* fix test in `DataSourceWithBackend`
This commit is contained in:
Sven Grossmann
2023-03-17 15:48:13 +01:00
committed by GitHub
parent 6f83a45e1b
commit 7261c6f7cd
8 changed files with 24 additions and 3 deletions
@@ -522,6 +522,9 @@ export interface DataQueryRequest<TQuery extends DataQuery = DataQuery> {
// Make it possible to hide support queries from the inspector
hideFromInspector?: boolean;
// Used to correlate multiple related requests
queryGroupId?: string;
}
export interface DataQueryTimings {
@@ -49,6 +49,7 @@ describe('DataSourceWithBackend', () => {
targets: [{ refId: 'A' }, { refId: 'B', datasource: { type: 'sample' } }],
dashboardUID: 'dashA',
panelId: 123,
queryGroupId: 'abc',
} as DataQueryRequest);
const args = mock.calls[0][0];
@@ -87,6 +88,7 @@ describe('DataSourceWithBackend', () => {
"X-Datasource-Uid": "abc, <mockuid>",
"X-Panel-Id": "123",
"X-Plugin-Id": "dummy, sample",
"X-Query-Group-Id": "abc",
},
"hideFromInspector": false,
"method": "POST",
@@ -77,6 +77,7 @@ enum PluginRequestHeaders {
DatasourceUID = 'X-Datasource-Uid', // can be used for routing/ load balancing
DashboardUID = 'X-Dashboard-Uid', // mainly useful for debuging slow queries
PanelID = 'X-Panel-Id', // mainly useful for debuging slow queries
QueryGroupID = 'X-Query-Group-Id', // mainly useful to find related queries with query chunking
}
/**
@@ -210,6 +211,9 @@ class DataSourceWithBackend<
if (request.panelId) {
headers[PluginRequestHeaders.PanelID] = `${request.panelId}`;
}
if (request.queryGroupId) {
headers[PluginRequestHeaders.QueryGroupID] = `${request.queryGroupId}`;
}
return getBackendSrv()
.fetch<BackendDataSourceResponse>({
url,