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 · 9 comments
Labels
enhancement New feature or request needs triage New item requiring triage receiver/k8scluster

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs triage New item requiring triage receiver/k8scluster
Projects
None yet
Development

No branches or pull requests

4 participants