-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NETOBSERV-1935: enable metrics from list/nested fields (#739)
* NETOBSERV-1935: enable metrics from list/nested fields This makes it possible to generate metrics with labels/filters set on list fields (e.g. interfaces) and nested fields (e.g. soon-coming structured network events) In metrics API, user needs to configure explicitly which list field needs to be "flattened", in order to be consumable as filters/labels. Nested fields can be consumed as filters/labels with the ">" character; E.g: `flatten: [networkEvents], filters: [{key: "networkEvents>type", value: "acl"}], labels: [networkEvents>name]` This is a sample config to filter a metric for ACL events and label it by name * linter
- Loading branch information
Showing
15 changed files
with
569 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package metrics | ||
|
||
import "github.com/netobserv/flowlogs-pipeline/pkg/config" | ||
|
||
func (p *Preprocessed) ApplyFilters(flow config.GenericMap, flatParts []config.GenericMap) (bool, []config.GenericMap) { | ||
filteredParts := flatParts | ||
for _, filter := range p.filters { | ||
if filter.useFlat { | ||
filteredParts = filter.filterFlatParts(filteredParts) | ||
if len(filteredParts) == 0 { | ||
return false, nil | ||
} | ||
} else if !filter.predicate(flow) { | ||
return false, nil | ||
} | ||
} | ||
return true, filteredParts | ||
} | ||
|
||
func (pf *preprocessedFilter) filterFlatParts(flatParts []config.GenericMap) []config.GenericMap { | ||
var filteredParts []config.GenericMap | ||
for _, part := range flatParts { | ||
if pf.predicate(part) { | ||
filteredParts = append(filteredParts, part) | ||
} | ||
} | ||
return filteredParts | ||
} |
Oops, something went wrong.