Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[receiver/receiver_creator] Add support for enabling logs' collecting…
… from K8s hints (#36581) #### Description This PR adds the logs part for #34427 based on the design decided at #34427 (comment). See the README docs for the description of this feature: https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/35617/files#diff-4127365c4062a7510fb7fede0fa239e9232549732898303d94c12fef0433d39d #### Link to tracking issue Fixes #34427 #### Testing Added unit-tests #### Documentation Added README section #### How to test this manually 1. Deploy the Collector helm chart: ```yaml mode: daemonset image: repository: otelcontribcol-dev tag: "latest" pullPolicy: IfNotPresent command: name: otelcontribcol 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} observe_nodes: true exporters: debug: verbosity: detailed receivers: receiver_creator/metrics: watch_observers: [ k8s_observer ] discovery: enabled: true ignore_receivers: - nginx2 receivers: receiver_creator/logs: watch_observers: [ k8s_observer ] discovery: enabled: true default_logs_discovery: false receivers: service: extensions: [health_check, k8s_observer] telemetry: logs: level: INFO pipelines: metrics: receivers: [ receiver_creator/metrics ] processors: [ batch ] exporters: [ debug ] logs/discovery: receivers: [ receiver_creator/logs ] #processors: [ batch ] exporters: [ debug ] ``` 2. Then deploy a target Pod with 2 containers: ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: redis-deployment labels: app: redis spec: replicas: 1 selector: matchLabels: app: redis template: metadata: labels: app: redis annotations: io.opentelemetry.discovery.metrics.6379/enabled: "true" io.opentelemetry.discovery.metrics.6379/scraper: redis io.opentelemetry.discovery.metrics.6379/signals: metrics io.opentelemetry.discovery.metrics.6379/config: | collection_interval: "20s" timeout: "10s" io.opentelemetry.discovery.logs.busybox/enabled: "true" io.opentelemetry.discovery.logs.busybox/config: | operators: - id: some type: add field: attributes.tag value: hints spec: containers: - image: redis imagePullPolicy: IfNotPresent name: redis ports: - name: redis containerPort: 6379 protocol: TCP - name: busybox image: busybox args: - /bin/sh - -c - while true; do echo "otel logs at $(date +%H:%M:%S)" && sleep 15s; done ``` 3. Esnure that logs are collected from both containers and that Redis metrics are collected from the Redis container: ```console 2024-11-28T11:04:14.921Z info receivercreator@v0.114.0/observerhandler.go:201 starting receiver {"kind": "receiver", "name": "receiver_creator/metrics", "data_type": "metrics", "name": "redis/91ec7d5c-c6fb-4977-9dbb-c24a85101326_6379", "endpoint": "10.244.0.6:6379", "endpoint_id": "k8s_observer/91ec7d5c-c6fb-4977-9dbb-c24a85101326/redis(6379)", "config": {"collection_interval":"20s","endpoint":"10.244.0.6:6379","timeout":"10s"}} 2024-11-28T11:04:14.921Z info receivercreator@v0.114.0/observerhandler.go:201 starting receiver {"kind": "receiver", "name": "receiver_creator/logs", "data_type": "logs", "name": "filelog/91ec7d5c-c6fb-4977-9dbb-c24a85101326_busybox", "endpoint": "10.244.0.6", "endpoint_id": "k8s_observer/91ec7d5c-c6fb-4977-9dbb-c24a85101326/busybox", "config": {"include":["/var/log/pods/default_redis-deployment-7777bf7db4-5rm6d_91ec7d5c-c6fb-4977-9dbb-c24a85101326/busybox/*.log"],"include_file_name":false,"include_file_path":true,"operators":[{"id":"container-parser","type":"container"},{"field":"attributes.tag","id":"some","type":"add","value":"hints"}]}} 2024-11-28T11:04:14.922Z info adapter/receiver.go:41 Starting stanza receiver {"kind": "receiver", "name": "receiver_creator/logs", "data_type": "logs", "name": "filelog/91ec7d5c-c6fb-4977-9dbb-c24a85101326_busybox/receiver_creator/logs{endpoint=\"10.244.0.6\"}/k8s_observer/91ec7d5c-c6fb-4977-9dbb-c24a85101326/busybox"} 2024-11-28T11:04:15.122Z info fileconsumer/file.go:265 Started watching file {"kind": "receiver", "name": "receiver_creator/logs", "data_type": "logs", "name": "filelog/91ec7d5c-c6fb-4977-9dbb-c24a85101326_busybox/receiver_creator/logs{endpoint=\"10.244.0.6\"}/k8s_observer/91ec7d5c-c6fb-4977-9dbb-c24a85101326/busybox", "component": "fileconsumer", "path": "/var/log/pods/default_redis-deployment-7777bf7db4-5rm6d_91ec7d5c-c6fb-4977-9dbb-c24a85101326/busybox/0.log"} 2024-11-28T11:04:15.979Z info Metrics {"kind": "exporter", "data_type": "metrics", "name": "debug/2", "resource metrics": 1, "metrics": 26, "data points": 31} ``` ### Follow-ups 1. File an issue for enhancing default behaviors: #36581 (comment) --------- Signed-off-by: ChrsMark <chrismarkou92@gmail.com>
- Loading branch information