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>
This commit is contained in:
Julius Volz 2024-11-05 16:12:05 +01:00
parent 02aa6d1de6
commit c1f8036228
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) => {