From 9a21436fe382a7fd9c27b83bcbac402d9cc34605 Mon Sep 17 00:00:00 2001 From: ChrsMark Date: Wed, 27 Nov 2024 13:55:54 +0200 Subject: [PATCH] [receiver/receiver_creator] Add support for logs' hints Signed-off-by: ChrsMark --- .chloggen/f_hints_logs.yaml | 27 ++ receiver/receivercreator/README.md | 103 ++++++- receiver/receivercreator/config_test.go | 37 +++ receiver/receivercreator/discovery.go | 103 ++++++- receiver/receivercreator/discovery_test.go | 285 +++++++++++++++++- receiver/receivercreator/fixtures_test.go | 29 ++ receiver/receivercreator/observerhandler.go | 17 +- .../receivercreator/observerhandler_test.go | 70 +++++ 8 files changed, 656 insertions(+), 15 deletions(-) create mode 100644 .chloggen/f_hints_logs.yaml diff --git a/.chloggen/f_hints_logs.yaml b/.chloggen/f_hints_logs.yaml new file mode 100644 index 000000000000..9e4b274aefbf --- /dev/null +++ b/.chloggen/f_hints_logs.yaml @@ -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: receivercreator + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add support for starting logs' collection based on provided k8s annotations' hints + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [34427] + +# (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: + +# 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] diff --git a/receiver/receivercreator/README.md b/receiver/receivercreator/README.md index ac836eb98e02..c3590d2340de 100644 --- a/receiver/receivercreator/README.md +++ b/receiver/receivercreator/README.md @@ -458,7 +458,8 @@ receiver_creator/metrics: # ignore_receivers: [] ``` -Find bellow the supported annotations that user can define to automatically enable receivers to start collecting metrics signals from the target Pods/containers. +Find bellow the supported annotations that user can define to automatically enable receivers to start +collecting metrics signals from the target Pods/containers. ### Supported metrics annotations @@ -511,11 +512,82 @@ The current implementation relies on the implementation of `k8sobserver` extensi the [pod_endpoint](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/v0.111.0/extension/observer/k8sobserver/pod_endpoint.go). The hints are evaluated per container by extracting the annotations from each [`Port` endpoint](#Port) that is emitted. +### Supported logs annotations + +This feature enables `filelog` receiver along with the `container` parser in order to collect logs from the discovered +Pods. + +#### Enable/disable discovery + +`io.opentelemetry.discovery.logs/enabled` (Required. Example: `"true"`) + +By default `"false"`. + +The following configuration can be used: + +```yaml +receiver_creator/logs: + watch_observers: [ k8s_observer ] + discovery: + enabled: true +``` +#### Define configuration +The default configuration for the `filelog` receiver is the following: + +```yaml +include: + - /var/log/pods/`pod.namespace`_`pod.name`_`pod.uid`/`container_name`/*.log +include_file_name: false +include_file_path: true +operators: + - id: container-parser + type: container +``` +This default can be extended using the respective annotation: +`io.opentelemetry.discovery.logs/config` + +**Example:** + +```yaml +io.opentelemetry.discovery.logs/config: | + include_file_name: true + max_log_size: "2MiB" + operators: + - type: regex_parser + regex: "^(?P