Skip to content

Document that matchers are ANDed together #2758

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

Merged
merged 2 commits into from
Dec 17, 2021
Merged

Document that matchers are ANDed together #2758

merged 2 commits into from
Dec 17, 2021

Conversation

mac-chaffee
Copy link
Contributor

@mac-chaffee mac-chaffee commented Nov 7, 2021

When trying to create more complex matchers, I wasn't sure whether the alert's labels had to match all matchers (AND) or just one (OR) in order to be sent. Looks like the source code indicates matchers are always ANDed together anywhere the Matchers type is used:

func (ms Matchers) Matches(lset model.LabelSet) bool {
for _, m := range ms {
if !m.Matches(string(lset[model.LabelName(m.Name)])) {
return false
}
}
return true

Also I see my editor trimmed trailing whitespace. I figure that's desirable, but I can undo it if need-be.

It does feel like "ANDed" is a weird word, but I guess it's somewhat common: https://english.stackexchange.com/a/79744

If there's a less obscure way to describe logical AND, I'm open to changing it.

Signed-off-by: Mac Chaffee <me@macchaffee.com>
@roidelapluie
Copy link
Member

I also feel like ANDed is a strange word. The current wording "A list of matchers that an alert has to fulfill to match the node." says that you must match the matchers in the list already, I am unsure this reword is needed.

@mac-chaffee
Copy link
Contributor Author

When I read it, my thinking is that "fulfill" doesn't necessarily imply "AND" or "OR".

One could say that an expression like x AND y is fulfilled by x=1,y=1, just like x OR y is fulfilled by x=0,y=1. The "list of matchers" would be the variables x and y.

Maybe an alternate phrasing could be "A list of matchers that must all evaluate to true for an alert to match the node"?

@roidelapluie
Copy link
Member

A list of all matchers that an alert has to fulfill to match the node. maybe?

@mac-chaffee
Copy link
Contributor Author

mac-chaffee commented Nov 9, 2021

I guess I'm not too concerned about that specific sentence changing, as long as there is a re-stating of it somewhere that's more explicit.

Guess we could remove the "(ANDed together)" from the other sections, but leave the extra sentence and example in the "matchers" section, since they're linked together anyway?

@roidelapluie
Copy link
Member

Yes that sounds better.

Signed-off-by: Mac Chaffee <me@macchaffee.com>
@mac-chaffee
Copy link
Contributor Author

Following up on this PR :)

Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@simonpasquier simonpasquier merged commit ec83f71 into prometheus:main Dec 17, 2021
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