Skip to content

[receivercreator/discovery] Add support for default annotation-equivalent config in receivercreator #40195

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

ChrsMark
Copy link
Member

@ChrsMark ChrsMark commented May 21, 2025

Description

This PR adds support for defining default annotation-equivalent configuration. This can be useful when a default behaviour is required for all discovered Pods/containers without having to explicitly annotate all Pods.

Example: Enable log collection for all discovered Pods/containers unless they are explicitly annotated with io.opentelemetry.discovery.logs/enabled: "false". (to avoid collecting Collector's own logs make sure that Collector Pods are properly annotated with io.opentelemetry.discovery.logs/enabled: "false")

Link to tracking issue

Fixes #37436

Testing

Added

Documentation

Added

How to test this manually

  1. Deploy Collector helm chart:
mode: daemonset

podAnnotations:
  io.opentelemetry.discovery.logs/enabled: "false"

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

clusterRole:
  create: true
  rules:
    - apiGroups:
        - ''
      resources:
        - 'pods'
        - 'nodes'
      verbs:
        - 'get'
        - 'list'
        - 'watch'
    - apiGroups: [ "" ]
      resources: [ "nodes/proxy"]
      verbs: [ "get" ]
    - apiGroups:
        - ""
      resources:
        - nodes/stats
      verbs:
        - get
    - nonResourceURLs:
        - "/metrics"
      verbs:
        - get

extraVolumeMounts:
  - name: varlogpods
    mountPath: /var/log/pods
    readOnly: true

extraVolumes:
  - name: varlogpods
    hostPath:
      path: /var/log/pods

config:
  extensions:
    k8s_observer:
      auth_type: serviceAccount
      node: ${env:K8S_NODE_NAME}
    health_check:
      endpoint: ${env:MY_POD_IP}:13133
  exporters:
    debug/2:
      verbosity: basic
    debug:
      verbosity: detailed

  receivers:

    receiver_creator/logs:
      watch_observers: [k8s_observer]
      discovery:
        enabled: true
        default_annotations:
          io.opentelemetry.discovery.logs/enabled: "true"
      receivers:


  service:
    extensions: [health_check, k8s_observer]
    telemetry:
      logs:
        level: INFO
    pipelines:
      logs/discovery:
        receivers: [ receiver_creator/logs ]
        #processors: [ batch ]
        exporters: [ debug ]
  1. Deploy a target Pod and ensure that logs are collected by default:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: busybox-deployment
  labels:
    app: busybox
spec:
  replicas: 1
  selector:
    matchLabels:
      app: busybox
  template:
    metadata:
      labels:
        app: busybox
      annotations:
        some: foo
    spec:
      containers:
        - name: busybox
          image: busybox
          args:
            - /bin/sh
            - -c
            - while true; do echo "otel logs at $(date +%H:%M:%S)" && sleep 2s; done
  1. After ensuring that logs are collected by default annotate the Pod properly to ensure that log collection is explicitly disabled: kubectl annotate pod busybox-deployment-77b9b7cfbd-5lfmh io.opentelemetry.discovery.logs/enabled="false"

@ChrsMark ChrsMark requested review from dmitryax and a team as code owners May 21, 2025 09:09
@ChrsMark ChrsMark force-pushed the add_support_for_default_log_collection_receivercreator branch from 6e57b74 to 7b31072 Compare May 21, 2025 09:13
@ChrsMark ChrsMark changed the title [receivercreator/discovery] Add support for default log collection receivercreator [receivercreator/discovery] Add support for default log collection in receivercreator May 21, 2025
@ChrsMark ChrsMark force-pushed the add_support_for_default_log_collection_receivercreator branch from 7b31072 to 7ff5fd3 Compare May 21, 2025 11:18
@ChrsMark ChrsMark force-pushed the add_support_for_default_log_collection_receivercreator branch from dca96c0 to f9fa364 Compare May 21, 2025 12:36
@ChrsMark ChrsMark changed the title [receivercreator/discovery] Add support for default log collection in receivercreator [receivercreator/discovery] Add support for default annotation-equivalent config in receivercreator May 21, 2025
@ChrsMark
Copy link
Member Author

@dmitryax please take a look when you get the chance.

@ChrsMark ChrsMark force-pushed the add_support_for_default_log_collection_receivercreator branch from f9fa364 to 6aac5a4 Compare May 21, 2025 13:15
Copy link
Member

@dmitryax dmitryax left a comment

Choose a reason for hiding this comment

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

LGTM. The comment isn't blocking 👍

IgnoreReceivers []string `mapstructure:"ignore_receivers"`
Enabled bool `mapstructure:"enabled"`
IgnoreReceivers []string `mapstructure:"ignore_receivers"`
DefaultAnnotations map[string]string `mapstructure:"default_annotations"`
Copy link
Member

Choose a reason for hiding this comment

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

I like how simple the interface is 👍

@ChrsMark ChrsMark added the ready to merge Code review completed; ready to merge by maintainers label May 27, 2025
#
# Example: Enable log collection for all discovered Pods/containers unless they are explicitly
# annotated with `io.opentelemetry.discovery.logs/enabled: "false"`.
# (to avoid collecting Collector's own logs make sure that Collector Pods are properly annotated
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for mentioning this in the documentation 👍

@andrzej-stencel andrzej-stencel merged commit f41bbf0 into open-telemetry:main May 27, 2025
175 checks passed
@github-actions github-actions bot added this to the next release milestone May 27, 2025
dd-jasminesun pushed a commit to DataDog/opentelemetry-collector-contrib that referenced this pull request Jun 23, 2025
…lent config in receivercreator (open-telemetry#40195)

#### Description

This PR adds support for defining default annotation-equivalent
configuration. This can be useful when a default behaviour is required
for all discovered Pods/containers without having to explicitly annotate
all Pods.

Example: Enable log collection for all discovered Pods/containers unless
they are explicitly annotated with
`io.opentelemetry.discovery.logs/enabled: "false"`. (to avoid collecting
Collector's own logs make sure that Collector Pods are properly
annotated with `io.opentelemetry.discovery.logs/enabled: "false"`)

<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes
open-telemetry#37436

<!--Describe what testing was performed and which tests were added.-->
#### Testing
Added

<!--Describe the documentation added.-->
#### Documentation
Added
<!--Please delete paragraphs that you did not use before submitting.-->

#### How to test this manually

1. Deploy Collector helm chart:
```yaml
mode: daemonset

podAnnotations:
  io.opentelemetry.discovery.logs/enabled: "false"

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

clusterRole:
  create: true
  rules:
    - apiGroups:
        - ''
      resources:
        - 'pods'
        - 'nodes'
      verbs:
        - 'get'
        - 'list'
        - 'watch'
    - apiGroups: [ "" ]
      resources: [ "nodes/proxy"]
      verbs: [ "get" ]
    - apiGroups:
        - ""
      resources:
        - nodes/stats
      verbs:
        - get
    - nonResourceURLs:
        - "/metrics"
      verbs:
        - get

extraVolumeMounts:
  - name: varlogpods
    mountPath: /var/log/pods
    readOnly: true

extraVolumes:
  - name: varlogpods
    hostPath:
      path: /var/log/pods

config:
  extensions:
    k8s_observer:
      auth_type: serviceAccount
      node: ${env:K8S_NODE_NAME}
    health_check:
      endpoint: ${env:MY_POD_IP}:13133
  exporters:
    debug/2:
      verbosity: basic
    debug:
      verbosity: detailed

  receivers:

    receiver_creator/logs:
      watch_observers: [k8s_observer]
      discovery:
        enabled: true
        default_annotations:
          io.opentelemetry.discovery.logs/enabled: "true"
      receivers:


  service:
    extensions: [health_check, k8s_observer]
    telemetry:
      logs:
        level: INFO
    pipelines:
      logs/discovery:
        receivers: [ receiver_creator/logs ]
        #processors: [ batch ]
        exporters: [ debug ]
```
2. Deploy a target Pod and ensure that logs are collected by default:
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: busybox-deployment
  labels:
    app: busybox
spec:
  replicas: 1
  selector:
    matchLabels:
      app: busybox
  template:
    metadata:
      labels:
        app: busybox
      annotations:
        some: foo
    spec:
      containers:
        - name: busybox
          image: busybox
          args:
            - /bin/sh
            - -c
            - while true; do echo "otel logs at $(date +%H:%M:%S)" && sleep 2s; done
```
3. After ensuring that logs are collected by default annotate the Pod
properly to ensure that log collection is explicitly disabled: `kubectl
annotate pod busybox-deployment-77b9b7cfbd-5lfmh
io.opentelemetry.discovery.logs/enabled="false"`

---------

Signed-off-by: ChrsMark <[email protected]>
Co-authored-by: Dmitry Anoshin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge Code review completed; ready to merge by maintainers receiver/receivercreator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide support for default log collection in receivercreator's discovery
4 participants