Skip to content

Commit

Permalink
[v9.3.x] Traces: Fix for multiple $__tags in trace to metrics (grafan…
Browse files Browse the repository at this point in the history
…a#60294)

Traces: Fix for multiple $__tags in trace to metrics (grafana#59641)

* Fix interpolation of multiple  in query

* Add another  to test case

(cherry picked from commit bf88147)

Co-authored-by: Joey Tawadrous <90795735+joey-grafana@users.noreply.github.com>
  • Loading branch information
2 people authored and GuaYounesPW committed Feb 8, 2023
1 parent cdf4781 commit bb72aab
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions public/app/features/explore/TraceView/createSpanLink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ describe('createSpanLinkFactory', () => {
splitOpenFn,
traceToMetricsOptions: {
datasourceUid: 'prom1Uid',
queries: [{ name: 'Named Query', query: 'metric{$__tags}[5m]' }],
queries: [{ name: 'Named Query', query: 'metric{$__tags, $__tags}[5m]' }],
tags: [
{ key: 'job', value: '' },
{ key: 'k8s.pod', value: 'pod' },
Expand All @@ -535,7 +535,7 @@ describe('createSpanLinkFactory', () => {
expect(links).toBeDefined();
expect(links!.metricLinks![0]!.href).toBe(
`/explore?left=${encodeURIComponent(
'{"range":{"from":"2020-10-14T01:00:00.000Z","to":"2020-10-14T01:00:01.000Z"},"datasource":"prom1Uid","queries":[{"expr":"metric{job=\\"tns/app\\", pod=\\"sample-pod\\"}[5m]","refId":"A"}],"panelsState":{}}'
'{"range":{"from":"2020-10-14T01:00:00.000Z","to":"2020-10-14T01:00:01.000Z"},"datasource":"prom1Uid","queries":[{"expr":"metric{job=\\"tns/app\\", pod=\\"sample-pod\\", job=\\"tns/app\\", pod=\\"sample-pod\\"}[5m]","refId":"A"}],"panelsState":{}}'
)}`
);
});
Expand Down
2 changes: 1 addition & 1 deletion public/app/features/explore/TraceView/createSpanLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ function buildMetricsQuery(query: TraceToMetricQuery, tags: Array<KeyValue<strin
}, [] as string[]);

const labelsQuery = labels?.join(', ');
expr = expr.replace('$__tags', labelsQuery);
expr = expr.replace(/\$__tags/g, labelsQuery);
}

return expr;
Expand Down

0 comments on commit bb72aab

Please sign in to comment.