Skip to content

PromQL: add support for parameters in PromQL query #139508

@felixbarny

Description

@felixbarny

For example:

PROMQL step=?_step rate(http_requests_total[?_step])

This should work already: step=?_step. Parameters are resolved with ExpressionBuilder#paramByNameOrPosition.

This isn't supported yet: rate(http_requests_total[?_step]). We get an ANTLR ParsingException (no viable alternative at input 'rate(http_requests_total[?') here because the PromQL grammar doesn't support parameters.

The quick and dirty workaround would be to replace parameters in the opaque promqlQuery string before invoking the PromQL parser:

promqlPlan = promqlParser.createStatement(
promqlQuery,
params.startLiteral(),
params.endLiteral(),
promqlStartLine,
promqlStartColumn
);

Another option is to adjust the PromQL grammar itself to add support for parameters. This lets us control in a more fine-grained way where we support double and single params. That's likely a bit more involved and we'll need to re-implement things in PromqlExpressionBuilder but my first instinct is that this is a the cleaner solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions