Skip to content

Commit acfaf0a

Browse files
Merge pull request #28399 from dgoodwin/patho-rework
TRT-1329: Refactor pathological events framework
2 parents 2435179 + d327eab commit acfaf0a

File tree

18 files changed

+1694
-1414
lines changed

18 files changed

+1694
-1414
lines changed

pkg/monitor/monitorapi/construction.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package monitorapi
22

33
import (
4+
"crypto/sha256"
45
"fmt"
56
"strings"
67
"time"
@@ -294,24 +295,37 @@ func (b *LocatorBuilder) withServer(serverName string) *LocatorBuilder {
294295
return b
295296
}
296297

298+
// TODO decide whether we want to allow "random" locator keys. deads2k is -1 on random locator keys and thinks we should enumerate every possible key we special case.
297299
func (b *LocatorBuilder) KubeEvent(event *corev1.Event) Locator {
298-
b.targetType = LocatorTypeKubeEvent
299300

300-
// WARNING: we're trying to use an enum for the locator keys, but we cannot know
301-
// all kinds in a cluster. Instead we'll split the kind and name into two different Keys
302-
// for Events:
303-
b.annotations[LocatorKindKey] = event.InvolvedObject.Kind
304-
b.annotations[LocatorNameKey] = event.InvolvedObject.Name
301+
// When Kube Events are displayed, we need repeats of the same event to appear on one line. To do this
302+
// we hash the event message, get the first ten characters, and add it as a hmsg locator key.
303+
hash := sha256.Sum256([]byte(event.Message))
304+
hashStr := fmt.Sprintf("%x", hash)[:10]
305+
b.annotations[LocatorHmsgKey] = hashStr
305306

306-
if len(event.InvolvedObject.Namespace) > 0 {
307-
b.annotations[LocatorNamespaceKey] = event.InvolvedObject.Namespace
307+
if event.InvolvedObject.Kind == "Namespace" {
308+
// namespace better match the event itself.
309+
return b.
310+
withNamespace(event.InvolvedObject.Name).
311+
Build()
312+
} else if event.InvolvedObject.Kind == "Node" {
313+
return b.
314+
withTargetType(LocatorTypeNode).
315+
withNode(event.InvolvedObject.Name).
316+
Build()
308317
}
309318

310-
// TODO: node + namespace is illegal, look at original impl, it may have handled this better
311-
if len(event.Source.Host) > 0 && event.InvolvedObject.Kind != "Node" {
319+
// Otherwise we have to fall back to a generic "Kind" locator, likely what deads2k refers to above as sketchy.
320+
// For now just preserving the old logic.
321+
b.targetType = LocatorTypeKind
322+
b.annotations[LocatorKey(strings.ToLower(event.InvolvedObject.Kind))] = event.InvolvedObject.Name
323+
if len(event.Source.Host) > 0 && event.Source.Component == "kubelet" {
312324
b.annotations[LocatorNodeKey] = event.Source.Host
313325
}
314-
326+
if len(event.InvolvedObject.Namespace) > 0 {
327+
b.annotations[LocatorNamespaceKey] = event.InvolvedObject.Namespace
328+
}
315329
return b.Build()
316330
}
317331

pkg/monitor/monitorapi/types.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ const (
109109
LocatorTypeE2ETest LocatorType = "E2ETest"
110110
LocatorTypeAPIServerShutdown LocatorType = "APIServerShutdown"
111111
LocatorTypeClusterVersion LocatorType = "ClusterVersion"
112+
LocatorTypeKind LocatorType = "Kind"
112113
LocatorTypeCloudMetrics LocatorType = "CloudMetrics"
113114
)
114115

@@ -120,10 +121,12 @@ const (
120121
LocatorClusterOperatorKey LocatorKey = "clusteroperator"
121122
LocatorClusterVersionKey LocatorKey = "clusterversion"
122123
LocatorNamespaceKey LocatorKey = "namespace"
124+
LocatorDeploymentKey LocatorKey = "deployment"
123125
LocatorNodeKey LocatorKey = "node"
124126
LocatorEtcdMemberKey LocatorKey = "etcd-member"
125127
LocatorKindKey LocatorKey = "kind"
126128
LocatorNameKey LocatorKey = "name"
129+
LocatorHmsgKey LocatorKey = "hmsg"
127130
LocatorPodKey LocatorKey = "pod"
128131
LocatorUIDKey LocatorKey = "uid"
129132
LocatorMirrorUIDKey LocatorKey = "mirror-uid"
@@ -213,11 +216,16 @@ const (
213216
AnnotationContainerExitCode AnnotationKey = "code"
214217
AnnotationCause AnnotationKey = "cause"
215218
AnnotationConfig AnnotationKey = "config"
219+
AnnotationContainer AnnotationKey = "container"
220+
AnnotationImage AnnotationKey = "image"
221+
AnnotationInteresting AnnotationKey = "interesting"
222+
AnnotationCount AnnotationKey = "count"
216223
AnnotationNode AnnotationKey = "node"
217224
AnnotationEtcdLocalMember AnnotationKey = "local-member-id"
218225
AnnotationEtcdTerm AnnotationKey = "term"
219226
AnnotationEtcdLeader AnnotationKey = "leader"
220227
AnnotationPreviousEtcdLeader AnnotationKey = "prev-leader"
228+
AnnotationPathological AnnotationKey = "pathological"
221229
AnnotationConstructed AnnotationKey = "constructed"
222230
AnnotationPhase AnnotationKey = "phase"
223231
AnnotationIsStaticPod AnnotationKey = "mirrored"
@@ -264,6 +272,7 @@ const (
264272
SourceAPIServerShutdown IntervalSource = "APIServerShutdown"
265273
SourceDisruption IntervalSource = "Disruption"
266274
SourceE2ETest IntervalSource = "E2ETest"
275+
SourceKubeEvent IntervalSource = "KubeEvent"
267276
SourceNetworkManagerLog IntervalSource = "NetworkMangerLog"
268277
SourceNodeMonitor IntervalSource = "NodeMonitor"
269278
SourceSystemJournalScanner IntervalSource = "KubeletLogScanner"
@@ -522,6 +531,11 @@ func IsInE2ENamespace(eventInterval Interval) bool {
522531

523532
func IsInNamespaces(namespaces sets.String) EventIntervalMatchesFunc {
524533
return func(eventInterval Interval) bool {
534+
// For new, structured locators:
535+
if ns, ok := eventInterval.StructuredLocator.Keys[LocatorNamespaceKey]; ok {
536+
return namespaces.Has(ns)
537+
}
538+
// TODO: For legacy locators, can be removed soon
525539
ns := NamespaceFromLocator(eventInterval.Locator)
526540
return namespaces.Has(ns)
527541
}

0 commit comments

Comments
 (0)