Skip to content

Commit f701321

Browse files
committed
fix merge conflicts
1 parent c10119c commit f701321

File tree

3 files changed

+5
-96
lines changed

3 files changed

+5
-96
lines changed

pkg/pipeline/encode/metrics/preprocess.go

Lines changed: 3 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package metrics
22

33
import (
4-
"fmt"
54
"regexp"
65
"strings"
76

87
"github.com/netobserv/flowlogs-pipeline/pkg/api"
9-
"github.com/netobserv/flowlogs-pipeline/pkg/config"
10-
"github.com/netobserv/flowlogs-pipeline/pkg/utils"
118
"github.com/netobserv/flowlogs-pipeline/pkg/utils/filters"
129
)
1310

@@ -24,7 +21,7 @@ type MappedLabel struct {
2421
}
2522

2623
type preprocessedFilter struct {
27-
predicate Predicate
24+
predicate filters.Predicate
2825
useFlat bool
2926
}
3027

@@ -39,61 +36,7 @@ func (p *Preprocessed) TargetLabels() []string {
3936
return targetLabels
4037
}
4138

42-
func Presence(filter api.MetricsFilter) Predicate {
43-
return func(flow config.GenericMap) bool {
44-
_, found := flow[filter.Key]
45-
return found
46-
}
47-
}
48-
49-
func Absence(filter api.MetricsFilter) Predicate {
50-
pred := Presence(filter)
51-
return func(flow config.GenericMap) bool { return !pred(flow) }
52-
}
53-
54-
func Equal(filter api.MetricsFilter) Predicate {
55-
varLookups := extractVarLookups(filter.Value)
56-
return func(flow config.GenericMap) bool {
57-
if val, found := flow[filter.Key]; found {
58-
sVal, ok := val.(string)
59-
if !ok {
60-
sVal = fmt.Sprint(val)
61-
}
62-
value := filter.Value
63-
if len(varLookups) > 0 {
64-
value = injectVars(flow, value, varLookups)
65-
}
66-
return sVal == value
67-
}
68-
return false
69-
}
70-
}
71-
72-
func NotEqual(filter api.MetricsFilter) Predicate {
73-
pred := Equal(filter)
74-
return func(flow config.GenericMap) bool { return !pred(flow) }
75-
}
76-
77-
func Regex(filter api.MetricsFilter) Predicate {
78-
r, _ := regexp.Compile(filter.Value)
79-
return func(flow config.GenericMap) bool {
80-
if val, found := flow[filter.Key]; found {
81-
sVal, ok := val.(string)
82-
if !ok {
83-
sVal = fmt.Sprint(val)
84-
}
85-
return r.MatchString(sVal)
86-
}
87-
return false
88-
}
89-
}
90-
91-
func NotRegex(filter api.MetricsFilter) Predicate {
92-
pred := Regex(filter)
93-
return func(flow config.GenericMap) bool { return !pred(flow) }
94-
}
95-
96-
func filterToPredicate(filter api.MetricsFilter) Predicate {
39+
func filterToPredicate(filter api.MetricsFilter) filters.Predicate {
9740
switch filter.Type {
9841
case api.MetricFilterEqual:
9942
return filters.Equal(filter.Key, filter.Value, true)
@@ -111,32 +54,7 @@ func filterToPredicate(filter api.MetricsFilter) Predicate {
11154
return filters.NotRegex(filter.Key, r)
11255
}
11356
// Default = Exact
114-
return Equal(filter)
115-
}
116-
117-
func extractVarLookups(value string) [][]string {
118-
// Extract list of variables to lookup
119-
// E.g: filter "$(SrcAddr):$(SrcPort)" would return [SrcAddr,SrcPort]
120-
if len(value) > 0 {
121-
return variableExtractor.FindAllStringSubmatch(value, -1)
122-
}
123-
return nil
124-
}
125-
126-
func injectVars(flow config.GenericMap, filterValue string, varLookups [][]string) string {
127-
injected := filterValue
128-
for _, matchGroup := range varLookups {
129-
var value string
130-
if rawVal, found := flow[matchGroup[1]]; found {
131-
if sVal, ok := rawVal.(string); ok {
132-
value = sVal
133-
} else {
134-
value = utils.ConvertToString(rawVal)
135-
}
136-
}
137-
injected = strings.ReplaceAll(injected, matchGroup[0], value)
138-
}
139-
return injected
57+
return filters.Equal(filter.Key, filter.Value, true)
14058
}
14159

14260
func Preprocess(def *api.MetricsItem) *Preprocessed {

pkg/pipeline/encode/metrics/preprocess_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ import (
88
"github.com/stretchr/testify/assert"
99
)
1010

11-
func Test_Filters_extractVarLookups(t *testing.T) {
12-
variables := extractVarLookups("$(abc)--$(def)")
13-
14-
assert.Equal(t, [][]string{{"$(abc)", "abc"}, {"$(def)", "def"}}, variables)
15-
16-
variables = extractVarLookups("")
17-
assert.Empty(t, variables)
18-
}
19-
2011
func Test_Flatten(t *testing.T) {
2112
pp := Preprocess(&api.MetricsItem{Flatten: []string{"interfaces", "events"}})
2213
fl := pp.GenerateFlatParts(config.GenericMap{

pkg/utils/filters/filters.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/netobserv/flowlogs-pipeline/pkg/utils"
1111
)
1212

13-
type Predicate func(flow config.GenericMap) bool
13+
type Predicate func(config.GenericMap) bool
1414

1515
var variableExtractor = regexp.MustCompile(`\$\(([^\)]+)\)`)
1616

@@ -106,7 +106,7 @@ func injectVars(flow config.GenericMap, filterValue string, varLookups [][]strin
106106
if sVal, ok := rawVal.(string); ok {
107107
value = sVal
108108
} else {
109-
value = fmt.Sprint(rawVal)
109+
value = utils.ConvertToString(rawVal)
110110
}
111111
}
112112
injected = strings.ReplaceAll(injected, matchGroup[0], value)

0 commit comments

Comments
 (0)