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

[pkg/ottl] Add ParseKeyValue function #31035

Merged
merged 9 commits into from
Feb 15, 2024

Conversation

dpaasman00
Copy link
Contributor

Description:
Adds a ParseKeyValue converter function that parses out key values pairs into a pcommon.Map. It takes a StringGetter target argument and 2 optional arguments for the pair delimiter and key value delimiter. This is an adaptation of the Stanza Key Value Parser operator to provide feature parity.

Given the following input string "k1=v1 k2=v2 k3=v3", the function would return the following map:

{ "k1": "v1", "k2": "v2", "k3": "v3" }

Link to tracking Issue:
Closes #30998

Testing:
Added unit tests and e2e test.

Documentation:
Added function documentation.

Copy link

linux-foundation-easycla bot commented Feb 5, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@dpaasman00 dpaasman00 marked this pull request as ready for review February 5, 2024 21:47
@dpaasman00 dpaasman00 requested a review from a team as a code owner February 5, 2024 21:47
Copy link
Member

@djaglowski djaglowski left a comment

Choose a reason for hiding this comment

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

I'm not familiar enough with ottl code standards to approve this but I can confirm it appears to implement equivalent parsing functionality to keyvalue_parser from pkg/stanza

pkg/ottl/ottlfuncs/func_parse_key_value.go Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_parse_key_value.go Outdated Show resolved Hide resolved
Copy link
Contributor

@evan-bradley evan-bradley left a comment

Choose a reason for hiding this comment

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

Looks good overall, just a few minor notes.

pkg/ottl/ottlfuncs/README.md Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_parse_key_value.go Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_parse_key_value.go Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_parse_key_value.go Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_parse_key_value.go Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_parse_key_value.go Show resolved Hide resolved
Copy link
Contributor

@evan-bradley evan-bradley 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 your persistence, I think we're getting close.

@dpaasman00
Copy link
Contributor Author

Unsure if I should update Stanza in this PR similar to how it was done in #31081 or if that's a separate PR?

@TylerHelmuth
Copy link
Member

@dpaasman00 we'll update stanza in a separate PR

@evan-bradley evan-bradley merged commit d0c0e97 into open-telemetry:main Feb 15, 2024
142 checks passed
djaglowski pushed a commit that referenced this pull request Feb 16, 2024
**Description:** <Describe what has changed.>

Updates the KeyValue parser to use the parseutils pkg and subsequent
functions

**Link to tracking Issue:** N/A

Follows up on this
[comment](#31035 (comment))
about merging functionality between Stanza and OTTL key value parsing

**Testing:** 

Unit tests still pass, had to update one because of different wording in
err message

**Documentation:** N/A
XinRanZhAWS pushed a commit to XinRanZhAWS/opentelemetry-collector-contrib that referenced this pull request Mar 13, 2024
**Description:** <Describe what has changed.>
Adds a `ParseKeyValue` converter function that parses out key values
pairs into a `pcommon.Map`. It takes a `StringGetter` target argument
and 2 optional arguments for the pair delimiter and key value delimiter.
This is an adaptation of the Stanza Key Value Parser operator to provide
feature parity.

Given the following input string `"k1=v1 k2=v2 k3=v3"`, the function
would return the following map:
```
{ "k1": "v1", "k2": "v2", "k3": "v3" }
```

**Link to tracking Issue:** <Issue number if applicable>
Closes open-telemetry#30998 

**Testing:** <Describe what testing was performed and which tests were
added.>
Added unit tests and e2e test.

**Documentation:** <Describe the documentation added.>
Added function documentation.
XinRanZhAWS pushed a commit to XinRanZhAWS/opentelemetry-collector-contrib that referenced this pull request Mar 13, 2024
…etry#31291)

**Description:** <Describe what has changed.>

Updates the KeyValue parser to use the parseutils pkg and subsequent
functions

**Link to tracking Issue:** N/A

Follows up on this
[comment](open-telemetry#31035 (comment))
about merging functionality between Stanza and OTTL key value parsing

**Testing:** 

Unit tests still pass, had to update one because of different wording in
err message

**Documentation:** N/A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[pkg/ottl] Add function for parsing key value pairs
7 participants