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

[k8sattributesprocessor] Support set resource attributes from environment variables of k8s pods #33700

Open
chenlujjj opened this issue Jun 21, 2024 · 4 comments
Labels
enhancement New feature or request processor/k8sattributes k8s Attributes processor

Comments

@chenlujjj
Copy link
Contributor

Component(s)

processor/k8sattributes

Is your feature request related to a problem? Please describe.

We are using the receiver creator with prometheus simple receiver as the receiver inside to automatically discover pods with prometheus.io/scrape: "true" annotations and collect metrics from them. The problem is that the service.name labels in the metrics are prometheus_simple/<ip:port>, but we want them be the real service name of the applications.

Describe the solution you'd like

Currently the k8sattributesprocessor can set resource attributes from k8s labels and annotations of pods, namespaces and nodes. If it can also extract pod environment variables, such as the OTEL_RESOURCE_ATTRIBUTES, OTEL_SERVICE_NAME, and set them as the resource attributes, that would help to solve the problem above.

Describe alternatives you've considered

No response

Additional context

No response

@chenlujjj chenlujjj added enhancement New feature or request needs triage New item requiring triage labels Jun 21, 2024
Copy link
Contributor

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@github-actions github-actions bot added the processor/k8sattributes k8s Attributes processor label Jun 21, 2024
@TylerHelmuth
Copy link
Member

Is prometheus_simple from prometheus_simple/<ip:port> the service name? If so, extracting the value from the resource attribute via the transformprocessor is a better way to go. https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/ottlfuncs#extractpatterns

@chenlujjj
Copy link
Contributor Author

chenlujjj commented Jun 22, 2024

Hi @TylerHelmuth , metrics service.name label is set as prometheus_simple/<ip:port> by the prometheus_simple receiver. The logic should be at this line of code.

So I came up with the idea to use k8sattributesprocessor to set the service.name from pod environment variable. Say if the pod has an environment variable OTEL_SERVICE_NAME=foo or OTEL_RESOURCE_ATTRIBUTES=service.name=foo, then the service.name label will be set as foo

Copy link
Contributor

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request processor/k8sattributes k8s Attributes processor
Projects
None yet
Development

No branches or pull requests

3 participants