Prometheus Precedence Operators

In Prometheus there are no specific precedence operators like those found in programming languages. However, Prometheus Query Language (PromQL) does have a specific order of evaluation for its functions and operators. The order of evaluation is as follows:

1. Parentheses: Expressions inside parentheses are evaluated first.

2. Unary Operators: Unary operators like "-" (negation) and "+" (identity) are evaluated next.

3. Multiplication and Division: The "*" (multiplication) and "/" (division) operators are evaluated from left to right.

4. Addition and Subtraction: The "+" (addition) and "-" (subtraction) operators are evaluated from left to right.

5. Comparison Operators: Comparison operators like "==" (equal), "!=" (not equal), "<" (less than), ">" (greater than), "<=" (less than or equal to), and ">=" (greater than or equal to) are evaluated next.

6. Logical Operators: Logical operators like "and", "or", and "unless" are evaluated from left to right.

It's important to note that Prometheus evaluates expressions strictly from left to right, without any operator precedence rules to override the default order.

Examples

Here's an example of a PromQL expression to illustrate the order of evaluation:

sum(rate(http_requests_total{job="myapp"}[5m])) / 60 * 100

In this example, the expression is evaluated by summing the results of the subquery:

rate(http_requests_total{job="myapp"}[5m])
Then the result is divided by 60 and finally multiplied by 100.

Remember that Prometheus evaluates expressions in a linear manner, so if you need to enforce specific operator precedence, you can use parentheses to group subexpressions and control the order of evaluation.