[v11.2.x] Tempo: Send the existing query with the request for a tags values (#91997)
Tempo: Send the existing query with the request for a tags values (#90931)
* Send query with request
* Ensure number tag values are added to query correctly
* Update test
* Update test
(cherry picked from commit d72846790e)
Co-authored-by: Joey <90795735+joey-grafana@users.noreply.github.com>
This commit is contained in:
co-authored by
Joey
parent
317fe580c1
commit
6d288f1d14
@@ -151,9 +151,9 @@ describe('generateQueryFromAdHocFilters generates the correct query for', () =>
|
||||
expect(
|
||||
generateQueryFromAdHocFilters([
|
||||
{ key: 'footag', operator: '=', value: 'foovalue' },
|
||||
{ key: 'bartag', operator: '=', value: 'barvalue' },
|
||||
{ key: 'bartag', operator: '=', value: '0' },
|
||||
])
|
||||
).toBe('{footag="foovalue" && bartag="barvalue"}');
|
||||
).toBe('{footag="foovalue" && bartag=0}');
|
||||
});
|
||||
|
||||
it('a filter with intrinsic values', () => {
|
||||
|
||||
@@ -81,9 +81,16 @@ const adHocValueHelper = (f: AdHocVariableFilter) => {
|
||||
if (intrinsics.find((t) => t === f.key)) {
|
||||
return f.value;
|
||||
}
|
||||
if (parseInt(f.value, 10).toString() === f.value) {
|
||||
return f.value;
|
||||
}
|
||||
return `"${f.value}"`;
|
||||
};
|
||||
|
||||
export const getTagWithoutScope = (tag: string) => {
|
||||
return tag.replace(/^(event|link|resource|span)\./, '');
|
||||
};
|
||||
|
||||
export const filterScopedTag = (f: TraceqlFilter) => {
|
||||
return scopeHelper(f) + f.tag;
|
||||
};
|
||||
|
||||
@@ -1192,10 +1192,7 @@ describe('should provide functionality for ad-hoc filters', () => {
|
||||
},
|
||||
};
|
||||
const response = await datasource.getTagValues(options);
|
||||
expect(response).toEqual([
|
||||
{ text: { type: 'value1', value: 'value1', label: 'value1' } },
|
||||
{ text: { type: 'value2', value: 'value2', label: 'value2' } },
|
||||
]);
|
||||
expect(response).toEqual([{ text: 'value1' }, { text: 'value2' }]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import { BarGaugeDisplayMode, TableCellDisplayMode, VariableFormatID } from '@gr
|
||||
import {
|
||||
generateQueryFromAdHocFilters,
|
||||
generateQueryFromFilters,
|
||||
getTagWithoutScope,
|
||||
interpolateFilters,
|
||||
} from './SearchTraceQLEditor/utils';
|
||||
import { TempoVariableQuery, TempoVariableQueryType } from './VariableQueryEditor';
|
||||
@@ -180,7 +181,7 @@ export class TempoDatasource extends DataSourceWithBackend<TempoQuery, TempoJson
|
||||
return tags.filter((tag) => tag !== undefined).map((tag) => ({ text: tag }));
|
||||
}
|
||||
|
||||
async labelValuesQuery(labelName?: string, query?: string): Promise<Array<{ text: string }>> {
|
||||
async labelValuesQuery(labelName?: string): Promise<Array<{ text: string }>> {
|
||||
if (!labelName) {
|
||||
return [];
|
||||
}
|
||||
@@ -202,7 +203,7 @@ export class TempoDatasource extends DataSourceWithBackend<TempoQuery, TempoJson
|
||||
// For V2, we need to send scope and tag name, e.g. `span.http.status_code`,
|
||||
// unless the tag has intrinsic scope
|
||||
const scopeAndTag = scope === 'intrinsic' ? labelName : `${scope}.${labelName}`;
|
||||
options = await this.languageProvider.getOptionsV2(scopeAndTag, query);
|
||||
options = await this.languageProvider.getOptionsV2(scopeAndTag);
|
||||
} catch {
|
||||
// For V1, the tag name (e.g. `http.status_code`) is enough
|
||||
options = await this.languageProvider.getOptionsV1(labelName);
|
||||
@@ -228,7 +229,23 @@ export class TempoDatasource extends DataSourceWithBackend<TempoQuery, TempoJson
|
||||
// Allows to retrieve the list of tag values for ad-hoc filters
|
||||
getTagValues(options: DataSourceGetTagValuesOptions<TempoQuery>): Promise<Array<{ text: string }>> {
|
||||
const query = generateQueryFromAdHocFilters(options.filters);
|
||||
return this.labelValuesQuery(options.key.replace(/^(resource|span)\./, ''), query);
|
||||
return this.tagValuesQuery(options.key, query);
|
||||
}
|
||||
|
||||
async tagValuesQuery(tag: string, query: string): Promise<Array<{ text: string }>> {
|
||||
let options;
|
||||
try {
|
||||
// For V2, we need to send scope and tag name, e.g. `span.http.status_code`,
|
||||
// unless the tag has intrinsic scope
|
||||
options = await this.languageProvider.getOptionsV2(tag, query);
|
||||
} catch {
|
||||
// For V1, the tag name (e.g. `http.status_code`) is enough
|
||||
options = await this.languageProvider.getOptionsV1(getTagWithoutScope(tag));
|
||||
}
|
||||
|
||||
return options.flatMap((option: SelectableValue<string>) =>
|
||||
option.value !== undefined ? [{ text: option.value }] : []
|
||||
);
|
||||
}
|
||||
|
||||
init = async () => {
|
||||
|
||||
Reference in New Issue
Block a user