mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CloudWatch Logs: Fix running logs queries with expressions (#65306)
This commit is contained in:
@@ -103,6 +103,61 @@ describe('DataSourceWithBackend', () => {
|
||||
`);
|
||||
});
|
||||
|
||||
test('correctly creates expression queries', () => {
|
||||
const { mock, ds } = createMockDatasource();
|
||||
ds.query({
|
||||
maxDataPoints: 10,
|
||||
intervalMs: 5000,
|
||||
targets: [{ refId: 'A' }, { refId: 'B', datasource: { type: '__expr__' } }],
|
||||
dashboardUID: 'dashA',
|
||||
panelId: 123,
|
||||
queryGroupId: 'abc',
|
||||
} as DataQueryRequest);
|
||||
|
||||
const args = mock.calls[0][0];
|
||||
|
||||
expect(mock.calls.length).toBe(1);
|
||||
expect(args).toMatchInlineSnapshot(`
|
||||
{
|
||||
"data": {
|
||||
"queries": [
|
||||
{
|
||||
"datasource": {
|
||||
"type": "dummy",
|
||||
"uid": "abc",
|
||||
},
|
||||
"datasourceId": 1234,
|
||||
"intervalMs": 5000,
|
||||
"maxDataPoints": 10,
|
||||
"queryCachingTTL": undefined,
|
||||
"refId": "A",
|
||||
},
|
||||
{
|
||||
"datasource": {
|
||||
"name": "Expression",
|
||||
"type": "__expr__",
|
||||
"uid": "__expr__",
|
||||
},
|
||||
"refId": "B",
|
||||
},
|
||||
],
|
||||
},
|
||||
"headers": {
|
||||
"X-Dashboard-Uid": "dashA",
|
||||
"X-Datasource-Uid": "abc",
|
||||
"X-Grafana-From-Expr": "true",
|
||||
"X-Panel-Id": "123",
|
||||
"X-Plugin-Id": "dummy",
|
||||
"X-Query-Group-Id": "abc",
|
||||
},
|
||||
"hideFromInspector": false,
|
||||
"method": "POST",
|
||||
"requestId": undefined,
|
||||
"url": "/api/ds/query?expression=true",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
test('should apply template variables only for the current data source', () => {
|
||||
const { mock, ds } = createMockDatasource();
|
||||
ds.applyTemplateVariables = jest.fn();
|
||||
|
||||
@@ -78,6 +78,7 @@ enum PluginRequestHeaders {
|
||||
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
|
||||
FromExpression = 'X-Grafana-From-Expr', // used by datasources to identify expression queries
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,14 +198,16 @@ class DataSourceWithBackend<
|
||||
});
|
||||
}
|
||||
|
||||
let url = '/api/ds/query';
|
||||
if (hasExpr) {
|
||||
url += '?expression=true';
|
||||
}
|
||||
|
||||
const headers: Record<string, string> = {};
|
||||
headers[PluginRequestHeaders.PluginID] = Array.from(pluginIDs).join(', ');
|
||||
headers[PluginRequestHeaders.DatasourceUID] = Array.from(dsUIDs).join(', ');
|
||||
|
||||
let url = '/api/ds/query';
|
||||
if (hasExpr) {
|
||||
headers[PluginRequestHeaders.FromExpression] = 'true';
|
||||
url += '?expression=true';
|
||||
}
|
||||
|
||||
if (request.dashboardUID) {
|
||||
headers[PluginRequestHeaders.DashboardUID] = request.dashboardUID;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user