diff --git a/public/app/plugins/datasource/tempo/datasource.test.ts b/public/app/plugins/datasource/tempo/datasource.test.ts index 0ed1d22114e..de5416de26e 100644 --- a/public/app/plugins/datasource/tempo/datasource.test.ts +++ b/public/app/plugins/datasource/tempo/datasource.test.ts @@ -1159,6 +1159,59 @@ describe('label values', () => { }); }); +describe('should provide functionality for ad-hoc filters', () => { + let datasource: TempoDatasource; + + beforeEach(() => { + datasource = createTempoDatasource(); + jest.spyOn(datasource, 'metadataRequest').mockImplementation( + createMetadataRequest({ + data: { + scopes: [{ name: 'span', tags: ['label1', 'label2'] }], + tagValues: [ + { + type: 'value1', + value: 'value1', + label: 'value1', + }, + { + type: 'value2', + value: 'value2', + label: 'value2', + }, + ], + }, + }) + ); + }); + + it('for getTagKeys', async () => { + const response = await datasource.getTagKeys(); + expect(response).toEqual([{ text: 'span.label1' }, { text: 'span.label2' }]); + }); + + it('for getTagValues', async () => { + const now = dateTime('2021-04-20T15:55:00Z'); + const options = { + key: 'span.label1', + filters: [], + timeRange: { + from: now, + to: now, + raw: { + from: 'now-15m', + to: 'now', + }, + }, + }; + const response = await datasource.getTagValues(options); + expect(response).toEqual([ + { text: { type: 'value1', value: 'value1', label: 'value1' } }, + { text: { type: 'value2', value: 'value2', label: 'value2' } }, + ]); + }); +}); + const prometheusMock = (): DataSourceApi => { return { query: jest.fn(() => diff --git a/public/app/plugins/datasource/tempo/datasource.ts b/public/app/plugins/datasource/tempo/datasource.ts index 13d82d9abfc..d2ada1f496b 100644 --- a/public/app/plugins/datasource/tempo/datasource.ts +++ b/public/app/plugins/datasource/tempo/datasource.ts @@ -11,6 +11,7 @@ import { DataQueryResponse, DataQueryResponseData, DataSourceApi, + DataSourceGetTagValuesOptions, DataSourceInstanceSettings, dateTime, FieldType, @@ -211,6 +212,23 @@ export class TempoDatasource extends DataSourceWithBackend> { + await this.languageProvider.fetchTags(); + const tags = this.languageProvider.tagsV2 || []; + return tags + .map(({ name, tags }) => + tags.filter((tag) => tag !== undefined).map((t) => (name !== 'intrinsic' ? `${name}.${t}` : `${t}`)) + ) + .flat() + .map((tag) => ({ text: tag })); + } + + // Allows to retrieve the list of tag values for ad-hoc filters + getTagValues(options: DataSourceGetTagValuesOptions): Promise> { + return this.labelValuesQuery(options.key.replace(/^(resource|span)\./, '')); + } + init = async () => { const response = await lastValueFrom( this._request('/api/status/buildinfo').pipe(