[receiver/receiver_creator] Add support for metrics' hints #35617
+599
−71
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR implements the metrics' part suggested at #34427 (comment). The current implementation only supports hints coming from Pods.
Users can use the following annotations to automatically enable receivers to start collecting metrics from the target Pods/containers.
Supported metrics annotations
io.opentelemetry.collector.receiver-creator.metrics/receiver
(example:nginx
)io.opentelemetry.collector.receiver-creator.metrics/endpoint
(example:"http://`endpoint`/nginx_status"
, if not provided it defaults toendpoint
which is of formpod_ip:container_port
.)io.opentelemetry.collector.receiver-creator.metrics/collection_interval
(example:20s
)io.opentelemetry.collector.receiver-creator.metrics/timeout
(example:1m
)io.opentelemetry.collector.receiver-creator.metrics/username
(example:admin
)io.opentelemetry.collector.receiver-creator.metrics/password
(example:passpass
)Support multiple target containers
Users can target the annotation to a specific container by suffixing it with the name of the port that container exposes, for example
io.opentelemetry.collector.receiver-creator.metrics.webserver/endpoint: "http://`endpoint`/nginx_status"
wherewebserver
is the name of the port the target container exposes.If a Pod is annotated with both container level hints and pod level hints the container level hints have priority and the Pod level hints are used as a fallback (see detailed example bellow).
The current implementation relies on the implementation of
k8sobserver
extension and specifically the pod_endpoint. The hints are evaluated per container by extracting the annotations from eachPort
endpoint that is emitted.TODOs:
Link to tracking issue
Part of #34427
Testing
Added unit-tests.
Documentation
Added
How to test this locally