-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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/k8sattributesprocessor] support regex capture groups in tag_name #9525
[processor/k8sattributesprocessor] support regex capture groups in tag_name #9525
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.
Also please add documentation to the new capabilities
if r.KeyRegex != nil { | ||
for k, v := range metadata { | ||
var name string | ||
if r.HasKeyRegexReference { |
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.
If we have formatter
as a string with regexp caption e.g. k8s.namespace.annotations.$0
, we can drop this condition along with the else
block, right?
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.
It seems to fully leverage $0
it has certain requirements for the regexp, which might lead to some breaking changes, so far basically the difference I found is how it behaviors between *
and .*
, e.g. https://go.dev/play/p/yUbTV_SKWCj
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.
Sorry I don't understand your point. Can you elaborate please
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.
$0 doesn't always represent the entire key, i.e. in https://go.dev/play/p/yUbTV_SKWCj, given the key is annotation1
, name is annotations.$0
,
- given the key_regex is
an*
, $0 would beann
anda
(both matches the regexp), after 2 iterations(the for loop in the sample code), we got the resultannotations.annannotations.a
(annotations.ann
+annotations.a
). - given the key_regex is
an.*
, $0 would beannotation1
as the matched string is the entire key, thus just one iteration and we got the expected resultannotations.annotation1
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 seems like an incorrect expansion logic. the result should not be composition of several matches.
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.
Just wrapping a regexp supplied by user with ^ and $should do the trick
would it be tricky to wrap it with ^ and $, given that user may have ^ or $ in their regexp, ^ and $ probably has to be appended during validation phase, where we need to handle cases like
- ^an.*
- ^an.*$
- (^an.*)
- (^an.*$)
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.
would it be tricky to wrap it with ^ and $, given that user may have ^ or $ in their regexp, ^ and $ probably has to be appended during validation phase, where we need to handle cases like
Yes, this would be the right approach. But let's not do it for now and keep this change as clean enhancement without breaking behavior
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.
@dmitryax yeah the reason I noticed that an*
is while making this change and noticed failures from current UT, which is expecting k8s.namespace.annotations.annotation1
.
opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/kube/client_test.go
Lines 650 to 663 in 29dd412
{ | |
name: "all-annotations", | |
rules: ExtractionRules{ | |
Annotations: []FieldExtractionRule{{ | |
KeyRegex: regexp.MustCompile("an*"), | |
From: MetadataFromNamespace, | |
}, | |
}, | |
}, | |
attributes: map[string]string{ | |
"k8s.namespace.annotations.annotation1": "av1", | |
}, | |
}, | |
} |
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.
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.
@dmitryax updated doc. |
Please address other comments |
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.
LGTM
…g_name (open-telemetry#9525) * refactor * support captured group in TagName * update CHANGELOG * add UT for entire matched string * fix lint error * add doc for capturing groups * remove capturing group validation * Update CHANGELOG.md * update doc * update substitution logical * remove extractField method from WatchClient * move changelog entry to current release Co-authored-by: Alex Boten <aboten@lightstep.com> Co-authored-by: Dmitrii Anoshin <anoshindx@gmail.com>
Description:
support configure key prefix in k8sattributesprocessor
Link to tracking Issue:
#8844
Testing:
Documentation: