mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
Tempo: Escape regex-sensitive characters in span name before building promql query (#66301)
* Tempo: escape regex-sensitive characters in span name before building promql query * Make gen-cue * Add type * Add tests * Test * Minor update --------- Co-authored-by: Joey Tawadrous <joey.tawadrous@grafana.com>
This commit is contained in:
parent
37de4a825b
commit
8b1afb594d
@ -30,6 +30,7 @@ import {
|
||||
makeServiceGraphViewRequest,
|
||||
makeTempoLink,
|
||||
getFieldConfig,
|
||||
getEscapedSpanNames,
|
||||
} from './datasource';
|
||||
import mockJson from './mockJsonResponse.json';
|
||||
import mockServiceGraph from './mockServiceGraph.json';
|
||||
@ -589,6 +590,20 @@ describe('Tempo service graph view', () => {
|
||||
expect(builtQuery).toBe('sum(rate(traces_spanmetrics_calls_total{}[$__rate_interval]))');
|
||||
});
|
||||
|
||||
it('should escape span names correctly', () => {
|
||||
const spanNames = [
|
||||
'/actuator/health/**',
|
||||
'$type + [test]|HTTP POST - post',
|
||||
'server.cluster.local:9090^/sample.test(.*)?',
|
||||
];
|
||||
let escaped = getEscapedSpanNames(spanNames);
|
||||
expect(escaped).toEqual([
|
||||
'/actuator/health/\\\\*\\\\*',
|
||||
'\\\\$type \\\\+ \\\\[test\\\\]\\\\|HTTP POST - post',
|
||||
'server\\\\.cluster\\\\.local:9090\\\\^/sample\\\\.test\\\\(\\\\.\\\\*\\\\)\\\\?',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should get field config correctly', () => {
|
||||
let datasourceUid = 's4Jvz8Qnk';
|
||||
let tempoDatasourceUid = 'EbPO1fYnz';
|
||||
|
@ -597,7 +597,7 @@ function errorAndDurationQuery(
|
||||
let serviceGraphViewMetrics = [];
|
||||
let errorRateBySpanName = '';
|
||||
let durationsBySpanName: string[] = [];
|
||||
const spanNames = rateResponse.data[0][0]?.fields[1]?.values ?? [];
|
||||
const spanNames = getEscapedSpanNames(rateResponse.data[0][0]?.fields[1]?.values ?? []);
|
||||
|
||||
if (spanNames.length > 0) {
|
||||
errorRateBySpanName = buildExpr(errorRateMetric, 'span_name=~"' + spanNames.join('|') + '"', request);
|
||||
@ -663,6 +663,10 @@ function makePromLink(title: string, expr: string, datasourceUid: string, instan
|
||||
};
|
||||
}
|
||||
|
||||
export function getEscapedSpanNames(values: string[]) {
|
||||
return values.map((value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\\\$&'));
|
||||
}
|
||||
|
||||
export function getFieldConfig(
|
||||
datasourceUid: string,
|
||||
tempoDatasourceUid: string,
|
||||
|
Loading…
Reference in New Issue
Block a user