Skip to content

Pushdown Prometheus Predicates #8742 #25957

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jirislav
Copy link

@jirislav jirislav commented Jun 9, 2025

Description

Implements pushdown for Prometheus predicates, as requested in #8742.

Additional context and related issues

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
(x) Release notes are required, with the following suggested text:

## Prometheus Connector
* Support predicate pushdown for equality, non-equality, LIKE & IN operators. (#8742)

Copy link

cla-bot bot commented Jun 9, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

Copy link

cla-bot bot commented Jun 9, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@jirislav jirislav force-pushed the pushdown-promql-label-filter branch from 62d8bd7 to dc6eaf4 Compare June 9, 2025 10:12
Copy link

cla-bot bot commented Jun 9, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@jirislav jirislav force-pushed the pushdown-promql-label-filter branch from dc6eaf4 to b2a6f1f Compare June 9, 2025 13:24
Copy link

cla-bot bot commented Jun 9, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@jirislav
Copy link
Author

jirislav commented Jun 9, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

I have the CLA signed and sent like 6 hours ago, not sure how long it usually takes to propagate to the related failing CI job.

@jirislav jirislav force-pushed the pushdown-promql-label-filter branch from b2a6f1f to 6028e80 Compare June 23, 2025 18:58
@cla-bot cla-bot bot added the cla-signed label Jun 23, 2025
@jirislav
Copy link
Author

@ebyhr could you please review & merge? I see you made recent changes to Prometheus Connector as well.

@ebyhr ebyhr removed their assignment Jun 24, 2025
Copy link
Member

@ebyhr ebyhr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just skimmed.

assertThat(request.extractPromQL()).isEqualTo("up{job=\"prometheus\"}[1d]");
});

assertThat(results).hasSizeBetween(1, 2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the result size non-deterministic? Please leave a code comment.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prometheus reports the up metric every 15 seconds, so we expect at least one row, but at most two rows if we filter for the last 15 seconds (edge case). Thanks for asking, I have added a code comment.

private static final int PROMETHEUS_PORT = 9090;
private static final String DEFAULT_VERSION = "v2.15.1";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this changes required?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your question is ambiguous, what change exactly?

If you mean the change of scope from private to public, then yes, we're using this constant in the TestPrometheusIntegration class.

If you mean the change of name from DEFAULT_VERSION to DEFAULT_PROMETHEUS_VERSION, then it's required to avoid ambiguity of what container exactly belongs this version to (prometheus vs. nginx).

@jirislav jirislav force-pushed the pushdown-promql-label-filter branch 4 times, most recently from a666bd4 to 6c3d0bc Compare June 27, 2025 11:04
PrometheusTableHandle tableHandle = ((PrometheusTableHandle) handle)
.withPredicate(constraint.getSummary());
.withPredicate(constraint.getSummary())
.withExpressions(rewriter.rewrite(session, expression, constraint.getAssignments()).orElseGet(ImmutableList::of));
return Optional.of(new ConstraintApplicationResult<>(tableHandle, constraint.getSummary(), constraint.getExpression(), false));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After updating tableHandle , it looks like remainingFilter and remainingExpression still reference the previous state. Is that intentional?

Copy link
Author

@jirislav jirislav Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is intentional because we can't push-down arbitrary operation for the labels map (see the testLabelLikeAndEqAndNeqNegatedPushDown test to see why - though it's just a single edge-case example).

Yes, Trino will potentially filter something that was already pushed down, but the real value of this PR is that Prometheus doesn't have to return all the timeseries anymore and Trino doesn't have to filter them all. From now, Prometheus will always perform very efficient timeseries filtering based on provided label selectors and Trino will go just through a fraction of data compared to previous version.

In the future, someone might add support for the OR operator, or NOT(x AND y) by spitting the query into multiple Prometheus requests, potentially covering all the logical edge-cases for label filter pushdown. At that point, I think we could safely remove all the filters on label values in the above discussed lines, but I'd argue it's out-of-scope for this PR, as this itself is a major improvement already.

@jirislav jirislav force-pushed the pushdown-promql-label-filter branch from 6c3d0bc to 3b8a38d Compare June 27, 2025 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

4 participants