-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[processor/k8sattributes] Automatic resource attributes #37114
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
[processor/k8sattributes] Automatic resource attributes #37114
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a changelog and also updating the document to describe how to use this feature?
@fatsheep9146 added changelog and docs I also tried adding e2e tests - but didn't get it to work. Please advise if/how to do this. |
@TylerHelmuth @ChrsMark can you take a look? |
# app.kubernetes.io/version => service.version | ||
# app.kubernetes.io/part-of => service.namespace | ||
# This setting is ignored if 'enabled' is set to false | ||
labels: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use like resource_labels_enabled
instead of labels
? I think labels are easy to be confused with other field also called labels, but they are of slice type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here's the config format I have in mind:
automatic_attributes:
# Apply the operator rules - see https://github.com/open-telemetry/semantic-conventions/blob/main/docs/non-normative/k8s-attributes.md
well_known_labels: true # default is false
annotation_prefixes: ["foo/"] # default is ["resource.opentelemetry.io/"] - use empty list to disable
exclude: ["service.version"] # default is empty list
- the feature to add the attributes is added when the
automatic_attributes:
key is added (even when it has no content
- this is similar to how you can add
http:
otlp receiver - it would require that the existence of the key can be checked as in https://github.com/open-telemetry/opentelemetry-collector/blob/96e860b9cbd815788142918801950d5fc93bcb0d/receiver/otlpreceiver/config.go#L71 or https://github.com/open-telemetry/opentelemetry-collector/blob/13470870dbb6b4c52f853c72c9dd8393d1286a08/otelcol/config.go#L23 - not sure if that's possible here
- allow the customization of annotation prefix
- allow to exclude attributes
@ChrsMark @fatsheep9146 wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with the key automatic_attributes
and well_known_labels
I wonder that why we need annotation_prefixes
, you mentioned that you want to implement the same logic with The OTel operator, but I don't see the otel operator can support user-defined annotation prefix. (Maybe I missed it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: The first split-off PR is #38825
annotation_prefixes
is not part of the operator- I thought that some more flexibility is in the spirit of the collector - but no strong opinion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the #38825 adds the otel_annotations
setting which will handle the "resource.opentelemetry.io/foo" becomes "foo"
part. Do we we have consensus on the rest of the settings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so - since it's defined in the otel semantic conventions: https://opentelemetry.io/docs/specs/semconv/non-normative/k8s-attributes/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zeitlinger I want to make sure I understand it right, so the scenario of this pr is like, if I create a pod PodA
which export log to a otel-collector which has k8sattributes processor enabled with this operator_rules.enabled
to be true.
Then if the PodA
has a annotation called
resource.opentelemetry.io/foo: "bar"
Then the log exported to the otel-collector will have a new attribute called foo
added to its resource attributes with value bar
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This proposal has shown up a couple of times in the past. We need to decide on where is the best place to implement this.
Check open-telemetry/opentelemetry-helm-charts#905 and #27261.
correct |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
please keep open - the spec issue is still ongoing |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
please keep open |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
the spec is merged - I'm planning to finish the PR this week |
61b534d
to
4dbf965
Compare
PR has been updated to reflect the spec |
Please resolve the CI issues:
Please also address the conflict. Once ready, please mark the PR as ready to review again. |
bc0d323
to
387ebca
Compare
@dmitryax as discussed in SIG, I'll break it down im multiple PRs, starting with the annotations |
that's correct - that's what https://github.com/open-telemetry/semantic-conventions/blob/main/docs/non-normative/k8s-attributes.md#specify-resource-attributes-using-kubernetes-annotations says |
Those are older discussions about semantic conventions - which have now been merged: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/non-normative/k8s-attributes.md This PR is about implementing this spec. |
Converted to draft, because some PRs will be split off first - #38825 so far |
enabled: true | ||
well_known_labels: true # default is false | ||
annotation_prefixes: ["foo/"] # default is ["resource.opentelemetry.io/"] - use empty list to disable | ||
exclude: ["service.version"] # default is empty list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just move well known attributes from this section to where all the other pre-defined resource attributes are configured extract.metadata
, and disabled by default?
Then this section would be responsible for taking resource attributes from annotations only. Instead of calling it automatic_attributes
, it can be something like
extract:
otel_annotations: <bool> // false by default
Then, if we want to provide flexibility for annotations extraction, we could add extract.annotations
with the same syntax as we currently have for extract.labels
. That is not really needed right now.
Providing such interface would be consistent with the existing one and easier to understand by the end users. Please let me know WDYT.
…prefix (#38825) This is the first part of #37114 - the ability to use an annotation prefix to define a resource attribute --------- Co-authored-by: Christos Markou <[email protected]>
the second and (maybe) final part is #39335 |
…prefix (open-telemetry#38825) This is the first part of open-telemetry#37114 - the ability to use an annotation prefix to define a resource attribute --------- Co-authored-by: Christos Markou <[email protected]>
…prefix (open-telemetry#38825) This is the first part of open-telemetry#37114 - the ability to use an annotation prefix to define a resource attribute --------- Co-authored-by: Christos Markou <[email protected]>
Description
Implements https://github.com/open-telemetry/semantic-conventions/blob/main/docs/non-normative/k8s-attributes.md#how-serviceversion-should-be-calculate
The OTel operator has a set of rules to create resource attributes - which is described here.
This PR allows the collector to create resource attributes with the same logic.
Why
If the operator supplies resource attributes (that are sent with OTLP), it seems redundant that the collector should be able to do the same - it will just overwrite the resource attribute with identical values.
This feature gets interesting if you are not only getting all data from OTLP - but some data elsewhere, e.g. from the file log receiver.
It's crucial to use the same values for resource attributes across signals - this makes correlation possible.
For example, it allows you to find file based the log entries on the same service instance as a trace you're viewing (around the same time).
Alternatives
The same result can be achieved using the transforprocessor - but it's a very long and hard-to-understand configuration.
It that way, it's similar to the container parser.
Testing
Unit tests were added - e2e tests later
Documentation
Added here
This also has a complete config.