Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BinModifier default value or null #95

Open
sunng87 opened this issue Oct 17, 2024 · 0 comments
Open

BinModifier default value or null #95

sunng87 opened this issue Oct 17, 2024 · 0 comments

Comments

@sunng87
Copy link
Member

sunng87 commented Oct 17, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant