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

feat(pkg/ottl) Adding an optional replacementFormat argument to the replace_pattern editors that specified the format of the replacement string #27686

Closed

Conversation

rnishtala-sumo
Copy link
Contributor

@rnishtala-sumo rnishtala-sumo commented Oct 16, 2023

Description: Adding an optional replacementFormat argument to the replace_pattern editors that specified the format of the replacement string

Testing: Unit tests were added for this new optional argument

Documentation:
https://github.com/rnishtala-sumo/opentelemetry-collector-contrib/blob/ottl-replace-pattern/pkg/ottl/ottlfuncs/README.md#replace_pattern

The following changelog could be reused for this PR

Related to this issue: #22787

want: func(expectedValue pcommon.Value) {
expectedValue.SetStr("application 0f2407f2d83337b1f757eb1754a7643ce0e8fba620bc605c54566cd6dfd838beotherarg=notsensitive key1 key2")
expectedValue.SetStr("application passwd=0f2407f2d83337b1f757eb1754a7643ce0e8fba620bc605c54566cd6dfd838be otherarg=notsensitive key1 key2")
Copy link
Contributor Author

@rnishtala-sumo rnishtala-sumo Oct 16, 2023

Choose a reason for hiding this comment

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

This is the overall goal of this PR. To be able to add an optional prefix to a hash string. It can also add a prefix to a regular string.

So these are all the ways that a prefix could be added with this change

  • replace_pattern(name, "^kube_([0-9A-Za-z]+_)", "k8s.$$1.")
  • replace_pattern(name, "^kube_([0-9A-Za-z]+_)", "$$1.", "k8s.")
  • replace_pattern(name, "^kube_([0-9A-Za-z]+_)", "$$1.", "k8s.", SHA256)
    Note that a prefix string is not included in the hash value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@rnishtala-sumo I am a little confused why this PR is needed. Can you open a new issue to describe the problem and how this solves it?

Copy link
Contributor Author

@rnishtala-sumo rnishtala-sumo Oct 17, 2023

Choose a reason for hiding this comment

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

@TylerHelmuth created this issue

#27820

The solution proposed in the issue is what this PR does.

@rnishtala-sumo rnishtala-sumo force-pushed the ottl-replace-pattern branch 3 times, most recently from 398d4c6 to ae7cd31 Compare October 18, 2023 21:54
replacementFormat: ottl.NewTestingOptional[string]("%s (passwd)"),
function: optionalArg,
want: func(expectedValue pcommon.Value) {
expectedValue.SetStr("application 0f2407f2d83337b1f757eb1754a7643ce0e8fba620bc605c54566cd6dfd838be (passwd) otherarg=notsensitive key1 key2")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

support for suffixes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TylerHelmuth @evan-bradley we're able to support a suffix as well using the suggested format string approach as mentioned in this comment

@rnishtala-sumo rnishtala-sumo changed the title feat(pkg/ottl) Adding an optional replacement prefix argument to the replace_pattern editors feat(pkg/ottl) Adding an optional replacementFormat argument to the replace_pattern editors that specified the format of the replacement string Oct 19, 2023
Copy link
Contributor

@MovieStoreGuy MovieStoreGuy left a comment

Choose a reason for hiding this comment

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

From my perspective, after ready through the issue I believe it makes more sense for functions like HASH to only be applied to the extracted groups which avoids the need of providing a format?

ie: replace_pattern(name, "^kube_(...)$", "prefix-$$1--infix-suffix", SHA256)

@@ -7,7 +7,7 @@ change_type: enhancement
component: pkg/ottl

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add optional Converter parameters to replacement Editors
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this updating an existing unpublished feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there will be a new changelog for this. Will revert this change.

@TylerHelmuth
Copy link
Member

TylerHelmuth commented Oct 27, 2023

@MovieStoreGuy Can you add that comment to the issue. It's definitely worth discussing more.

Copy link
Contributor

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 Nov 11, 2023
Copy link
Contributor

Closed as inactive. Feel free to reopen if this PR is still being worked on.

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.

3 participants