Fix selector / series formatting for empty metric names

Fixes https://github.com/prometheus/prometheus/issues/15335

Signed-off-by: Julius Volz <julius.volz@gmail.com>
pull/15341/head
Julius Volz 2024-11-05 16:12:05 +01:00
parent 1b2defa7a2
commit d19e749dc6
2 changed files with 15 additions and 1 deletions

View File

@ -157,6 +157,20 @@ describe("serializeNode and formatNode", () => {
},
output: "metric_name[5m] @ start() offset -10m",
},
{
node: {
type: nodeType.vectorSelector,
name: "", // Test formatting a selector with an empty metric name.
matchers: [
{ type: matchType.equal, name: "label1", value: "value1" },
],
offset: 0,
timestamp: null,
startOrEnd: null,
},
output:
'{label1="value1"}',
},
// Aggregations.
{

View File

@ -271,7 +271,7 @@ const metricNameRe = /^[a-zA-Z_:][a-zA-Z0-9_:]*$/;
const labelNameCharsetRe = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
export const metricContainsExtendedCharset = (str: string) => {
return !metricNameRe.test(str);
return str !== "" && !metricNameRe.test(str);
};
export const labelNameContainsExtendedCharset = (str: string) => {