Tempo: Fix service graph when tempoApmTable is enabled (#60975)

Fix query variables breaking the generated query for the APM service graph
This commit is contained in:
Andre Pereira 2023-01-04 16:18:41 +00:00 committed by GitHub
parent 1381fb6dfc
commit 298576c6a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View File

@ -567,6 +567,16 @@ describe('Tempo apm table', () => {
expect(builtQuery).toBe(
'topk(5, sum(rate(traces_spanmetrics_calls_total{service="app",service="app"}[$__range])) by (span_name))'
);
targets = { targets: [{ queryType: 'serviceMap', serviceMapQuery: '{client="${app}",service="$app"}' }] } as any;
builtQuery = buildExpr(
{ expr: 'topk(5, sum(rate(traces_spanmetrics_calls_total{}[$__range])) by (span_name))', params: [] },
'',
targets
);
expect(builtQuery).toBe(
'topk(5, sum(rate(traces_spanmetrics_calls_total{service="${app}",service="$app"}[$__range])) by (span_name))'
);
});
it('should build link expr correctly', () => {
@ -669,17 +679,17 @@ describe('Tempo apm table', () => {
];
const objToAlign = {
'HTTP GET - root': {
value: 0.1234,
value: '0.1234',
},
'HTTP GET': {
value: 0.6789,
value: '0.6789',
},
'HTTP POST - post': {
value: 0.4321,
value: '0.4321',
},
};
let value = getRateAlignedValues(resp, objToAlign as any);
let value = getRateAlignedValues(resp, objToAlign);
expect(value.toString()).toBe('0,0.6789,0.1234,0,0.4321');
});

View File

@ -820,7 +820,11 @@ export function buildExpr(
extraParams: string,
request: DataQueryRequest<TempoQuery>
) {
let serviceMapQuery = request.targets[0]?.serviceMapQuery?.replace('{', '').replace('}', '') ?? '';
let serviceMapQuery = request.targets[0]?.serviceMapQuery ?? '';
const serviceMapQueryMatch = serviceMapQuery.match(/^{(.*)}$/);
if (serviceMapQueryMatch?.length) {
serviceMapQuery = serviceMapQueryMatch[1];
}
// map serviceGraph metric tags to APM metric tags
serviceMapQuery = serviceMapQuery.replace('client', 'service').replace('server', 'service');
const metricParams = serviceMapQuery.includes('span_name')