mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Tempo: Add support for ad-hoc filters (#83290)
* Add support for ad-hoc filters * Add tests * Update types
This commit is contained in:
parent
af4382e4c2
commit
1899afccb5
@ -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 => {
|
const prometheusMock = (): DataSourceApi => {
|
||||||
return {
|
return {
|
||||||
query: jest.fn(() =>
|
query: jest.fn(() =>
|
||||||
|
@ -11,6 +11,7 @@ import {
|
|||||||
DataQueryResponse,
|
DataQueryResponse,
|
||||||
DataQueryResponseData,
|
DataQueryResponseData,
|
||||||
DataSourceApi,
|
DataSourceApi,
|
||||||
|
DataSourceGetTagValuesOptions,
|
||||||
DataSourceInstanceSettings,
|
DataSourceInstanceSettings,
|
||||||
dateTime,
|
dateTime,
|
||||||
FieldType,
|
FieldType,
|
||||||
@ -211,6 +212,23 @@ export class TempoDatasource extends DataSourceWithBackend<TempoQuery, TempoJson
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allows to retrieve the list of tags for ad-hoc filters
|
||||||
|
async getTagKeys(): Promise<Array<{ text: string }>> {
|
||||||
|
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<Array<{ text: string }>> {
|
||||||
|
return this.labelValuesQuery(options.key.replace(/^(resource|span)\./, ''));
|
||||||
|
}
|
||||||
|
|
||||||
init = async () => {
|
init = async () => {
|
||||||
const response = await lastValueFrom(
|
const response = await lastValueFrom(
|
||||||
this._request('/api/status/buildinfo').pipe(
|
this._request('/api/status/buildinfo').pipe(
|
||||||
|
Loading…
Reference in New Issue
Block a user