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 ...@@ -332,9 +332,11 @@ export class ElasticDatasource extends DataSourceApi<ElasticsearchQuery, Elastic
} }
let queryObj; let queryObj;
if (target.isLogsQuery) { if (target.isLogsQuery || queryDef.hasMetricOfType(target, 'logs')) {
target.bucketAggs = [queryDef.defaultBucketAgg()]; target.bucketAggs = [queryDef.defaultBucketAgg()];
target.metrics = [queryDef.defaultMetricAgg()]; target.metrics = [queryDef.defaultMetricAgg()];
// Setting this for metrics queries that are typed as logs
target.isLogsQuery = true;
queryObj = this.queryBuilder.getLogsQuery(target, queryString); queryObj = this.queryBuilder.getLogsQuery(target, queryString);
} else { } else {
if (target.alias) { if (target.alias) {
......
...@@ -73,6 +73,7 @@ export const metricAggTypes = [ ...@@ -73,6 +73,7 @@ export const metricAggTypes = [
minVersion: 2, minVersion: 2,
}, },
{ text: 'Raw Document', value: 'raw_document', requiresField: false }, { text: 'Raw Document', value: 'raw_document', requiresField: false },
{ text: 'Logs', value: 'logs', requiresField: false },
]; ];
export const bucketAggTypes = [ export const bucketAggTypes = [
...@@ -260,3 +261,7 @@ export function defaultBucketAgg() { ...@@ -260,3 +261,7 @@ export function defaultBucketAgg() {
export const findMetricById = (metrics: any[], id: any) => { export const findMetricById = (metrics: any[], id: any) => {
return _.find(metrics, { id: id }); 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', () => { ...@@ -86,25 +86,25 @@ describe('ElasticQueryDef', () => {
describe('pipeline aggs depending on esverison', () => { describe('pipeline aggs depending on esverison', () => {
describe('using esversion undefined', () => { describe('using esversion undefined', () => {
test('should not get pipeline aggs', () => { test('should not get pipeline aggs', () => {
expect(queryDef.getMetricAggTypes(undefined).length).toBe(9); expect(queryDef.getMetricAggTypes(undefined).length).toBe(10);
}); });
}); });
describe('using esversion 1', () => { describe('using esversion 1', () => {
test('should not get pipeline aggs', () => { test('should not get pipeline aggs', () => {
expect(queryDef.getMetricAggTypes(1).length).toBe(9); expect(queryDef.getMetricAggTypes(1).length).toBe(10);
}); });
}); });
describe('using esversion 2', () => { describe('using esversion 2', () => {
test('should get pipeline aggs', () => { test('should get pipeline aggs', () => {
expect(queryDef.getMetricAggTypes(2).length).toBe(12); expect(queryDef.getMetricAggTypes(2).length).toBe(13);
}); });
}); });
describe('using esversion 5', () => { describe('using esversion 5', () => {
test('should get pipeline aggs', () => { 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