-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Filter alerts #633
Filter alerts #633
Conversation
PromQL is usable as a standalone package largely. I did significant refactoring of Prometheus's internal type structure in the https://github.com/prometheus/prometheus/tree/dev-2.0/promql You can give it a look and let me know if and how it helps. In general one has to consider at which point one wants to depend at all as opposed to just copying the relevant bits of code. Label matcher queries are somewhat involved of course. So it can make sense. |
dispatch/dispatch.go
Outdated
var overview AlertOverview | ||
|
||
d.mtx.RLock() | ||
defer d.mtx.RUnlock() | ||
|
||
matchers, err := promql.ParseMetricSelector(filter) | ||
if err != nil { | ||
// TODO: Do we bail on a bad filter? Or just ignore it and continue on? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, return an error in this function.
I'm getting a failure on circle-ci because of the build constraint in |
@stuartnelson3 that shouldn't be the case I think. There's a fallback for the amd64 assembly implementations: https://github.com/dgryski/go-bits/blob/master/clz.go Looks like vendoring tools might only vendor for the arch they are run on. You'll probably have to add it manually. |
This now imports a ton of other stuff storage related. Mh, I thought I eliminated everything. |
Urgh, so it still depends on storage/ which is just a set of interface, so that's largely okay. |
Sounds like integration tests that may better live in |
ab15877
to
7b68724
Compare
Not sure if this is a valid vendoring strategy by you folks, but I went ahead and deleted the |
The circleci build fails because |
@stuartnelson3 thinking a bit more. Parsing a metric descriptor or selector are so useful across a bunch of potential tools, I don't thinking binding us to the I'd propose adding parsing code for both to the dev-2.0 branch for ParseMetric(string) (Labels, error)
ParseLabels(string) (Labels, error)
ParseMatcher(string) (*Matcher, error) That can either be copying logic from How does that sound? |
@fabxc that makes sense -- parsing metrics/selectors is going to be needed in most tools within the prometheus ecosystem, but all of the additional promql stuff is not necessary. Whichever of your three suggestions you prefer sounds good to me. If a regexp is easiest that sounds fine to me since these won't be performance critical, but a smaller parse loop would also be fine by me. Any idea when you'll have a chance to add this to your |
Somewhat busy right now. Also we have to add a Blocker here is that I've already been at that point and realized that we might want it to be an interface that can also implement OR. FWIW, in the meantime I'd just hack into AM whatever you need and we can worry about making it nice and moving it into the right package later. Just stab it with a regex ;) |
Sweet lord finally. This ... got a bit out of hand. There was a lot of crazy vendoring updates that have resulted in a ridiculous diff. The bottom line is that alertmanager will now filter the silences and alert groups as designated by the URL encoded matcher string in the
Corresponds to the label matchers:
|
Can you please make sure to keep the commits for a PR in a reviewable way. This is 20 commits not and I've no clear set of things to look at other than "everything". |
Yeah, I apologize for that. I had a lot of issues going back and forth with vendoring. I'll squash these down into "code" and a "vendoring" commit. |
7810ad0
to
0954959
Compare
sils = append(sils, s) | ||
} | ||
|
||
respond(w, sils) | ||
} | ||
|
||
func matchesFilterLabels(s *types.Silence, matchers []*labels.Matcher) bool { | ||
sms := map[string]string{} | ||
for _, m := range s.Matchers { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole loop is less than ideal.
I'm not sure how Matchers
is used elsewhere in the code or if it is a slice for a reason, but changing the initial parsing of the protobuf silence so that silence.Matchers
is a map[string]*Matcher
would simplify this.
Or, if you don't care about this being in the API, that's fine too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't want to couple our protobuf representation, which is also our internal model to that type.
I'd have to give our whole architecture a proper look and see how it all fits with the modeling changes we discussed as part of the new UI.
@fabxc Cleaned up the commits, should be easy to read now. |
This updates several old dependencies, removes some that are no longer needed, and adds `pkg/labels` from prometheus `dev-2.0` branch.
This is a temporary simplified re-implementation of promQL's metric selector parsing.
Filter alerts through `?filter=` query string.
Filter silences through `?filter=` query string.
0954959
to
049fbbd
Compare
Assuming tests pass, I would love to get this merged -- querying silences and alerts is something we definitely wanted to add to the API, and when we figure out how we want to do the inverse searching (I think that was one of the implementation optimizations) it can just be changed without modifying the API. Adding this also helps remove a decent amount of filtering code from #636 |
Sorry about dropping the ball. Generally looks fine to me 👍 |
sils = append(sils, s) | ||
} | ||
|
||
respond(w, sils) | ||
} | ||
|
||
func matchesFilterLabels(s *types.Silence, matchers []*labels.Matcher) bool { | ||
sms := map[string]string{} | ||
for _, m := range s.Matchers { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't want to couple our protobuf representation, which is also our internal model to that type.
I'd have to give our whole architecture a proper look and see how it all fits with the modeling changes we discussed as part of the new UI.
parse/parse.go
Outdated
@@ -0,0 +1,59 @@ | |||
package parse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this to pkg/parse
?
* refactor alert fetch to pull filters * discard all multiple query logic in favor of simpler regex * discard all matching logic * cleanup a number of small things that made the code odd * relax the regex in pkg/parse/parse.go to allow no quote characters
@fabxc something I wanted to add in the new UI was filtering alerts using the same promql label matching language.
promQL and the metric.LabelMatchers aren't a separable library, so it makes for a super terrible vendoring situation.I talked with @beorn7 and he reminded me that you had mentioned that you wanted promQL to be usable as a standalone package.Do you have any thoughts on this? Is this something we could do to contribute to the project?package
labels
are imported from prometheus branchdev-2.0
.