Skip to content

[receiver/k8seventsreceiver] add extraction rules for labels and annotations #39495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

gmlexx
Copy link

@gmlexx gmlexx commented Apr 18, 2025

Inspired by k8sattributesprocessor introduce the similar configuration syntax to support labels and annotations extraction from event

Testing

  • Unit tests for configuration, event processing and rules
  • Manual docker image testing on kind cluster

Documentation

  • Updated k8seventsreceiver README with configuration examples

@gmlexx gmlexx requested review from dmitryax, TylerHelmuth, ChrsMark and a team as code owners April 18, 2025 14:03
Copy link

linux-foundation-easycla bot commented Apr 18, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: gmlexx / name: Aleksei Larkov (af46ffd)

@gmlexx gmlexx changed the title [receiver/k8seventsreceiver] add extraction rules for labels and anno… [receiver/k8seventsreceiver] add extraction rules for labels and annotations Apr 18, 2025
@gmlexx gmlexx force-pushed the k8s-events-receiver-extraction-rules branch from e002bf3 to 4e7c2dd Compare April 18, 2025 14:14
@gmlexx gmlexx force-pushed the k8s-events-receiver-extraction-rules branch 3 times, most recently from 93020e1 to 13f0d6f Compare April 21, 2025 12:20
for _, opt := range allOptions {
if err := opt(kr); err != nil {
kr.settings.Logger.Error("Could not apply option", zap.Error(err))
componentstatus.ReportStatus(host, componentstatus.NewFatalErrorEvent(err))
Copy link
Member

Choose a reason for hiding this comment

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

Should this be a fatal error?

Copy link
Author

Choose a reason for hiding this comment

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

I believe that yes, as the incorrect configuration shouldn't be executed as it's hard to catch later just from logs error reporting, better to fail immediately

extract:
annotations: # same can be applied for labels
- tag_name: a1 # extracts value of annotation from event with key `annotation-one` and inserts it as a tag with key `a1`
key: annotation-one
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a sample produced log as an example here? My concern is mostly about how these will be represented and under which fields of the Log 🤔 .

Copy link
Author

Choose a reason for hiding this comment

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

THB, I don't know how as there is no produced log example exist for this receiver to add new attributes to this set.
Is there a good example to follow?

@@ -149,6 +151,8 @@ func getEvent() *corev1.Event {
Name: "1",
Namespace: "test",
CreationTimestamp: v1.Now(),
Labels: make(map[string]string),
Copy link
Member

Choose a reason for hiding this comment

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

Shall we add some tests that will also illustrate what type of data this feature produces?

Copy link
Author

Choose a reason for hiding this comment

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

Sure, added TestEventLabelsAndAnnotationsExtractionOptions test

lr := rl.ScopeLogs().At(0)
attrs := lr.LogRecords().At(0).Attributes()

attr, ok := attrs.Get("k8s.event.labels.testlabel")
Copy link
Member

Choose a reason for hiding this comment

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

We will need to discuss and decide if k8s.event.label/annotation is the proper place for this. If so, I guess we would need to define those as Semantic Conventions.

/cc @TylerHelmuth @dmitryax

Copy link
Member

Choose a reason for hiding this comment

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

We were planning to deprecate this receiver in favor of the k8sobjectsreceiver (#24242). If the semconv is willing to define semantic conventions for k8s events we could consider reversing that decision, but my understanding if that we are no longer in the business of defining semconv for log attributes and are instead supposed to follow Otel's Event spec.

Copy link
Member

Choose a reason for hiding this comment

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

I think focusing on #24242 first would be ideal. It would not worth it adding stuff for k8sevents receiver if it's to get deprecated.

…tations

Inspired by k8sattributesprocessor introduces the similar configuration
syntax to support labels and annotations extraction from event
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

Copy link
Contributor

Closed as inactive. Feel free to reopen if this PR is still being worked on.

@github-actions github-actions bot closed this May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants