Skip to content
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

[processor/k8sattributes] Add support for exposing k8s.pod.ip metadata #33440

Merged
merged 5 commits into from
Jun 19, 2024

Conversation

ChrsMark
Copy link
Member

@ChrsMark ChrsMark commented Jun 8, 2024

Description:

This PR adds support for exporting the k8s.pod.ip as part of the metadata added by the processor.

Link to tracking Issue: Fixes #32960

Testing: Added

Documentation:

Testing notes

See #33440 (comment)

@github-actions github-actions bot added the processor/k8sattributes k8s Attributes processor label Jun 8, 2024
@ChrsMark ChrsMark force-pushed the add_k8s_pod_ip branch 2 times, most recently from 01560be to 75922a8 Compare June 9, 2024 11:53
@ChrsMark
Copy link
Member Author

ChrsMark commented Jun 9, 2024

Testing this manually

  1. Using the following values file for the Helm chart:
mode: daemonset
presets:
  logsCollection:
    enabled: true
  kubernetesAttributes:
    enabled: true

image:
  repository: otelcontribcol-dev
  tag: "0.0.1"
  pullPolicy: IfNotPresent

command:
  name: otelcontribcol

config:
  exporters:
    debug:
      verbosity: detailed
  receivers:
    filelog:
      start_at: end
      include_file_name: false
      include_file_path: true
      exclude:
        - /var/log/pods/default_daemonset-opentelemetry-collector*_*/opentelemetry-collector/*.log
      include:
        - /var/log/pods/*/*/*.log
      operators:
        - id: container-parser
          type: container
          output: some
        - id: some
          type: add
          field: attributes.key2.key_in
          value: val2
  processors:
    k8sattributes:
      filter:
        node_from_env_var: K8S_NODE_NAME
      passthrough: false
      pod_association:
        - sources:
            - from: resource_attribute
              name: k8s.pod.ip
        - sources:
            - from: resource_attribute
              name: k8s.pod.uid
        - sources:
            - from: connection
      extract:
        metadata:
          - "k8s.namespace.name"
          - "k8s.deployment.name"
          - "k8s.statefulset.name"
          - "k8s.daemonset.name"
          - "k8s.cronjob.name"
          - "k8s.job.name"
          - "k8s.node.name"
          - "k8s.pod.name"
          - "k8s.pod.uid"
          - "k8s.pod.ip"
          - "k8s.pod.start_time"

  service:
    pipelines:
      logs:
        receivers: [filelog]
        processors: [batch]
        exporters: [debug]
  1. Verify that the produced log records report the Pod's IP:
2024-06-08T17:19:10.102Z	info	ResourceLog #0
Resource SchemaURL: 
Resource attributes:
     -> k8s.container.name: Str(busybox)
     -> k8s.namespace.name: Str(default)
     -> k8s.pod.name: Str(daemonset-logs-ndfz9)
     -> k8s.container.restart_count: Str(0)
     -> k8s.pod.uid: Str(6e35d5db-ed8c-4c27-96ba-5d525a216616)
     -> k8s.pod.ip: Str(10.244.2.5)
     -> k8s.pod.start_time: Str(2024-06-08T17:19:02Z)
     -> k8s.daemonset.name: Str(daemonset-logs)
     -> k8s.node.name: Str(kind-worker3)
ScopeLogs #0
ScopeLogs SchemaURL: 
InstrumentationScope  
LogRecord #0
ObservedTimestamp: 2024-06-08 17:19:09.868870532 +0000 UTC
Timestamp: 2024-06-08 17:19:09.719245859 +0000 UTC
SeverityText: 
SeverityNumber: Unspecified(0)
Body: Str(otel logs at 17:19:09)
Attributes:
     -> log.file.path: Str(/var/log/pods/default_daemonset-logs-ndfz9_6e35d5db-ed8c-4c27-96ba-5d525a216616/busybox/0.log)
     -> time: Str(2024-06-08T17:19:09.719245859Z)
     -> log.iostream: Str(stdout)
     -> logtag: Str(F)
     -> key2: Map({"key_in":"val2"})
Trace ID: 
Span ID: 
Flags: 0
LogRecord #1
ObservedTimestamp: 2024-06-08 17:19:09.868930219 +0000 UTC
Timestamp: 2024-06-08 17:19:09.821239181 +0000 UTC
SeverityText: 
SeverityNumber: Unspecified(0)
Body: Str(otel logs at 17:19:09)
Attributes:
     -> log.file.path: Str(/var/log/pods/default_daemonset-logs-ndfz9_6e35d5db-ed8c-4c27-96ba-5d525a216616/busybox/0.log)
     -> time: Str(2024-06-08T17:19:09.821239181Z)
     -> log.iostream: Str(stdout)
     -> logtag: Str(F)
     -> key2: Map({"key_in":"val2"})
Trace ID: 
Span ID: 
Flags: 0
	{"kind": "exporter", "data_type": "logs", "name": "debug"}

@ChrsMark ChrsMark marked this pull request as ready for review June 9, 2024 12:08
@ChrsMark ChrsMark requested a review from a team June 9, 2024 12:08
Copy link
Contributor

@fatsheep9146 fatsheep9146 left a comment

Choose a reason for hiding this comment

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

Could you add a e2e test in e2e_test.go to cover the case that, if we don not enable "k8s.pod.ip" in k8sattributes:extract:metadata, then the emitted logs/traces/metrics will not include "k8s.pod.ip" metadata?

@ChrsMark
Copy link
Member Author

Thank's @fatsheep9146, I have added this at e47f401.

.chloggen/add_k8s_pod_ip.yaml Outdated Show resolved Hide resolved
processor/k8sattributesprocessor/metadata.yaml Outdated Show resolved Hide resolved
processor/k8sattributesprocessor/options.go Outdated Show resolved Hide resolved
Copy link
Member

@crobert-1 crobert-1 left a comment

Choose a reason for hiding this comment

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

I'm not very familiar with this component, but the general logic looks good to me. 👍

.chloggen/add_k8s_pod_ip.yaml Outdated Show resolved Hide resolved
Copy link
Member

@TylerHelmuth TylerHelmuth left a comment

Choose a reason for hiding this comment

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

Since the processor uses k8s.pod.ip already I'm ok with merging this, but I did notice that k8s.pod.ip is not defined in https://github.com/open-telemetry/semantic-conventions/blob/main/docs/resource/k8s.md. @ChrsMark can you take up proposing that attribute?

@ChrsMark
Copy link
Member Author

Sure @TylerHelmuth , I filed open-telemetry/semantic-conventions#1160 for this.

@TylerHelmuth TylerHelmuth added the ready to merge Code review completed; ready to merge by maintainers label Jun 18, 2024
Copy link
Contributor

@fatsheep9146 fatsheep9146 left a comment

Choose a reason for hiding this comment

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

/home/runner/work/opentelemetry-collector-contrib/opentelemetry-collector-contrib/.tools/goimports -w  -local github.com/open-telemetry/opentelemetry-collector-contrib ./
make[2]: Leaving directory '/home/runner/work/opentelemetry-collector-contrib/opentelemetry-collector-contrib'
make[1]: Leaving directory '/home/runner/work/opentelemetry-collector-contrib/opentelemetry-collector-contrib'
Generated code is out of date, please run "make generate" and commit the changes in this PR.

Is this failed check should be fixed?

Signed-off-by: ChrsMark <[email protected]>
@ChrsMark
Copy link
Member Author

Is this failed check should be fixed?

Needed to run make generate again after rebasing. Thank's.

@codeboten codeboten merged commit 97f46cc into open-telemetry:main Jun 19, 2024
154 checks passed
@github-actions github-actions bot added this to the next release milestone Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
processor/k8sattributes k8s Attributes processor ready to merge Code review completed; ready to merge by maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need extract k8s.pod.ip using k8sattributes processor
6 participants