-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpattern_test.go
116 lines (92 loc) · 5.92 KB
/
pattern_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
package logparser
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
)
func TestPattern(t *testing.T) {
assert.Equal(t,
"package.name got things in",
NewPattern("2019-07-24 12:06:21,688 package.name [DEBUG] got 10 things in 3.1s").String())
assert.Equal(t,
"INFO GET",
NewPattern("INFO 192.168.1.6 GET /standalone?job_cycles=50000&sleep=20ms&sleep_jitter_percent=500 200 0.113s").String())
assert.Equal(t,
"WARN client closed connection after",
NewPattern("WARN client 192.168.1.8:57600 closed connection after 1.000s").String())
assert.Equal(t,
"Jun host kubelet watch of ended with too old resource version",
NewPattern("Jun 16 21:41:24 host01 kubelet[961]: W0616 21:41:24.642736 961 reflector.go:341] k8s.io/kubernetes/pkg/kubelet/config/apiserver.go:47: watch of *v1.Pod ended with: too old resource version: 81608152 (81608817)").String())
assert.Equal(t,
"Unable to ensure the docker processes run in the desired containers errors moving pid failed to find pid namespace of process",
NewPattern(`Unable to ensure the docker processes run in the desired containers: errors moving "docker-containerd" pid: failed to find pid namespace of process '㌟'`).String())
assert.Equal(t,
"ExecSync from runtime service failed rpc error code Unknown desc container not running",
NewPattern("ExecSync 099a0cbb70555d5d0e1823993175947487c9bc075171df5a161d8e46456b232c 'bash -c echo -ne \x01\x04\x00\x00\x00\x00 | nc 127.0.0.1 81' from runtime service failed: rpc error: code = Unknown desc = container not running (099a0cbb70555d5d0e1823993175947487c9bc075171df5a161d8e46456b232c)").String())
assert.Equal(t,
"Get request canceled",
NewPattern("2019/07/23 15:21:08 http-load-generator.go:49: Get http://golang-app/standalone?job_cycles=50000\u0026sleep=20ms\u0026sleep_jitter_percent=500: net/http: request canceled (Client.Timeout exceeded while awaiting headers)").String())
assert.Equal(t,
"query for app done in",
NewPattern(`2019/07/24 10:40:38.887696 module.go:3334: [INFO: 3fe862d0-f5d0-460f-88d5-e6088985e881]: query "{app!=[xz,xz3],name=[long.name]}" for app="xzxzx" done in 0.016s`).String())
assert.Equal(t,
"",
NewPattern(`[Full GC (Allocation Failure) [CMS: 176934K->176934K(176960K), 0.0451364 secs] 253546K->253546K(253632K), [Metaspace: 11797K->11797K(1060864K)], 0.0454767 secs] [Times: user=0.04 sys=0.00, real=0.05 secs]`).String())
assert.Equal(t,
"Nov FAIL message received from about",
NewPattern(`1:S 12 Nov 2019 07:52:11.999 * FAIL message received from b9112fbdd53291f1924bd3ff81d24b4d48e38929 about e16a51c1d8639a6cc904d8c4dce4ef6d5a1287c3`).String())
assert.Equal(t,
"Nov Start of election delayed for milliseconds",
NewPattern(`1:S 12 Nov 2019 13:17:07.347 # Start of election delayed for 502 milliseconds (rank #0, offset 99524)`).String())
assert.Equal(t,
"WARN org.eclipse.jetty.server.HttpChannel",
NewPattern(`11227 [qtp672320506-43] WARN org.eclipse.jetty.server.HttpChannel - /`).String())
assert.Equal(t,
NewPattern("\tat sun.reflect.GeneratedMethodAccessor72.invoke(Unknown Source) ~[na:na]").String(),
NewPattern("\tat sun.reflect.GeneratedMethodAccessor71.invoke(Unknown Source) ~[na:na]").String())
assert.Equal(t,
NewPattern("ERROR 1 --- [io-8080-exec-18] o.h.engine.jdbc.spi.SqlExceptionHelper : Too many connections").String(),
NewPattern("ERROR 1 --- [nio-8080-exec-9] o.h.engine.jdbc.spi.SqlExceptionHelper : Too many connections").String())
assert.Equal(t,
"no results match selector",
NewPattern(`[WARNING] no results match selector: {'status': ['1*', '2'], 'app': 'app1', 'host': 'parse*'}"}`).String())
assert.Equal(t,
"WARNING items are not found for project UniqueName",
NewPattern(`WARNING: d2cf9441-82d6-4fc6-8c16-d2a8531ff4a5 26 items are not found {name=[aaaabbbbbcccc]} for project UniqueName`).String())
assert.Equal(t,
"Dec gke-foo---bcbd-node-eoj startupscript Finished running startup script",
NewPattern(`Dec 21 23:17:22 gke-foo-1-1-4b5cbd14-node-4eoj startupscript: Finished running startup script /var/run/google.startup.script`).String())
assert.Equal(t,
"foo bar",
NewPattern(`foo @ 0x000000000daffc3b 0x1 0xaa 0aa3f bar`).String(),
)
}
func TestPatternWeakEqual(t *testing.T) {
assert.True(t, NewPattern("foo one baz").WeakEqual(NewPattern("foo two baz")))
assert.True(t, NewPattern("foo baz one").WeakEqual(NewPattern("foo baz two")))
assert.False(t, NewPattern("foo bar baz").WeakEqual(NewPattern("foo barr bazz")))
assert.False(t, NewPattern("foo bar baz").WeakEqual(NewPattern("baz bar foo")))
}
func BenchmarkPatternWeakEqual(b *testing.B) {
p1 := NewPattern("foo one two bar buz")
p2 := NewPattern("foo three four bar buz")
for n := 0; n < b.N; n++ {
p1.WeakEqual(p2)
}
}
func TestPatternRemoveQuotedAndBrackets(t *testing.T) {
buf := bytes.NewBuffer(nil)
assert.Equal(t, "foo bar", removeQuotedAndBrackets(`foo 'squoted' bar`, buf))
assert.Equal(t, "foo bar", removeQuotedAndBrackets(`foo 'squoted \'baz\'' bar`, buf))
assert.Equal(t, "foo bar", removeQuotedAndBrackets(`foo "dquoted" bar`, buf))
assert.Equal(t, "foo bar", removeQuotedAndBrackets(`foo "dquoted \"baz\"" bar`, buf))
assert.Equal(t, "foo bar", removeQuotedAndBrackets(`foo "dquoted 'squoted' " bar`, buf))
assert.Equal(t, "foo bar", removeQuotedAndBrackets(`foo 'squoted "baz"' bar`, buf))
assert.Equal(t, " msg", removeQuotedAndBrackets(`[nio-8080-exec-9] msg`, buf))
assert.Equal(t, "json: ", removeQuotedAndBrackets(`json: {'arr': ['1', '2'], 'str': 'strval', 'age': 20}`, buf))
assert.Equal(t, " ",
removeQuotedAndBrackets(`[Full GC (Allocation Failure) [CMS: 176934K->176934K(176960K), 0.0451364 secs] 253546K->253546K(253632K), [Metaspace: 11797K->11797K(1060864K)], 0.0454767 secs] [Times: user=0.04 sys=0.00, real=0.05 secs]`, buf))
assert.Equal(t,
"Jun 16 21:41:24 host01 kubelet: W0616 21:41:24.642736 961 reflector.go:341]",
removeQuotedAndBrackets(`Jun 16 21:41:24 host01 kubelet[961]: W0616 21:41:24.642736 961 reflector.go:341]`, buf))
}