Skip to content

Commit f49b038

Browse files
committed
Include Normal Evicted events
Add metrics
1 parent be25f8b commit f49b038

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

docs/ADVANCED_FILTERING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ When advanced filtering is enabled, the following rules are applied:
2121

2222
### Event Resources (api/v1/Event and events.k8s.io/v1/Event)
2323

24-
- **Sent**: Only Warning events that are Created
24+
- **Sent**:
25+
- Warning events that are Created
26+
- Any event with Reason "Evicted" (regardless of Type - Normal or Warning)
2527
- **Filtered**:
26-
- Normal events (regardless of operation)
28+
- Normal events (unless Reason is "Evicted")
2729
- Warning events with Update or Delete operations
2830

2931
### Job Resources

pkg/filter/filter.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,25 @@ func (f *Filter) shouldSendEventResource(e event.Event) bool {
8787
return false
8888
}
8989

90+
// Check the event reason - always send Evicted events regardless of type
91+
isEvictedEvent := false
92+
switch obj := e.Obj.(type) {
93+
case *api_v1.Event:
94+
if obj.Reason == "Evicted" {
95+
isEvictedEvent = true
96+
logrus.Debugf("Event resource with reason 'Evicted' will be sent regardless of type")
97+
}
98+
case *events_v1.Event:
99+
if obj.Reason == "Evicted" {
100+
isEvictedEvent = true
101+
logrus.Debugf("Event resource with reason 'Evicted' will be sent regardless of type")
102+
}
103+
}
104+
105+
if isEvictedEvent {
106+
return true
107+
}
108+
90109
// Check if it's a warning event
91110
switch obj := e.Obj.(type) {
92111
case *api_v1.Event:

pkg/filter/filter_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,30 @@ func TestShouldSendEventResource(t *testing.T) {
116116
},
117117
expected: true,
118118
},
119+
{
120+
name: "Evicted Event Normal Type - Should Send",
121+
event: event.Event{
122+
Kind: "Event",
123+
Reason: "Created",
124+
Obj: &api_v1.Event{
125+
Type: api_v1.EventTypeNormal,
126+
Reason: "Evicted",
127+
},
128+
},
129+
expected: true,
130+
},
131+
{
132+
name: "Evicted EventsV1 Normal Type - Should Send",
133+
event: event.Event{
134+
Kind: "Event",
135+
Reason: "Created",
136+
Obj: &events_v1.Event{
137+
Type: api_v1.EventTypeNormal,
138+
Reason: "Evicted",
139+
},
140+
},
141+
expected: true,
142+
},
119143
}
120144

121145
for _, tt := range tests {

pkg/handlers/cloudevent/cloudevent.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/bitnami-labs/kubewatch/config"
3030
"github.com/bitnami-labs/kubewatch/pkg/event"
3131
"github.com/bitnami-labs/kubewatch/pkg/filter"
32+
"github.com/bitnami-labs/kubewatch/pkg/metrics"
3233
"k8s.io/apimachinery/pkg/runtime"
3334
)
3435

@@ -99,6 +100,22 @@ func (m *CloudEvent) Handle(e event.Event) {
99100
return
100101
}
101102

103+
// Increment the sent metrics counter
104+
// Map event.Reason to eventType for consistency with the total metrics
105+
eventType := "unknown"
106+
switch e.Reason {
107+
case "Created":
108+
eventType = "create"
109+
case "Updated":
110+
eventType = "update"
111+
case "Deleted":
112+
eventType = "delete"
113+
}
114+
115+
if metrics.EventsSentTotal != nil {
116+
metrics.EventsSentTotal.WithLabelValues(e.Kind, eventType).Inc()
117+
}
118+
102119
m.Counter++ // TODO: do we have to worry about threadsafety here?
103120
message := m.prepareMessage(e)
104121

0 commit comments

Comments
 (0)