Commit a499586f by David Committed by GitHub

Elasticsearch: Support rendering in logs panel (#20229)

* Elasticsearch: Support rendering in logs panel

- add "Logs" metric query type so panels can inform the datasource that
the query is a logs query
- datasource modifies target when metric query type `logs` is detected
- then existing log result processeing paths are followed

* Fix failing test, number of agg types changed
parent 4d7d1317
......@@ -332,9 +332,11 @@ export class ElasticDatasource extends DataSourceApi<ElasticsearchQuery, Elastic
}
let queryObj;
if (target.isLogsQuery) {
if (target.isLogsQuery || queryDef.hasMetricOfType(target, 'logs')) {
target.bucketAggs = [queryDef.defaultBucketAgg()];
target.metrics = [queryDef.defaultMetricAgg()];
// Setting this for metrics queries that are typed as logs
target.isLogsQuery = true;
queryObj = this.queryBuilder.getLogsQuery(target, queryString);
} else {
if (target.alias) {
......
......@@ -73,6 +73,7 @@ export const metricAggTypes = [
minVersion: 2,
},
{ text: 'Raw Document', value: 'raw_document', requiresField: false },
{ text: 'Logs', value: 'logs', requiresField: false },
];
export const bucketAggTypes = [
......@@ -260,3 +261,7 @@ export function defaultBucketAgg() {
export const findMetricById = (metrics: any[], id: any) => {
return _.find(metrics, { id: id });
};
export function hasMetricOfType(target: any, type: string): boolean {
return target && target.metrics && target.metrics.some((m: any) => m.type === type);
}
......@@ -86,25 +86,25 @@ describe('ElasticQueryDef', () => {
describe('pipeline aggs depending on esverison', () => {
describe('using esversion undefined', () => {
test('should not get pipeline aggs', () => {
expect(queryDef.getMetricAggTypes(undefined).length).toBe(9);
expect(queryDef.getMetricAggTypes(undefined).length).toBe(10);
});
});
describe('using esversion 1', () => {
test('should not get pipeline aggs', () => {
expect(queryDef.getMetricAggTypes(1).length).toBe(9);
expect(queryDef.getMetricAggTypes(1).length).toBe(10);
});
});
describe('using esversion 2', () => {
test('should get pipeline aggs', () => {
expect(queryDef.getMetricAggTypes(2).length).toBe(12);
expect(queryDef.getMetricAggTypes(2).length).toBe(13);
});
});
describe('using esversion 5', () => {
test('should get pipeline aggs', () => {
expect(queryDef.getMetricAggTypes(5).length).toBe(12);
expect(queryDef.getMetricAggTypes(5).length).toBe(13);
});
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment