Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7d04c7c
Add more types to severity map
gaddas3 Oct 9, 2025
53896bf
Reference to k8s event api
gaddas3 Oct 9, 2025
a9c8224
Merge branch 'open-telemetry:main' into k8seventsreceiver-update-seve…
gaddas3 Oct 10, 2025
01e2177
Merge branch 'open-telemetry:main' into k8seventsreceiver-update-seve…
gaddas3 Oct 10, 2025
a5471bb
Merge branch 'open-telemetry:main' into k8seventsreceiver-update-seve…
gaddas3 Oct 10, 2025
90fb6a6
keep the existing severity mapping logic
gaddas3 Oct 14, 2025
15cf372
keep the existing severity mapping logic
gaddas3 Oct 14, 2025
68ec4b1
update change log for receiver/k8seventsreceiver
gaddas3 Oct 14, 2025
9cb9cbb
Merge branch 'main' into k8seventsreceiver-update-severity-map
gaddas3 Oct 14, 2025
81fc37e
keep the existing severity mapping logic
gaddas3 Oct 14, 2025
b1cbcd4
Merge branch 'main' into k8seventsreceiver-update-severity-map
gaddas3 Oct 15, 2025
9219e58
update change log for receiver/k8seventsreceiver
gaddas3 Oct 14, 2025
ea8aa34
Merge branch 'main' into k8seventsreceiver-update-severity-map
gaddas3 Oct 16, 2025
df2b233
update change log
gaddas3 Oct 15, 2025
29d3680
Merge branch 'main' into k8seventsreceiver-update-severity-map
gaddas3 Oct 16, 2025
690ec12
Merge branch 'main' into k8seventsreceiver-update-severity-map
gaddas3 Oct 17, 2025
91738ff
unit tests for different event types
gaddas3 Oct 20, 2025
dfe79e8
Merge branch 'main' into k8seventsreceiver-update-severity-map
gaddas3 Oct 20, 2025
8385208
Merge branch 'main' into k8seventsreceiver-update-severity-map
gaddas3 Oct 20, 2025
059bcda
unit tests for different event types
gaddas3 Oct 20, 2025
85f8e1b
Merge branch 'main' into k8seventsreceiver-update-severity-map
gaddas3 Oct 20, 2025
087f33f
Merge branch 'main' into k8seventsreceiver-update-severity-map
gaddas3 Oct 21, 2025
b5c909e
Merge branch 'main' into k8seventsreceiver-update-severity-map
gaddas3 Oct 21, 2025
ab2e762
Merge branch 'main' into k8seventsreceiver-update-severity-map
gaddas3 Oct 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/k8seventsreceiver-update-severity-map.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'enhancement'

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: k8seventsreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Allow more event types like Error and Critical which are typically used by applications when creating events.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [43401]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: k8seventsreceiver allows event types Error and Critical in addition to the current Normal and Warning event types.

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
6 changes: 4 additions & 2 deletions receiver/k8seventsreceiver/k8s_event_to_logdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
totalResourceAttributes = 6
)

// Only two types of events are created as of now.
// For more info: https://docs.openshift.com/container-platform/4.9/rest_api/metadata_apis/event-core-v1.html
// By default k8s event has only two types of events (Normal, Warning), here are we allowing other types as well.
// For more info: https://github.com/kubernetes/api/blob/release-1.34/events/v1/types_swagger_doc_generated.go#L42
var severityMap = map[string]plog.SeverityNumber{
"normal": plog.SeverityNumberInfo,

Check failure on line 29 in receiver/k8seventsreceiver/k8s_event_to_logdata.go

View workflow job for this annotation

GitHub Actions / lint-matrix (windows, receiver-1)

File is not properly formatted (gci)

Check failure on line 29 in receiver/k8seventsreceiver/k8s_event_to_logdata.go

View workflow job for this annotation

GitHub Actions / lint-matrix (linux, receiver-1)

File is not properly formatted (gci)

Check failure on line 29 in receiver/k8seventsreceiver/k8s_event_to_logdata.go

View workflow job for this annotation

GitHub Actions / scoped-tests-matrix (ubuntu-latest)

File is not properly formatted (gci)
"warning": plog.SeverityNumberWarn,
"error": plog.SeverityNumberError,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason you're not just adding the new types here? I do agree that this implementation is preserving some more info but I'm not sure it s needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a bad use of words on my part. I meant just adding them there, without the rest of the logic (which is the state of the PR now)

"critical": plog.SeverityNumberFatal,
}

// k8sEventToLogRecord converts Kubernetes event to plog.LogRecordSlice and adds the resource attributes.
Expand Down
51 changes: 46 additions & 5 deletions receiver/k8seventsreceiver/k8s_event_to_logdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,50 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8seventsreceiver/internal/metadata"
)

func TestK8sEventToLogDataWithDifferentEventTypes(t *testing.T) {
tests := []struct {
name string
eventType string
expectedLog plog.SeverityNumber
}{
{
name: "Normal",
eventType: "Normal",
expectedLog: plog.SeverityNumberInfo,
},
{
name: "Warning",
eventType: "Warning",
expectedLog: plog.SeverityNumberWarn,
},
{
name: "Error",
eventType: "Error",
expectedLog: plog.SeverityNumberError,
},
{
name: "Critical",
eventType: "Critical",
expectedLog: plog.SeverityNumberFatal,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
k8sEvent := getEvent(test.eventType)

ld := k8sEventToLogData(zap.NewNop(), k8sEvent, "latest")
rl := ld.ResourceLogs().At(0)
lr := rl.ScopeLogs().At(0)
logRecord := lr.LogRecords().At(0)

assert.Equal(t, test.expectedLog, logRecord.SeverityNumber())
})
}
}

func TestK8sEventToLogData(t *testing.T) {
k8sEvent := getEvent()
k8sEvent := getEvent("Normal")

ld := k8sEventToLogData(zap.NewNop(), k8sEvent, "latest")
rl := ld.ResourceLogs().At(0)
Expand All @@ -32,7 +74,7 @@ func TestK8sEventToLogData(t *testing.T) {
}

func TestK8sEventToLogDataWithApiAndResourceVersion(t *testing.T) {
k8sEvent := getEvent()
k8sEvent := getEvent("Normal")

ld := k8sEventToLogData(zap.NewNop(), k8sEvent, "latest")
attrs := ld.ResourceLogs().At(0).Resource().Attributes()
Expand All @@ -54,8 +96,7 @@ func TestK8sEventToLogDataWithApiAndResourceVersion(t *testing.T) {
}

func TestUnknownSeverity(t *testing.T) {
k8sEvent := getEvent()
k8sEvent.Type = "Unknown"
k8sEvent := getEvent("Unknown")

ld := k8sEventToLogData(zap.NewNop(), k8sEvent, "latest")
rl := ld.ResourceLogs().At(0)
Expand All @@ -66,7 +107,7 @@ func TestUnknownSeverity(t *testing.T) {
}

func TestScopeNameAndVersion(t *testing.T) {
k8sEvent := getEvent()
k8sEvent := getEvent("Normal")

version := "latest"
ld := k8sEventToLogData(zap.NewNop(), k8sEvent, version)
Expand Down
16 changes: 8 additions & 8 deletions receiver/k8seventsreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestHandleEvent(t *testing.T) {
require.NotNil(t, r)
recv := r.(*k8seventsReceiver)
recv.ctx = t.Context()
k8sEvent := getEvent()
k8sEvent := getEvent("Normal")
recv.handleEvent(k8sEvent)

assert.Equal(t, 1, sink.LogRecordCount())
Expand All @@ -83,15 +83,15 @@ func TestDropEventsOlderThanStartupTime(t *testing.T) {
require.NotNil(t, r)
recv := r.(*k8seventsReceiver)
recv.ctx = t.Context()
k8sEvent := getEvent()
k8sEvent := getEvent("Normal")
k8sEvent.FirstTimestamp = v1.Time{Time: time.Now().Add(-time.Hour)}
recv.handleEvent(k8sEvent)

assert.Equal(t, 0, sink.LogRecordCount())
}

func TestGetEventTimestamp(t *testing.T) {
k8sEvent := getEvent()
k8sEvent := getEvent("Normal")
eventTimestamp := getEventTimestamp(k8sEvent)
assert.Equal(t, k8sEvent.FirstTimestamp.Time, eventTimestamp)

Expand All @@ -117,7 +117,7 @@ func TestAllowEvent(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, r)
recv := r.(*k8seventsReceiver)
k8sEvent := getEvent()
k8sEvent := getEvent("Normal")

shouldAllowEvent := recv.allowEvent(k8sEvent)
assert.True(t, shouldAllowEvent)
Expand Down Expand Up @@ -158,7 +158,7 @@ func TestReceiverWithLeaderElection(t *testing.T) {

// Become leader: start processing events
le.InvokeOnLeading()
recv.handleEvent(getEvent())
recv.handleEvent(getEvent("Normal"))

require.Eventually(t, func() bool {
return sink.LogRecordCount() == 1
Expand All @@ -174,14 +174,14 @@ func TestReceiverWithLeaderElection(t *testing.T) {

// regain leadership and inject again
le.InvokeOnLeading()
recv.handleEvent(getEvent())
recv.handleEvent(getEvent("Normal"))

require.Eventually(t, func() bool {
return sink.LogRecordCount() == 2
}, 5*time.Second, 100*time.Millisecond, "logs not collected after regaining leadership")
}

func getEvent() *corev1.Event {
func getEvent(eventType string) *corev1.Event {
return &corev1.Event{
InvolvedObject: corev1.ObjectReference{
APIVersion: "v1",
Expand All @@ -193,7 +193,7 @@ func getEvent() *corev1.Event {
Reason: "testing_event_1",
Count: 2,
FirstTimestamp: v1.Now(),
Type: "Normal",
Type: eventType,
Message: "testing event message",
ObjectMeta: v1.ObjectMeta{
UID: types.UID("289686f9-a5c0"),
Expand Down
Loading