-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
duplicated_events_test.go
730 lines (679 loc) · 32.2 KB
/
duplicated_events_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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
package pathologicaleventlibrary
import (
_ "embed"
"regexp"
"testing"
"time"
v1 "github.com/openshift/api/config/v1"
"github.com/openshift/origin/pkg/monitor/monitorapi"
"github.com/stretchr/testify/assert"
)
func TestEventCountExtractor(t *testing.T) {
tests := []struct {
name string
input string
message string
times int
}{
{
name: "simple",
input: `pod/network-check-target-5f44k node/ip-10-0-210-155.us-west-2.compute.internal - reason/NetworkNotReady network is not ready: container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:Network plugin returns error: No CNI configuration file in /etc/kubernetes/cni/net.d/. Has your network provider started? (24 times)`,
message: `pod/network-check-target-5f44k node/ip-10-0-210-155.us-west-2.compute.internal - reason/NetworkNotReady network is not ready: container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:Network plugin returns error: No CNI configuration file in /etc/kubernetes/cni/net.d/. Has your network provider started?`,
times: 24,
},
{
name: "new lines",
input: "ns/e2e-container-probe-7285 pod/liveness-f0fce2c6-6eed-4ace-bf69-2df5e5b8b1ea node/ci-op-sti304mj-2a78c-pq5zv-worker-b-sknbn reason/ProbeWarning Liveness probe warning: <a href=\"http://0.0.0.0/\">Found</a>.\n\n (22 times)",
message: "ns/e2e-container-probe-7285 pod/liveness-f0fce2c6-6eed-4ace-bf69-2df5e5b8b1ea node/ci-op-sti304mj-2a78c-pq5zv-worker-b-sknbn reason/ProbeWarning Liveness probe warning: <a href=\"http://0.0.0.0/\">Found</a>.\n\n",
times: 22,
},
{
name: "other message",
input: "some node message",
times: 0,
},
{
name: "pod eviction failure",
input: "reason/MalscheduledPod pod/router-default-84c89f5bf8-5rdcb pod/router-default-84c89f5bf8-bg9ql should be one per node, but all were placed on node/ip-10-0-172-166.ec2.internal; evicting pod/router-default-84c89f5bf8-5rdcb (79 times)",
message: "reason/MalscheduledPod pod/router-default-84c89f5bf8-5rdcb pod/router-default-84c89f5bf8-bg9ql should be one per node, but all were placed on node/ip-10-0-172-166.ec2.internal; evicting pod/router-default-84c89f5bf8-5rdcb",
times: 79,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
actualMessage, actualCount := GetTimesAnEventHappened(test.input)
assert.Equal(t, test.times, actualCount)
assert.Equal(t, test.message, actualMessage)
})
}
}
func TestEventRegexExcluder(t *testing.T) {
allowedRepeatedEventsRegex := combinedRegexp(AllowedRepeatedEventPatterns...)
tests := []struct {
name string
message string
}{
{
name: "port-forward",
message: `ns/e2e-port-forwarding-588 pod/pfpod node/ci-op-g1d5csj7-b08f5-fgrqd-worker-b-xj89f - reason/Unhealthy Readiness probe failed:`,
},
{
name: "container-probe",
message: ` ns/e2e-container-probe-3794 pod/test-webserver-3faa80d6-05f2-42a7-9846-099e8a4cf28c node/ci-op-gzm3mjwm-875d2-tvchv-worker-c-w47mw - reason/Unhealthy Readiness probe failed: Get "http://10.131.0.54:81/": dial tcp 10.131.0.54:81: connect: connection refused`,
},
{
name: "failing-init-container",
message: `ns/e2e-init-container-368 pod/pod-init-cb40ee55-e9c5-4c4b-b541-47cc018d9856 node/ci-op-ncxkp5gj-875d2-5jcfn-worker-c-pwf97 - reason/BackOff Back-off restarting failed container`,
},
{
name: "scc-test-3",
message: `ns/e2e-test-scc-578l5 pod/test3 - reason/FailedScheduling 0/6 nodes are available: 3 node(s) didn't match Pod's node affinity/selector, 3 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate.`,
},
{
name: "missing image",
message: `ns/e2e-deployment-478 pod/webserver-deployment-795d758f88-fdr4d node/ci-op-h1wxg6l0-16f7c-mb4sj-worker-b-wcdcf - reason/BackOff Back-off pulling image "webserver:404"`,
},
{
name: "non-root",
message: `ns/e2e-security-context-test-6596 pod/explicit-root-uid node/ci-op-isj7rd3k-2a78c-kk69w-worker-a-v4kdb - reason/Failed Error: container's runAsUser breaks non-root policy (pod: "explicit-root-uid_e2e-security-context-test-6596(22bf29d0-e546-4a15-8dd7-8acd9165c924)", container: explicit-root-uid)`,
},
{
name: "local-volume-failed-scheduling",
message: `ns/e2e-persistent-local-volumes-test-7012 pod/pod-940713ce-7645-4d8c-bba0-5705350a5655 reason/FailedScheduling 0/6 nodes are available: 1 node(s) had volume node affinity conflict, 2 node(s) didn't match Pod's node affinity/selector, 3 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate. (2 times)`,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
actual := allowedRepeatedEventsRegex.MatchString(test.message)
assert.True(t, actual, "did not match")
})
}
}
func TestUpgradeEventRegexExcluder(t *testing.T) {
allowedRepeatedEventsRegex := combinedRegexp(AllowedUpgradeRepeatedEventPatterns...)
tests := []struct {
name string
message string
}{
{
name: "etcd-member",
message: `ns/openshift-etcd-operator deployment/etcd-operator - reason/UnhealthyEtcdMember unhealthy members: ip-10-0-198-128.ec2.internal`,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
actual := allowedRepeatedEventsRegex.MatchString(test.message)
if !actual {
t.Fatal("did not match")
}
})
}
}
func buildInterval(message string) monitorapi.Interval {
return monitorapi.Interval{
Condition: monitorapi.Condition{Message: message},
From: time.Unix(872827200, 0).In(time.UTC),
To: time.Unix(872827200, 0).In(time.UTC),
}
}
func TestPathologicalEventsWithNamespaces(t *testing.T) {
evaluator := duplicateEventsEvaluator{
allowedRepeatedEventPatterns: AllowedRepeatedEventPatterns,
knownRepeatedEventsBugs: []KnownProblem{},
}
from := time.Unix(872827200, 0).In(time.UTC)
to := time.Unix(872827200, 0).In(time.UTC)
tests := []struct {
name string
namespace string
platform v1.PlatformType
topology v1.TopologyMode
intervals []monitorapi.Interval
expectedMessage string
}{
{
name: "matches 22 with namespace openshift",
intervals: []monitorapi.Interval{buildInterval("ns/openshift - reason/SomeEvent1 foo (22 times)")},
namespace: "openshift",
platform: v1.AWSPlatformType,
topology: v1.SingleReplicaTopologyMode,
expectedMessage: "1 events happened too frequently\n\nevent happened 22 times, something is wrong: - ns/openshift - reason/SomeEvent1 foo From: 04:00:00Z To: 04:00:00Z result=reject ",
},
{
name: "matches 22 with namespace e2e",
intervals: []monitorapi.Interval{buildInterval(`ns/random - reason/SomeEvent1 foo (22 times)`)},
namespace: "",
platform: v1.AWSPlatformType,
topology: v1.SingleReplicaTopologyMode,
expectedMessage: "1 events happened too frequently\n\nevent happened 22 times, something is wrong: - ns/random - reason/SomeEvent1 foo From: 04:00:00Z To: 04:00:00Z result=reject ",
},
{
name: "matches 22 with no namespace",
intervals: []monitorapi.Interval{buildInterval(`reason/SomeEvent1 foo (22 times)`)},
namespace: "",
platform: v1.AWSPlatformType,
topology: v1.SingleReplicaTopologyMode,
expectedMessage: "1 events happened too frequently\n\nevent happened 22 times, something is wrong: - reason/SomeEvent1 foo From: 04:00:00Z To: 04:00:00Z result=reject ",
},
{
name: "matches 12 with namespace openshift",
intervals: []monitorapi.Interval{buildInterval(`ns/openshift - reason/SomeEvent1 foo (12 times)`)},
namespace: "openshift",
platform: v1.AWSPlatformType,
topology: v1.SingleReplicaTopologyMode,
expectedMessage: "",
},
{
// This is ignored because it was during a master NodeUpdate interval
name: "ignore FailedScheduling in openshift-controller-manager if masters are updating",
intervals: []monitorapi.Interval{
{
Condition: monitorapi.Condition{
Level: monitorapi.Info,
StructuredLocator: monitorapi.Locator{
Type: monitorapi.LocatorTypeNode,
Keys: map[monitorapi.LocatorKey]string{}, // what node doesn't matter, all we can do is see if masters are updating
},
StructuredMessage: monitorapi.Message{
Reason: monitorapi.NodeUpdateReason,
HumanMessage: "config/rendered-master-5ab4844b3b5a58958785e2c27d99f50f phase/Update roles/control-plane,master reached desired config roles/control-plane,master",
Annotations: map[monitorapi.AnnotationKey]string{
monitorapi.AnnotationConstructed: "node-lifecycle-constructor",
monitorapi.AnnotationPhase: "Update",
monitorapi.AnnotationRoles: "control-plane,master",
},
},
},
Source: monitorapi.SourceNodeState,
From: from.Add(-1 * time.Minute),
To: to.Add(1 * time.Minute),
},
buildInterval(`ns/openshift-controller-manager reason/FailedScheduling 0/6 nodes are available: 2 node(s) were unschedulable, 4 node(s) didn't match pod anti-affinity rules. preemption: 0/6 nodes are available: 2 Preemption is not helpful for scheduling, 4 No preemption victims found for incoming pod.. (22 times)`)},
namespace: "openshift-controller-manager",
platform: v1.AWSPlatformType,
topology: v1.HighlyAvailableTopologyMode,
expectedMessage: "",
},
{
// This is not ignored because there were no masters in NodeUpdate
name: "match FailedScheduling in openshift-controller-manager when masters are not updating",
intervals: []monitorapi.Interval{
buildInterval(`ns/openshift-controller-manager reason/FailedScheduling 0/6 nodes are available: 2 node(s) were unschedulable, 4 node(s) didn't match pod anti-affinity rules. preemption: 0/6 nodes are available: 2 Preemption is not helpful for scheduling, 4 No preemption victims found for incoming pod.. (22 times)`)},
namespace: "openshift-controller-manager",
platform: v1.AWSPlatformType,
topology: v1.HighlyAvailableTopologyMode,
expectedMessage: "1 events happened too frequently\n\nevent happened 22 times, something is wrong: - ns/openshift-controller-manager reason/FailedScheduling 0/6 nodes are available: 2 node(s) were unschedulable, 4 node(s) didn't match pod anti-affinity rules. preemption: 0/6 nodes are available: 2 Preemption is not helpful for scheduling, 4 No preemption victims found for incoming pod.. From: 04:00:00Z To: 04:00:00Z result=reject ",
},
{
// This still matches despite the masters updating because it's not in an openshift namespace
name: "match FailedScheduling outside openshift namespaces if masters are updating",
intervals: []monitorapi.Interval{
{
Condition: monitorapi.Condition{
Level: monitorapi.Info,
StructuredLocator: monitorapi.Locator{
Type: monitorapi.LocatorTypeNode,
Keys: map[monitorapi.LocatorKey]string{}, // what node doesn't matter, all we can do is see if masters are updating
},
StructuredMessage: monitorapi.Message{
Reason: monitorapi.NodeUpdateReason,
HumanMessage: "config/rendered-master-5ab4844b3b5a58958785e2c27d99f50f phase/Update roles/control-plane,master reached desired config roles/control-plane,master",
Annotations: map[monitorapi.AnnotationKey]string{
monitorapi.AnnotationConstructed: "node-lifecycle-constructor",
monitorapi.AnnotationPhase: "Update",
monitorapi.AnnotationRoles: "control-plane,master",
},
},
},
Source: monitorapi.SourceNodeState,
From: from.Add(-1 * time.Minute),
To: to.Add(1 * time.Minute),
},
buildInterval(`ns/mynamespace reason/FailedScheduling 0/6 nodes are available: 2 node(s) were unschedulable, 4 node(s) didn't match pod anti-affinity rules. preemption: 0/6 nodes are available: 2 Preemption is not helpful for scheduling, 4 No preemption victims found for incoming pod.. (22 times)`)},
namespace: "mynamespace",
platform: v1.AWSPlatformType,
topology: v1.HighlyAvailableTopologyMode,
expectedMessage: "1 events happened too frequently\n\nevent happened 22 times, something is wrong: - ns/mynamespace reason/FailedScheduling 0/6 nodes are available: 2 node(s) were unschedulable, 4 node(s) didn't match pod anti-affinity rules. preemption: 0/6 nodes are available: 2 Preemption is not helpful for scheduling, 4 No preemption victims found for incoming pod.. From: 04:00:00Z To: 04:00:00Z result=reject ",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
events := monitorapi.Intervals(test.intervals)
evaluator.platform = test.platform
evaluator.topology = test.topology
testName := "events should not repeat"
junits := evaluator.testDuplicatedEvents(testName, false, events, nil, false)
namespaces := getNamespacesForJUnits()
assert.Equal(t, len(namespaces), len(junits), "didn't get junits for all known namespaces")
jUnitName := getJUnitName(testName, test.namespace)
for _, junit := range junits {
if (junit.Name == jUnitName) && (test.expectedMessage != "") {
assert.Equal(t, test.expectedMessage, junit.FailureOutput.Output)
} else {
if !assert.Nil(t, junit.FailureOutput, "expected success but got failure output") {
t.Logf(junit.FailureOutput.Output)
}
}
}
})
}
}
func TestKnownBugEvents(t *testing.T) {
evaluator := duplicateEventsEvaluator{
allowedRepeatedEventPatterns: AllowedRepeatedEventPatterns,
knownRepeatedEventsBugs: []KnownProblem{
{
Regexp: regexp.MustCompile(`ns/.* reason/SomeEvent1.*`),
BZ: "https://bugzilla.redhat.com/show_bug.cgi?id=1234567",
},
{
Regexp: regexp.MustCompile("ns/.*reason/SomeEvent2.*"),
BZ: "https://bugzilla.redhat.com/show_bug.cgi?id=1234567",
Topology: TopologyPointer(v1.SingleReplicaTopologyMode),
},
{
Regexp: regexp.MustCompile("ns/.*reason/SomeEvent3.*"),
BZ: "https://bugzilla.redhat.com/show_bug.cgi?id=1234567",
Platform: PlatformPointer(v1.AWSPlatformType),
},
{
Regexp: regexp.MustCompile("ns/.*reason/SomeEvent4.*"),
BZ: "https://bugzilla.redhat.com/show_bug.cgi?id=1234567",
Topology: TopologyPointer(v1.HighlyAvailableTopologyMode),
},
{
Regexp: regexp.MustCompile("ns/.*reason/SomeEvent5.*"),
BZ: "https://bugzilla.redhat.com/show_bug.cgi?id=1234567",
Platform: PlatformPointer(v1.GCPPlatformType),
},
{
Regexp: regexp.MustCompile("ns/.*reason/SomeEvent6.*"),
BZ: "https://bugzilla.redhat.com/show_bug.cgi?id=1234567",
Platform: PlatformPointer(""),
},
},
}
tests := []struct {
name string
message string
match bool
platform v1.PlatformType
topology v1.TopologyMode
}{
{
name: "matches without platform or topology",
message: `ns/e2e - reason/SomeEvent1 foo (21 times)`,
match: true,
platform: v1.AWSPlatformType,
topology: v1.SingleReplicaTopologyMode,
},
{
name: "matches with topology",
message: `ns/e2e - reason/SomeEvent2 foo (21 times)`,
match: true,
platform: v1.AWSPlatformType,
topology: v1.SingleReplicaTopologyMode,
},
{
name: "matches with topology and platform",
message: `ns/e2e - reason/SomeEvent3 foo (21 times)`,
match: true,
platform: v1.AWSPlatformType,
topology: v1.SingleReplicaTopologyMode,
},
{
name: "does not match against different topology",
message: `ns/e2e - reason/SomeEvent4 foo (21 times)`,
platform: v1.AWSPlatformType,
topology: v1.SingleReplicaTopologyMode,
match: false,
},
{
name: "does not match against different platform",
message: `ns/e2e - reason/SomeEvent5 foo (21 times)`,
platform: v1.AWSPlatformType,
topology: v1.SingleReplicaTopologyMode,
match: false,
},
{
name: "empty platform matches empty platform",
message: `ns/e2e - reason/SomeEvent6 foo (21 times)`,
platform: "",
match: true,
},
{
name: "empty platform doesn't match another platform",
message: `ns/e2e - reason/SomeEvent6 foo (21 times)`,
platform: v1.AWSPlatformType,
match: false,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
events := monitorapi.Intervals{}
events = append(events,
monitorapi.Interval{
Condition: monitorapi.Condition{Message: test.message},
From: time.Unix(1, 0).In(time.UTC),
To: time.Unix(1, 0).In(time.UTC)},
)
evaluator.platform = test.platform
evaluator.topology = test.topology
junits := evaluator.testDuplicatedEvents("events should not repeat", false, events, nil, true)
assert.GreaterOrEqual(t, len(junits), 1, "didn't get junit for duplicated event")
if test.match {
assert.Contains(t, junits[0].FailureOutput.Output, "1 events with known BZs")
} else {
assert.NotContains(t, junits[0].FailureOutput.Output, "1 events with known BZs")
}
})
}
}
func TestKnownBugEventsGroup(t *testing.T) {
evaluator := duplicateEventsEvaluator{
allowedRepeatedEventPatterns: AllowedRepeatedEventPatterns,
knownRepeatedEventsBugs: []KnownProblem{
{
Regexp: regexp.MustCompile(`ns/.* reason/SomeEvent1.*`),
BZ: "https://bugzilla.redhat.com/show_bug.cgi?id=1234567",
},
},
}
tests := []struct {
name string
messages []string
platform v1.PlatformType
topology v1.TopologyMode
expectedMessage string
}{
{
name: "matches 22 before",
messages: []string{`ns/e2e - reason/SomeEvent1 foo (22 times)`, `ns/e2e - reason/SomeEvent1 foo (21 times)`},
platform: v1.AWSPlatformType,
topology: v1.SingleReplicaTopologyMode,
expectedMessage: "1 events with known BZs\n\nevent happened 22 times, something is wrong: - ns/e2e - reason/SomeEvent1 foo From: 04:00:00Z To: 04:00:00Z - https://bugzilla.redhat.com/show_bug.cgi?id=1234567 result=allow ",
},
{
name: "matches 25 after",
messages: []string{`ns/e2e - reason/SomeEvent1 foo (21 times)`, `ns/e2e - reason/SomeEvent1 foo (25 times)`},
platform: v1.AWSPlatformType,
topology: v1.SingleReplicaTopologyMode,
expectedMessage: "1 events with known BZs\n\nevent happened 25 times, something is wrong: - ns/e2e - reason/SomeEvent1 foo From: 04:00:00Z To: 04:00:00Z - https://bugzilla.redhat.com/show_bug.cgi?id=1234567 result=allow ",
},
{
name: "matches 22 below with below threshold following",
messages: []string{`ns/e2e - reason/SomeEvent1 foo (22 times)`, `ns/e2e - reason/SomeEvent1 foo (5 times)`},
platform: v1.AWSPlatformType,
topology: v1.SingleReplicaTopologyMode,
expectedMessage: "1 events with known BZs\n\nevent happened 22 times, something is wrong: - ns/e2e - reason/SomeEvent1 foo From: 04:00:00Z To: 04:00:00Z - https://bugzilla.redhat.com/show_bug.cgi?id=1234567 result=allow ",
},
{
name: "matches 22 with multiple line message",
messages: []string{"ns/e2e - reason/SomeEvent1 foo \nbody:\n (22 times)"},
platform: v1.AWSPlatformType,
topology: v1.SingleReplicaTopologyMode,
expectedMessage: "1 events with known BZs\n\nevent happened 22 times, something is wrong: - ns/e2e - reason/SomeEvent1 foo result=allow \nbody:\n From: 04:00:00Z To: 04:00:00Z - https://bugzilla.redhat.com/show_bug.cgi?id=1234567",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
events := monitorapi.Intervals{}
for _, message := range test.messages {
events = append(events,
monitorapi.Interval{
Condition: monitorapi.Condition{Message: message},
From: time.Unix(872827200, 0).In(time.UTC),
To: time.Unix(872827200, 0).In(time.UTC)},
)
}
evaluator.platform = test.platform
evaluator.topology = test.topology
junits := evaluator.testDuplicatedEvents("events should not repeat", false, events, nil, true)
assert.GreaterOrEqual(t, len(junits), 1, "didn't get junit for duplicated event")
assert.Equal(t, test.expectedMessage, junits[0].FailureOutput.Output)
})
}
}
func TestMakeProbeTestEventsGroup(t *testing.T) {
tests := []struct {
name string
messages []string
match bool
regEx string
operator string
expectedMessage string
}{
{
name: "matches 22 before",
messages: []string{`ns/e2e - reason/ProbeError foo Liveness probe error: Get "https://10.128.0.21:8443/healthz": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) occurred (22 times)`, `ns/e2e - reason/ProbeError foo Liveness probe error: Get "https://10.128.0.21:8443/healthz": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) occurred (21 times)`},
match: true,
operator: "e2e",
regEx: ProbeErrorLivenessMessageRegExpStr,
expectedMessage: "00:00:01 ns/e2e - reason/ProbeError foo Liveness probe error: Get \"https://10.128.0.21:8443/healthz\": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) occurred (22 times)\n",
},
{
name: "no matches 22 before",
messages: []string{`ns/e2e - reason/ProbeError foo Liveness probe error: Get "https://10.128.0.21:8443/healthz": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) occurred (22 times)`, `ns/e2e - reason/ProbeError foo Liveness probe error: Get "https://10.128.0.21:8443/healthz": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) occurred (21 times)`},
match: false,
operator: "e2e",
regEx: ProbeErrorConnectionRefusedRegExpStr,
expectedMessage: "",
},
{
name: "matches 25 after",
messages: []string{`ns/openshift-oauth-apiserver pod/apiserver-647fc6c7bf-s8b4h node/ip-10-0-150-209.us-west-1.compute.internal - reason/ProbeError Readiness probe error: Get "https://10.128.0.38:8443/readyz": dial tcp 10.128.0.38:8443: connect: connection refused occurred (22 times)`, `ns/openshift-oauth-apiserver pod/apiserver-647fc6c7bf-s8b4h node/ip-10-0-150-209.us-west-1.compute.internal - reason/ProbeError Readiness probe error: Get "https://10.128.0.38:8443/readyz": dial tcp 10.128.0.38:8443: connect: connection refused occurred (25 times)`},
operator: "openshift-oauth-apiserver",
match: true,
regEx: ProbeErrorConnectionRefusedRegExpStr,
expectedMessage: "00:00:01 ns/openshift-oauth-apiserver pod/apiserver-647fc6c7bf-s8b4h node/ip-10-0-150-209.us-west-1.compute.internal - reason/ProbeError Readiness probe error: Get \"https://10.128.0.38:8443/readyz\": dial tcp 10.128.0.38:8443: connect: connection refused occurred (25 times)\n",
},
{
name: "no matches 25 after",
messages: []string{`ns/openshift-oauth-apiserver pod/apiserver-647fc6c7bf-s8b4h node/ip-10-0-150-209.us-west-1.compute.internal - reason/ProbeError Readiness probe error: Get "https://10.128.0.38:8443/readyz": dial tcp 10.128.0.38:8443: connect: connection refused occurred (22 times)`, `ns/openshift-oauth-apiserver pod/apiserver-647fc6c7bf-s8b4h node/ip-10-0-150-209.us-west-1.compute.internal - reason/ProbeError Readiness probe error: Get "https://10.128.0.38:8443/readyz": dial tcp 10.128.0.38:8443: connect: connection refused occurred (25 times)`},
operator: "openshift-oauth-apiserver",
match: false,
regEx: ProbeErrorLivenessMessageRegExpStr,
expectedMessage: "",
},
{
name: "matches 22 below with below threshold following",
messages: []string{`reason/ProbeError Readiness probe error: Get "https://10.130.0.15:8443/healthz": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) occurred (22 times)`, `reason/ProbeError Readiness probe error: Get "https://10.130.0.15:8443/healthz": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) occurred (5 times)`},
operator: "openshift-oauth-apiserver",
match: true,
regEx: ProbeErrorReadinessMessageRegExpStr,
expectedMessage: "00:00:01 reason/ProbeError Readiness probe error: Get \"https://10.130.0.15:8443/healthz\": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) occurred (22 times)\n",
},
{
name: "no matches 22 below with below threshold following",
messages: []string{`reason/ProbeError Readiness probe error: Get "https://10.130.0.15:8443/healthz": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) occurred (22 times)`, `reason/ProbeError Readiness probe error: Get "https://10.130.0.15:8443/healthz": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) occurred (5 times)`},
operator: "openshift-oauth-apiserver",
match: false,
regEx: ProbeErrorConnectionRefusedRegExpStr,
expectedMessage: "",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
events := monitorapi.Intervals{}
for _, message := range test.messages {
events = append(events,
monitorapi.Interval{
Condition: monitorapi.Condition{Message: message},
From: time.Unix(1, 0).In(time.UTC),
To: time.Unix(1, 0).In(time.UTC)},
)
}
junits := MakeProbeTest("Test Test", events, test.operator, test.regEx, DuplicateEventThreshold)
assert.GreaterOrEqual(t, len(junits), 1, "Didn't get junit for duplicated event")
if test.match {
assert.Equal(t, test.expectedMessage, junits[0].FailureOutput.Output)
} else {
assert.Nil(t, junits[0].FailureOutput, "expected case to not match, but it did: %s", test.name)
}
})
}
}
func TestPathologicalEventsTopologyAwareHintsDisabled(t *testing.T) {
evaluator := duplicateEventsEvaluator{
allowedRepeatedEventPatterns: AllowedRepeatedEventPatterns,
knownRepeatedEventsBugs: []KnownProblem{},
}
from := time.Unix(872827200, 0).In(time.UTC)
to := time.Unix(872827200, 0).In(time.UTC)
tests := []struct {
name string
namespace string
platform v1.PlatformType
topology v1.TopologyMode
intervals []monitorapi.Interval
expectedMessage string
}{
{
// This is ignored because the node is tainted by test
name: "ignore TopologyAwareHintsDisabled before dns container ready",
intervals: []monitorapi.Interval{
{
Condition: monitorapi.Condition{
Level: monitorapi.Info,
StructuredLocator: monitorapi.Locator{
Type: monitorapi.LocatorTypeE2ETest,
Keys: map[monitorapi.LocatorKey]string{
monitorapi.LocatorE2ETestKey: "[sig-node] NoExecuteTaintManager Single Pod [Serial] doesn't evict pod with tolerations from tainted nodes [Skipped:SingleReplicaTopology] [Suite:openshift/conformance/serial] [Suite:k8s]",
},
},
StructuredMessage: monitorapi.Message{},
},
Source: monitorapi.SourceE2ETest,
From: from.Add(-10 * time.Minute),
To: to.Add(10 * time.Minute),
},
{
Condition: monitorapi.Condition{
Level: monitorapi.Info,
StructuredLocator: monitorapi.Locator{
Type: monitorapi.LocatorTypePod,
Keys: map[monitorapi.LocatorKey]string{
monitorapi.LocatorNamespaceKey: "openshift-dns",
monitorapi.LocatorPodKey: "dns-default-jq2qn",
},
},
StructuredMessage: monitorapi.Message{
Reason: monitorapi.PodReasonGracefulDeleteStarted,
Annotations: map[monitorapi.AnnotationKey]string{
monitorapi.AnnotationConstructed: "pod-lifecycle-constructor",
monitorapi.AnnotationReason: "GracefulDelete",
},
},
},
Source: monitorapi.SourcePodState,
From: from.Add(-5 * time.Minute),
To: to.Add(1 * time.Minute),
},
{
Condition: monitorapi.Condition{
Level: monitorapi.Info,
Message: "pathological/true reason/TopologyAwareHintsDisabled Unable to allocate minimum required endpoints to each zone without exceeding overload threshold (5 endpoints, 3 zones), addressType: IPv4 (23 times)",
},
From: from.Add(11 * time.Minute),
To: to.Add(12 * time.Minute),
},
{
Condition: monitorapi.Condition{
Level: monitorapi.Info,
StructuredLocator: monitorapi.Locator{
Type: monitorapi.LocatorTypeContainer,
Keys: map[monitorapi.LocatorKey]string{
monitorapi.LocatorNamespaceKey: "openshift-dns",
monitorapi.LocatorContainerKey: "dns",
monitorapi.LocatorPodKey: "dns-default-jq2qn",
},
},
StructuredMessage: monitorapi.Message{
Reason: monitorapi.ContainerReasonReady,
Annotations: map[monitorapi.AnnotationKey]string{
monitorapi.AnnotationConstructed: "pod-lifecycle-constructor",
monitorapi.AnnotationReason: "Ready",
},
},
},
Source: monitorapi.SourcePodState,
From: from.Add(15 * time.Minute),
To: to.Add(16 * time.Minute),
},
},
namespace: "openshift-dns",
expectedMessage: "",
},
{
// This is not ignored because there is no dns ready following
name: "fire TopologyAwareHintsDisabled when there is no dns container ready",
intervals: []monitorapi.Interval{
{
Condition: monitorapi.Condition{
Level: monitorapi.Info,
StructuredLocator: monitorapi.Locator{
Type: monitorapi.LocatorTypeE2ETest,
Keys: map[monitorapi.LocatorKey]string{
monitorapi.LocatorE2ETestKey: "[sig-node] NoExecuteTaintManager Single Pod [Serial] doesn't evict pod with tolerations from tainted nodes [Skipped:SingleReplicaTopology] [Suite:openshift/conformance/serial] [Suite:k8s]",
},
},
StructuredMessage: monitorapi.Message{},
},
Source: monitorapi.SourceE2ETest,
From: from.Add(-10 * time.Minute),
To: to.Add(10 * time.Minute),
},
{
Condition: monitorapi.Condition{
Level: monitorapi.Info,
StructuredLocator: monitorapi.Locator{
Type: monitorapi.LocatorTypePod,
Keys: map[monitorapi.LocatorKey]string{
monitorapi.LocatorNamespaceKey: "openshift-dns",
monitorapi.LocatorPodKey: "dns-default-jq2qn",
},
},
StructuredMessage: monitorapi.Message{
Reason: monitorapi.PodReasonGracefulDeleteStarted,
Annotations: map[monitorapi.AnnotationKey]string{
monitorapi.AnnotationConstructed: "pod-lifecycle-constructor",
monitorapi.AnnotationReason: "GracefulDelete",
},
},
},
Source: monitorapi.SourcePodState,
From: from.Add(-5 * time.Minute),
To: to.Add(1 * time.Minute),
},
{
Condition: monitorapi.Condition{
Level: monitorapi.Info,
Locator: "ns/openshift-dns service/dns-default hmsg/ade328ddf3",
Message: "pathological/true reason/TopologyAwareHintsDisabled Unable to allocate minimum required endpoints to each zone without exceeding overload threshold (5 endpoints, 3 zones), addressType: IPv4 (23 times)",
},
From: from.Add(11 * time.Minute),
To: to.Add(12 * time.Minute),
},
},
namespace: "openshift-dns",
expectedMessage: "1 events happened too frequently\n\nevent happened 23 times, something is wrong: ns/openshift-dns service/dns-default hmsg/ade328ddf3 - pathological/true reason/TopologyAwareHintsDisabled Unable to allocate minimum required endpoints to each zone without exceeding overload threshold (5 endpoints, 3 zones), addressType: IPv4 From: 04:11:00Z To: 04:12:00Z result=reject ",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
events := monitorapi.Intervals(test.intervals)
testName := "events should not repeat"
junits := evaluator.testDuplicatedEvents(testName, false, events, nil, false)
jUnitName := getJUnitName(testName, test.namespace)
for _, junit := range junits {
if (junit.Name == jUnitName) && (test.expectedMessage != "") {
assert.Equal(t, test.expectedMessage, junit.FailureOutput.Output)
} else {
if !assert.Nil(t, junit.FailureOutput, "expected success but got failure output") {
t.Logf(junit.FailureOutput.Output)
}
}
}
})
}
}