Fix some event filtering
Make it possible to use health_status, exec_start and exec_create as is in event filter. This way, using `health_status` as filter will allow to get all health_status events (healthy, unhealthy, …) instead of having to us all combination (`health_status: healthy`, `health_status: unhealthy`, …). Same goes for `exec_start` and `exec_create`. Signed-off-by: Vincent Demeester <vincent@sbr.pm> Upstream-commit: 71d8313ad415b8ec6efff3e88f48b5465f30c9a9 Component: engine
This commit is contained in:
@@ -18,7 +18,7 @@ func NewFilter(filter filters.Args) *Filter {
|
||||
|
||||
// Include returns true when the event ev is included by the filters
|
||||
func (ef *Filter) Include(ev events.Message) bool {
|
||||
return ef.filter.ExactMatch("event", ev.Action) &&
|
||||
return ef.matchEvent(ev) &&
|
||||
ef.filter.ExactMatch("type", ev.Type) &&
|
||||
ef.matchDaemon(ev) &&
|
||||
ef.matchContainer(ev) &&
|
||||
@@ -29,6 +29,24 @@ func (ef *Filter) Include(ev events.Message) bool {
|
||||
ef.matchLabels(ev.Actor.Attributes)
|
||||
}
|
||||
|
||||
func (ef *Filter) matchEvent(ev events.Message) bool {
|
||||
// #25798 if an event filter contains either health_status, exec_create or exec_start without a colon
|
||||
// Let's to a FuzzyMatch instead of an ExactMatch.
|
||||
if ef.filterContains("event", map[string]struct{}{"health_status": {}, "exec_create": {}, "exec_start": {}}) {
|
||||
return ef.filter.FuzzyMatch("event", ev.Action)
|
||||
}
|
||||
return ef.filter.ExactMatch("event", ev.Action)
|
||||
}
|
||||
|
||||
func (ef *Filter) filterContains(field string, values map[string]struct{}) bool {
|
||||
for _, v := range ef.filter.Get(field) {
|
||||
if _, ok := values[v]; ok {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (ef *Filter) matchLabels(attributes map[string]string) bool {
|
||||
if !ef.filter.Include("label") {
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user