Skip to content

Support matchers in rules API #1843

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 1 commit into
base: main
Choose a base branch
from
Open

Conversation

jotak
Copy link

@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 <[email protected]>
@@ -494,7 +494,7 @@ type API interface {
// under the TSDB's data directory and returns the directory as response.
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
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
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

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.

2 participants