Skip to content

Commit

Permalink
Use the reportingComponent if source.component is missing for creatin…
Browse files Browse the repository at this point in the history
…g wavefront events from k8s events
  • Loading branch information
jerrybelmonte committed Dec 4, 2023
1 parent e146c81 commit 7e49908
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
9 changes: 8 additions & 1 deletion collector/plugins/events/eventrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,18 @@ func (er *EventRouter) addEvent(obj interface{}, isInInitialList bool) {
ns = "default"
}

var component string
if len(e.Source.Component) > 0 {
component = e.Source.Component
} else {
component = e.ReportingController
}

tags := map[string]string{
"namespace_name": ns,
"kind": e.InvolvedObject.Kind,
"reason": e.Reason,
"component": e.Source.Component,
"component": component,
"type": e.Type,
"important": e.Annotations["important"],
}
Expand Down
10 changes: 6 additions & 4 deletions collector/plugins/events/eventrouter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,28 @@ func TestAddEvent(t *testing.T) {
require.Equal(t, "test-namespace", event.InvolvedObject.Namespace)
})

t.Run("sets the lastTimestamp based on kubernetes event time if lastTimestamp is zero", func(t *testing.T) {
t.Run("sets the lastTimestamp and source component for FailedScheduling k8s events", func(t *testing.T) {
sink := &MockExport{}
er := NewEventRouter(fake.NewSimpleClientset(), configuration.EventsConfig{}, sink, true, testhelper.NewEmptyFakeWorkloadCache())
event := &v1.Event{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test-namespace",
},
Message: "Test message for events",
Message: "0/3 nodes are available: 3 Insufficient memory. preemption: 0/3 nodes\n are available: 3 No preemption victims found for incoming pod..",
EventTime: metav1.NewMicroTime(time.Now()),
InvolvedObject: v1.ObjectReference{
Namespace: "test-namespace",
Kind: "some-kind",
Name: "test-name",
},
Type: "Normal",
Reason: "some-reason",
Type: "Warning",
Reason: "FailedScheduling",
ReportingController: "default-scheduler",
}

er.addEvent(event, false)
require.True(t, !sink.Ts.IsZero())
require.Equal(t, "default-scheduler", sink.Annotations["component"])
})

t.Run("does not send add events for events that already existed prior to startup", func(t *testing.T) {
Expand Down
34 changes: 18 additions & 16 deletions collector/plugins/events/examples/failed_scheduling.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
apiVersion: v1
items:
- apiVersion: v1
count: 12
eventTime: null
firstTimestamp: "2023-11-06T21:35:02Z"
- action: Scheduling
apiVersion: v1
eventTime: "2023-12-04T21:41:46.328778Z"
firstTimestamp: null
involvedObject:
apiVersion: v1
kind: Pod
name: pod-cannot-be-scheduled
namespace: collector-targets
resourceVersion: "16226"
uid: 557e30eb-7a22-4386-a6da-5243424c49f4
resourceVersion: "27946519"
uid: 0571a69c-4259-4465-a649-baa3e12a88ee
kind: Event
lastTimestamp: "2023-11-06T21:42:03Z"
lastTimestamp: null
message: '0/3 nodes are available: 3 Insufficient memory. preemption: 0/3 nodes
are available: 3 No preemption victims found for incoming pod..'
metadata:
creationTimestamp: "2023-11-06T21:35:02Z"
name: pod-cannot-be-scheduled.17952642b64bb20b
creationTimestamp: "2023-12-04T21:41:46Z"
name: pod-cannot-be-scheduled.179dbee0a8bc5d36
namespace: collector-targets
resourceVersion: "865"
uid: ba7c9601-4316-4b05-b48a-40306f6a473f
resourceVersion: "51754"
uid: fb67fd57-3090-41e5-8e94-a623ccc7b07c
reason: FailedScheduling
reportingComponent: ""
reportingInstance: ""
source:
component: default-scheduler
type: Warning
reportingComponent: default-scheduler
reportingInstance: default-scheduler-gke-584afebdf6574fe9a52c-5a06-7f4f-vm
source: {}
type: Warning
kind: List
metadata:
resourceVersion: ""

0 comments on commit 7e49908

Please sign in to comment.