GreptimeTeam / GreptimeTeam/promql-parser

BinModifier default value or null

Open
#95 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
104
Forks
29
Avg merge
15h 27m
Merged PRs (30d)
1

Description

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:

```json
{
"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`

```json
{
"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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.