forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter_test.go
132 lines (112 loc) · 3.22 KB
/
filter_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package filter
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestCompile(t *testing.T) {
f, err := Compile(nil)
require.NoError(t, err)
require.Nil(t, f)
f, err = Compile([]string{"cpu"})
require.NoError(t, err)
require.True(t, f.Match("cpu"))
require.False(t, f.Match("cpu0"))
require.False(t, f.Match("mem"))
f, err = Compile([]string{"cpu*"})
require.NoError(t, err)
require.True(t, f.Match("cpu"))
require.True(t, f.Match("cpu0"))
require.False(t, f.Match("mem"))
f, err = Compile([]string{"cpu", "mem"})
require.NoError(t, err)
require.True(t, f.Match("cpu"))
require.False(t, f.Match("cpu0"))
require.True(t, f.Match("mem"))
f, err = Compile([]string{"cpu", "mem", "net*"})
require.NoError(t, err)
require.True(t, f.Match("cpu"))
require.False(t, f.Match("cpu0"))
require.True(t, f.Match("mem"))
require.True(t, f.Match("network"))
f, err = Compile([]string{"cpu.*.count"}, '.')
require.NoError(t, err)
require.False(t, f.Match("cpu.count"))
require.True(t, f.Match("cpu.measurement.count"))
require.False(t, f.Match("cpu.field.measurement.count"))
f, err = Compile([]string{"cpu.*.count"}, '.', ',')
require.NoError(t, err)
require.True(t, f.Match("cpu.measurement.count"))
require.False(t, f.Match("cpu.,.count")) // ',' is not considered under * as it is specified as a separator
require.False(t, f.Match("cpu.field,measurement.count"))
}
func TestIncludeExclude(t *testing.T) {
labels := []string{"best", "com_influxdata", "timeseries", "com_influxdata_telegraf", "ever"}
tags := make([]string, 0, len(labels))
filter, err := NewIncludeExcludeFilter(nil, []string{"com_influx*"})
if err != nil {
t.Fatalf("Failed to create include/exclude filter - %v", err)
}
for i := range labels {
if filter.Match(labels[i]) {
tags = append(tags, labels[i])
}
}
require.Equal(t, []string{"best", "timeseries", "ever"}, tags)
}
var benchbool bool
func BenchmarkFilterSingleNoGlobFalse(b *testing.B) {
f, err := Compile([]string{"cpu"})
require.NoError(b, err)
var tmp bool
for n := 0; n < b.N; n++ {
tmp = f.Match("network")
}
benchbool = tmp
}
func BenchmarkFilterSingleNoGlobTrue(b *testing.B) {
f, err := Compile([]string{"cpu"})
require.NoError(b, err)
var tmp bool
for n := 0; n < b.N; n++ {
tmp = f.Match("cpu")
}
benchbool = tmp
}
func BenchmarkFilter(b *testing.B) {
f, err := Compile([]string{"cpu", "mem", "net*"})
require.NoError(b, err)
var tmp bool
for n := 0; n < b.N; n++ {
tmp = f.Match("network")
}
benchbool = tmp
}
func BenchmarkFilterNoGlob(b *testing.B) {
f, err := Compile([]string{"cpu", "mem", "net"})
require.NoError(b, err)
var tmp bool
for n := 0; n < b.N; n++ {
tmp = f.Match("net")
}
benchbool = tmp
}
func BenchmarkFilter2(b *testing.B) {
f, err := Compile([]string{"aa", "bb", "c", "ad", "ar", "at", "aq",
"aw", "az", "axxx", "ab", "cpu", "mem", "net*"})
require.NoError(b, err)
var tmp bool
for n := 0; n < b.N; n++ {
tmp = f.Match("network")
}
benchbool = tmp
}
func BenchmarkFilter2NoGlob(b *testing.B) {
f, err := Compile([]string{"aa", "bb", "c", "ad", "ar", "at", "aq",
"aw", "az", "axxx", "ab", "cpu", "mem", "net"})
require.NoError(b, err)
var tmp bool
for n := 0; n < b.N; n++ {
tmp = f.Match("net")
}
benchbool = tmp
}