promql-parser
promql-parser copied to clipboard
BinModifier default value or null
This might not be an issue at all, but to record different behaviour between our parser and prometheus default.
For this query statement, the output of prometheus 3.0 parse_query of process_virtual_memory_bytes / process_cpu_seconds_total is like:
{
"data": {
"bool": false,
"lhs": {
"matchers": [
{
"name": "__name__",
"type": "=",
"value": "process_virtual_memory_bytes"
}
],
"name": "process_virtual_memory_bytes",
"offset": 0,
"startOrEnd": null,
"timestamp": null,
"type": "vectorSelector"
},
"matching": {
"card": "one-to-one",
"include": [],
"labels": [],
"on": false
},
"op": "/",
"rhs": {
"matchers": [
{
"name": "__name__",
"type": "=",
"value": "process_cpu_seconds_total"
}
],
"name": "process_cpu_seconds_total",
"offset": 0,
"startOrEnd": null,
"timestamp": null,
"type": "vectorSelector"
},
"type": "binaryExpr"
}
}
The matching part
"matching": {
"card": "one-to-one",
"include": [],
"labels": [],
"on": false
},
In our implementation, BinModifier is set to None in this case.
There is a case when matching is set to Null in prometheus: 1 / process_cpu_seconds_total
{
"data": {
"bool": false,
"lhs": {
"type": "numberLiteral",
"val": "1"
},
"matching": null,
"op": "/",
"rhs": {
"matchers": [
{
"name": "__name__",
"type": "=",
"value": "process_cpu_seconds_total"
}
],
"name": "process_cpu_seconds_total",
"offset": 0,
"startOrEnd": null,
"timestamp": null,
"type": "vectorSelector"
},
"type": "binaryExpr"
}
}
Conclusion
For binary expression, prometheus only set matching to null when one of the argument is literal, when both are vectorSelector, prometheus generates default matching: {"card": "one-to-one"}.
In our implementation, BinModifier is always set to null if no modifier provided.