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 ToKeyValueString Converter #35409

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

kuiperda
Copy link
Contributor

@kuiperda kuiperda commented Sep 24, 2024

Description:

Implements ToKeyValueString OTTL Converter.

Link to tracking Issue: #35334

Testing: Added unit tests and e2e

Documentation: Added

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 like the round trip tests. This looks good to me. cc @TylerHelmuth

pkg/ottl/ottlfuncs/README.md Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/README.md Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/README.md Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_marshal_key_value.go Outdated Show resolved Hide resolved
@kuiperda
Copy link
Contributor Author

@TylerHelmuth Thanks for the feedback, I believe I've addressed everything.

@kuiperda kuiperda changed the title [pkg/ottl] Add MarshalKeyValue Converter [pkg/ottl] Add ToKeyValueString Converter Sep 30, 2024
Comment on lines 99 to 103
for _, kv := range keyValues {
k := escapeAndQuoteKV(kv.key, delimiter, pairDelimiter)
vStr := escapeAndQuoteKV(kv.val.AsString(), delimiter, pairDelimiter)
kvStrings = append(kvStrings, fmt.Sprintf("%s%s%v", k, delimiter, vStr))
}
} else {
target.Range(func(k string, v pcommon.Value) bool {
key := escapeAndQuoteKV(k, delimiter, pairDelimiter)
vStr := escapeAndQuoteKV(v.AsString(), delimiter, pairDelimiter)
kvStrings = append(kvStrings, fmt.Sprintf("%s%s%v", key, delimiter, vStr))
return true
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to reuse this logic so that in the future, if we need to change it, we don't accidentally change it for only the sorted path or only the unsorted path.

Comment on lines 70 to 72
kvString := convertMapToKV(source, delimiter, pairDelimiter, sortOutput)

return kvString, nil
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
kvString := convertMapToKV(source, delimiter, pairDelimiter, sortOutput)
return kvString, nil
return convertMapToKV(source, delimiter, pairDelimiter, sortOutput), nil

for _, kv := range keyValues {
k := escapeAndQuoteKV(kv.key, delimiter, pairDelimiter)
vStr := escapeAndQuoteKV(kv.val.AsString(), delimiter, pairDelimiter)
kvStrings = append(kvStrings, fmt.Sprintf("%s%s%v", k, delimiter, vStr))
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 recalling something from my past that fmt.Sprintf has to do an extra allocation to convert types. It may be more efficient, although more verbose, to handle OTTL's supported types to string manually.

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'm noticing those values are all strings anyway and can just be joined together.

@kuiperda
Copy link
Contributor Author

kuiperda commented Oct 1, 2024

@TylerHelmuth I've addressed the feedback from yesterday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants