diff --git a/public/app/plugins/datasource/elasticsearch/datasource.test.ts b/public/app/plugins/datasource/elasticsearch/datasource.test.ts index c653ac8a132..6b8d2606184 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.test.ts +++ b/public/app/plugins/datasource/elasticsearch/datasource.test.ts @@ -353,6 +353,20 @@ describe('ElasticDatasource', () => { ).toEqual(undefined); }); + it('does not return logs volume query for hidden query', () => { + expect( + ds.getSupplementaryQuery( + { type: SupplementaryQueryType.LogsVolume }, + { + refId: 'A', + metrics: [{ type: 'logs', id: '1' }], + query: 'foo="bar"', + hide: true, + } + ) + ).toEqual(undefined); + }); + it('returns logs volume query for log query', () => { expect( ds.getSupplementaryQuery( @@ -417,6 +431,20 @@ describe('ElasticDatasource', () => { metrics: [{ type: 'logs', id: '1', settings: { limit: '100' } }], }); }); + + it('does not return logs samples for hidden time series queries', () => { + expect( + ds.getSupplementaryQuery( + { type: SupplementaryQueryType.LogsSample, limit: 100 }, + { + refId: 'A', + query: '', + bucketAggs: [{ type: 'date_histogram', id: '1' }], + hide: true, + } + ) + ).toEqual(undefined); + }); }); describe('getDataProvider', () => { @@ -434,6 +462,21 @@ describe('ElasticDatasource', () => { expect(ds.getSupplementaryRequest(SupplementaryQueryType.LogsSample, options)).not.toBeDefined(); }); + it('does not create a logs volume provider for hidden queries', () => { + const options: DataQueryRequest = { + ...dataQueryDefaults, + targets: [ + { + refId: 'A', + metrics: [{ type: 'logs', id: '1', settings: { limit: '100' } }], + hide: true, + }, + ], + }; + + expect(ds.getSupplementaryRequest(SupplementaryQueryType.LogsVolume, options)).not.toBeDefined(); + }); + it('does create a logs sample provider for time series query', () => { const options: DataQueryRequest = { ...dataQueryDefaults, diff --git a/public/app/plugins/datasource/elasticsearch/datasource.ts b/public/app/plugins/datasource/elasticsearch/datasource.ts index 3cc574ab770..60623c04cd1 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.ts +++ b/public/app/plugins/datasource/elasticsearch/datasource.ts @@ -595,6 +595,10 @@ export class ElasticDatasource getSupplementaryQuery(options: SupplementaryQueryOptions, query: ElasticsearchQuery): ElasticsearchQuery | undefined { let isQuerySuitable = false; + if (query.hide) { + return undefined; + } + switch (options.type) { case SupplementaryQueryType.LogsVolume: // it has to be a logs-producing range-query diff --git a/public/app/plugins/datasource/loki/datasource.test.ts b/public/app/plugins/datasource/loki/datasource.test.ts index c650ba4e4e9..491981c1a79 100644 --- a/public/app/plugins/datasource/loki/datasource.test.ts +++ b/public/app/plugins/datasource/loki/datasource.test.ts @@ -1414,6 +1414,15 @@ describe('LokiDatasource', () => { expect(ds.getSupplementaryRequest(SupplementaryQueryType.LogsVolume, options)).toBeDefined(); }); + it('does not create provider for hidden logs query', () => { + const options: DataQueryRequest = { + ...baseRequestOptions, + targets: [{ expr: '{label="value"}', refId: 'A', queryType: LokiQueryType.Range, hide: true }], + }; + + expect(ds.getSupplementaryRequest(SupplementaryQueryType.LogsVolume, options)).not.toBeDefined(); + }); + it('does not create provider for metrics query', () => { const options: DataQueryRequest = { ...baseRequestOptions, @@ -1526,7 +1535,21 @@ describe('LokiDatasource', () => { }); }); - it('does return logs volume query for instant log query', () => { + it('does not return logs volume query for hidden log query', () => { + expect( + ds.getSupplementaryQuery( + { type: SupplementaryQueryType.LogsVolume }, + { + expr: '{label="value"}', + queryType: LokiQueryType.Range, + refId: 'A', + hide: true, + } + ) + ).toEqual(undefined); + }); + + it('returns logs volume query for instant log query', () => { // we changed logic to automatically run logs queries as range queries, thus there's a volume query now expect( ds.getSupplementaryQuery( @@ -1605,6 +1628,20 @@ describe('LokiDatasource', () => { }); }); + it('does not return logs sample query for hidden query', () => { + expect( + ds.getSupplementaryQuery( + { type: SupplementaryQueryType.LogsSample }, + { + expr: 'rate({label="value"}[5m]', + queryType: LokiQueryType.Range, + refId: 'A', + hide: true, + } + ) + ).toEqual(undefined); + }); + it('returns logs sample query for instant metric query', () => { expect( ds.getSupplementaryQuery( diff --git a/public/app/plugins/datasource/loki/datasource.ts b/public/app/plugins/datasource/loki/datasource.ts index ca87c5de46f..985784f4421 100644 --- a/public/app/plugins/datasource/loki/datasource.ts +++ b/public/app/plugins/datasource/loki/datasource.ts @@ -206,6 +206,10 @@ export class LokiDatasource * @returns A supplemented Loki query or undefined if unsupported. */ getSupplementaryQuery(options: SupplementaryQueryOptions, query: LokiQuery): LokiQuery | undefined { + if (query.hide) { + return undefined; + } + const normalizedQuery = getNormalizedLokiQuery(query); let expr = removeCommentsFromQuery(normalizedQuery.expr); let isQuerySuitable = false;