8000 Support matchers in rules API by jotak · Pull Request #1843 · prometheus/client_golang · GitHub
[go: up one dir, main page]

Skip to content

Conversation

jotak
Copy link
Contributor
@jotak jotak commented Jul 28, 2025

Similar to the older change on Labels API (#828), this adds matches to the Rules API.

This is a breaking change. If sending breaking changes is an issue, we could create another function signature - but that would be less consistent with the existing code base.

breaking change migration:
Compilation will fail for client callers who use api.Rules(ctx).
Simply change it to api.Rules(ctx, nil) to keep the same behaviour.

Similar to the older change on Labels API (prometheus#828),
this adds `matches` to the `Rules` API.

This is a breaking change

Signed-off-by: Joel Takvorian <jtakvori@redhat.com>
Snapshot(ctx context.Context, skipHead bool) (SnapshotResult, error)
// Rules returns a list of alerting and recording rules that are currently loaded.
Rules(ctx context.Context) (RulesResult, error)
Rules(ctx context.Context, matches []string) (RulesResult, error)
Copy link
Member

Choose a reason for hiding this comment

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

Not a blocker, how about making matches a variadic argument? It would make it neater

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do it if desired, but I also see some cons:

  • it's less consistent with other API functions that also use matches []string, such as LabelNames
  • if the signature has to change again later to add more arguments, depending on what those new arguments are, variadic may have to be reconsidered (e.g. if another []string-like argument is added)

I don't really have an opinion here, let me know what's best

Copy link
Contributor Author
@jotak jotak Jul 29, 2025

Choose a reason for hiding this comment

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

Also, I only proposed to add matches because it's the use-case I'm interested in, but there are a bunch of other arguments that could be relevant, according to the doc. I guess I'm trying to avoid a bigger refactoring, if that makes sense. But a more future-proof change would be to accept a parameters struct.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, never mind. I was lazy, and I hadn't checked the other parameters.
Even though we consider the API package as experimental, let's stick to the existing conventions.

We can add Options if needed.

When it comes to making it future-proof, maybe we can have the type as a first-order parameter as well and make the rest optional.

Any thoughts? cc @bwplotka

Copy link
Member

Choose a reason for hiding this comment

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

I would vote for sticking to consistency and breaking ppl here, as we historically did on this experimental package. We should likely deprecate and move to exp or api module to make it clearer that it's experimental... (or make OpenAPI/swagger flow possible finally)

I would say LGTM for now

Copy link
Member
@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Thanks!

@bwplotka bwplotka merged commit 4ae032f into prometheus:main Aug 21, 2025
8 checks passed
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 this pull request may close these issues.

3 participants

0