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

Push boolean operations into scanners #338

Open
fpetkovski opened this issue Nov 27, 2023 · 5 comments
Open

Push boolean operations into scanners #338

fpetkovski opened this issue Nov 27, 2023 · 5 comments

Comments

@fpetkovski
Copy link
Collaborator

fpetkovski commented Nov 27, 2023

Certain PromQL expression can be considered as (sample) selectors and can be evaluated directly in scanners.

One example is:

sum(kube_pod_info == 1)

For this query, we could apply == 1 directly into the vector_selector (maybe we should rename this to vector_scanner) and avoid emitting samples which do not match that binary operation.

@fpetkovski fpetkovski changed the title Push boolean selectors into scanners Push boolean operations into scanners Nov 27, 2023
@harsh-ps-2003
Copy link

As far as I can understand, the ability to consider certain PromQL expressions as sample selectors and evaluate them directly in scanners is to optimize the query execution process. By applying the binary operation directly in the vector selector (or scanner), unnecessary samples that do not match the binary operation can be avoided, leading to more efficient query evaluation. As a potential optimization, does implementing a custom logical operator injected at the instantiation of the engine to handle the specific PromQL expressions that can be directly evaluated in scanners feels right to you? Should I try to solve this issue (I may need some help though)? @fpetkovski

@fpetkovski
Copy link
Collaborator Author

Hi @harsh-ps-2003, thank you for looking into this. Instead of a new operator, I would suggest adding a filtering function to the vector scanner which would take in a step vector and produce a new step vector with filtered samples.

@harsh-ps-2003
Copy link

following your suggestion @fpetkovski I did the following changes in vector selector :

// Implementation of the filtering function.
func filterBinaryOpEqual(v model.StepVector, value float64) model.StepVector {
	filtered := model.StepVector{}

	// Iterate over the samples in the StepVector.
	for i, sample := range v.Samples {
		if sample == value {
			// Append the matching sample to the filtered StepVector.
			filtered.AppendSample(nil, v.SampleIDs[i], sample)
		}
	}

	return filtered
}

to filter the samples through vector scanner. But I dont know how to test whether my code is working or not! Any directions?

@fpetkovski
Copy link
Collaborator Author

I suggest that you add a new test case in this test and then we can see if your change works.

Feel free to raise a PR with the new test and your change.

@harsh-ps-2003
Copy link

harsh-ps-2003 commented Jan 7, 2024

I tried to solve the issue, but it seems that I am unable to do so. Still I am making a draft PR so that you could see what am I messing up.

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

Successfully merging a pull request may close this issue.

2 participants