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

[receiver/k8scluster] Adding kubernetes labels as attributes to HorizontalPodAutoscaling metrics #35318

Open
povilasv opened this issue Sep 20, 2024 · 11 comments
Labels

Comments

@povilasv
Copy link
Contributor

Component(s)

receiver/k8scluster

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

I'm interested in adding Kubernetes labels as attributes to HorizontalPodAutoscaling metrics we have in k8scluster receiver:

Describe the solution you'd like

There is two ways we could achieve this:

  1. Enhance k8sattributes processor to look at hpa.UID and extract labels from that.

  2. Alternatively have some support of mapping labels to attributes, on each metric in k8sclusterreceiver 🤔 ?

metrics:
   k8s.hpa.desired_replicas
     enabled:
     labels:
       - attribute_name: team
          key: app.kubernetes.io/team

Any suggestions / ideas?

Describe alternatives you've considered

No response

Additional context

No response

@povilasv povilasv added enhancement New feature or request needs triage New item requiring triage labels Sep 20, 2024
@povilasv povilasv changed the title Adding kubernetes labels as attributes Adding kubernetes labels as attributes to metrics Sep 20, 2024
Copy link
Contributor

Pinging code owners for receiver/k8scluster: @dmitryax @TylerHelmuth @povilasv. See Adding Labels via Comments if you do not have permissions to add labels yourself.

@TylerHelmuth TylerHelmuth changed the title Adding kubernetes labels as attributes to metrics [receiver/k8scluster] Adding kubernetes labels as attributes to HorizontalPodAutoscaling metrics Sep 20, 2024
@TylerHelmuth
Copy link
Member

The k8scluster receiver doesn't have that metadata already right?

@povilasv
Copy link
Contributor Author

k8scluster receiver does have it:

We basically loop thru all HPAs:
https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/k8sclusterreceiver/internal/collection/collector.go#L101-L103

And just need to change this to map HPA label's to resource attributes:
https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/k8sclusterreceiver/internal/hpa/hpa.go#L19-L23

The more interesting thing, I would like to build something generic. I.e. you can do same thing for jobs, cronjobs, deployments...

Thoughts?

@dmitryax
Copy link
Member

Ideally, this should be sent with entities as non-identifying attributes via a side channel. I know that not every backend will be able to adopt entities, so we might need a solution like this, but I think we should first consider entities as a higher priority now. Later, we can probably have a generic solution to move entities to resource attributes for backends that don't support them, which can be implemented in a new processor later.

k8s cluster receiver already sends experimental entities. @povilasv have you looked into that? Does it work for your use case at this point?

@povilasv
Copy link
Contributor Author

Very good point, somehow didn't think of entities to be honest 🤔 And thinking more about it, strictly speaking k8s object labels don't fit OTEL resource attributes due to immutability.

I agree, sending via non-identifying attributes makes sense. I would maybe even include all K8s object labels / annotations into Entity by default. And then later we can think about some filtering mechanism 🤔

But I would also argue that this processor that adds entity attributes as attributes to the metrics might be also high priorty. It would work well with Prometheus / graphite and also give vendors time adopt Entities. What do you think @dmitryax / @TylerHelmuth ?

I'll also try to catchup on the Entties, and see what can I do to help 👍

@TylerHelmuth
Copy link
Member

@dmitryax are entities stable?

@dmitryax
Copy link
Member

dmitryax commented Oct 4, 2024

@dmitryax are entities stable?

It's far from being stable. But the active work is ongoing.

@dmitryax
Copy link
Member

dmitryax commented Oct 4, 2024

By the way, this receiver can currently send pod and namespace labels only as experimental entities encoded in logs. It doesn't seem right to make it different for HPAs. Even if we want to have a configuration option to set the k8s labels/annotations on the resource attribute, this has to apply to all k8s objects that we are sending metrics about.

@povilasv
Copy link
Contributor Author

povilasv commented Oct 7, 2024

. Even if we want to have a configuration option to set the k8s labels/annotations on the resource attribute, this has to apply to all k8s objects that we are sending metrics about.

I agree. My proposal was to basically for all k8s objects user could choose to add certain k8s labels to resource attributes.

But given k8s labels are not immutable, we would violate resource attribute immutability. So now I have doubts about this proposal 🤔 I guess k8s attributes processor violates resource attribute immutability too.

So maybe we don't fix the current issue - until we have Entities?

@TylerHelmuth
Copy link
Member

@dmitryax I feel like I need more info on how entities are recorded in OTLP. Will there be breaking changes if we continue to represent things as resource attributes are that entities? I don't want to block all k8s component work for entities unless there are going to be significant breaking changes.

@atoulme atoulme removed the needs triage New item requiring triage label Oct 12, 2024
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.

@github-actions github-actions bot added the Stale label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants