mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Tempo: Escape backslash in span name for promsql query (#83024)
* Tempo: Escape backslash in span name for promsql query In promsql, backslashes in regexes must be doubly escaped for them to be interpreted as a literal backslash character. Fixes #79791 * Fix regex replace --------- Co-authored-by: Andrej Ocenas <mr.ocenas@gmail.com>
This commit is contained in:
@@ -724,12 +724,14 @@ describe('Tempo service graph view', () => {
|
|||||||
'/actuator/health/**',
|
'/actuator/health/**',
|
||||||
'$type + [test]|HTTP POST - post',
|
'$type + [test]|HTTP POST - post',
|
||||||
'server.cluster.local:9090^/sample.test(.*)?',
|
'server.cluster.local:9090^/sample.test(.*)?',
|
||||||
|
'test\\path',
|
||||||
];
|
];
|
||||||
let escaped = getEscapedSpanNames(spanNames);
|
let escaped = getEscapedSpanNames(spanNames);
|
||||||
expect(escaped).toEqual([
|
expect(escaped).toEqual([
|
||||||
'/actuator/health/\\\\*\\\\*',
|
'/actuator/health/\\\\*\\\\*',
|
||||||
'\\\\$type \\\\+ \\\\[test\\\\]\\\\|HTTP POST - post',
|
'\\\\$type \\\\+ \\\\[test\\\\]\\\\|HTTP POST - post',
|
||||||
'server\\\\.cluster\\\\.local:9090\\\\^/sample\\\\.test\\\\(\\\\.\\\\*\\\\)\\\\?',
|
'server\\\\.cluster\\\\.local:9090\\\\^/sample\\\\.test\\\\(\\\\.\\\\*\\\\)\\\\?',
|
||||||
|
'test\\\\\\\\path',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -955,8 +955,10 @@ function makePromLink(title: string, expr: string, datasourceUid: string, instan
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: this is basically the same as prometheus/datasource.ts#prometheusSpecialRegexEscape which is used to escape
|
||||||
|
// template variable values. It would be best to move it to some common place.
|
||||||
export function getEscapedSpanNames(values: string[]) {
|
export function getEscapedSpanNames(values: string[]) {
|
||||||
return values.map((value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\\\$&'));
|
return values.map((value: string) => value.replace(/\\/g, '\\\\\\\\').replace(/[$^*{}\[\]\'+?.()|]/g, '\\\\$&'));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFieldConfig(
|
export function getFieldConfig(
|
||||||
|
|||||||
Reference in New Issue
Block a user