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

[processor/k8sattributesprocessor] support key_regex match full length value #13381

Merged
merged 5 commits into from
Sep 7, 2022

Conversation

erenming
Copy link
Contributor

Description:

support key_regex match full length of value

Link to tracking Issue:
#9716

Testing:
test for failed match when ecounter paritial regex pattern

Documentation:

@erenming erenming requested review from a team and dmitryax as code owners August 16, 2022 14:25
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 16, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: erenming / name: Eren (8f21086)

@erenming erenming changed the title support key_regex match full length value [processor/k8sattributesprocessor] support key_regex match full length value Aug 16, 2022
Copy link
Member

@dmitryax dmitryax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

processor/k8sattributesprocessor/config.go Show resolved Hide resolved
processor/k8sattributesprocessor/internal/kube/kube.go Outdated Show resolved Hide resolved
processor/k8sattributesprocessor/internal/kube/kube.go Outdated Show resolved Hide resolved
@dmitryax
Copy link
Member

Also please add a changelog entry marked as breaking to unreleased directory

@erenming erenming requested a review from dmitryax August 17, 2022 14:38
@@ -1290,3 +1301,11 @@ func newTestClientWithRulesAndFilters(t *testing.T, e ExtractionRules, f Filters
func newTestClient(t *testing.T) (*WatchClient, *observer.ObservedLogs) {
return newTestClientWithRulesAndFilters(t, ExtractionRules{}, Filters{})
}

func regexpMustCompile(pattern string) *regexp.Regexp {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit inconsistent that we use this helper in this file, but hardcode the pattern in processor/k8sattributesprocessor/options_test.go. Also we need to expose RegexpCompile from this module just because of this helper.

I'd recommend removing all the helpers and hardcode ^(?:...)$ pattern when needed including processor/k8sattributesprocessor/options.go. I believe it'll be less complicated. We don't need to reuse code just for tests

Copy link
Contributor Author

@erenming erenming Aug 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, i think, the testcase in processor/k8sattributesprocessor/options_test.go is used to test the function withExtractAnnotations, so it shouldn't relay on the RegexpCompile fucntion (and so, no need to expose regexpMustCompile).

But the testcase in processor/k8sattributesprocessor/internal/kube/client_test.go is used to test the parameter KeyRegex, so it could use the helper regexpMustCompile.

This is my opinion, please correct me if i was wrong

Copy link
Member

@dmitryax dmitryax Aug 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of the tests is different but neither of them test RegexpCompile function. Test cases that you changed in processor/k8sattributesprocessor/internal/kube/client_test.go just utilize the function, don't test it. In order to test it, you need to write or update test cases covering extractFieldRules function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, RegexpCompile is a bit useless indeed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, but i have a problem.
Does Parameter Regex need to use full length matches? Now it's inconsistent with KeyRegex

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. Regex is intended to extract new fields so it doesn't need to be that strict. But I understand your concern. I would lean towards not touching Regex at this point

@erenming erenming requested a review from dmitryax August 19, 2022 14:31
@erenming
Copy link
Contributor Author

@dmitryax Hi, is there anything still need to soved?

@github-actions
Copy link
Contributor

github-actions bot commented Sep 7, 2022

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Sep 7, 2022
@mx-psi mx-psi removed the Stale label Sep 7, 2022
@dmitryax dmitryax merged commit bc9e9ba into open-telemetry:main Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants