Jaeger: Add support for traceID field to accept variables. (#45559)

This commit is contained in:
Marco Dalalba 2022-03-02 11:35:36 -03:00 committed by GitHub
parent f530775e45
commit e738896316
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -159,6 +159,32 @@ describe('JaegerDatasource', () => {
});
});
it('should resolve templates in traceID', async () => {
const mock = setupFetchMock({ data: [testResponse] });
const ds = new JaegerDatasource(defaultSettings, timeSrvStub);
await lastValueFrom(
ds.query({
...defaultQuery,
scopedVars: {
$traceid: {
text: 'traceid',
value: '5311b0dd0ca8df3463df93c99cb805a6',
},
},
targets: [
{
query: '$traceid',
refId: '1',
},
],
})
);
expect(mock).toBeCalledWith({
url: `${defaultSettings.url}/api/traces/5311b0dd0ca8df3463df93c99cb805a6`,
});
});
it('should resolve templates in tags', async () => {
const mock = setupFetchMock({ data: [testResponse] });
const ds = new JaegerDatasource(defaultSettings, timeSrvStub);

View File

@ -52,7 +52,9 @@ export class JaegerDatasource extends DataSourceApi<JaegerQuery, JaegerJsonData>
}
if (target.queryType !== 'search' && target.query) {
return this._request(`/api/traces/${encodeURIComponent(target.query)}`).pipe(
return this._request(
`/api/traces/${encodeURIComponent(getTemplateSrv().replace(target.query, options.scopedVars))}`
).pipe(
map((response) => {
const traceData = response?.data?.data?.[0];
if (!traceData) {