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/transform] Add replace_match and replace_all_matches functions #10132

Merged

Conversation

TylerHelmuth
Copy link
Member

Description:
This PR adds 2 new functions, replace_match and replace_all_matches.

replace_match takes a telemetry path and replace's it with the supplied replacement if the value matches the supplied pattern.

replace_all_matches does the same, exact on all possible values on a supplied map.

Link to tracking Issue:
Related to #8252

Testing:
Added unit tests

Documentation:
Updated README. Submitted PR to update processing.md doc

processor/transformprocessor/README.md Outdated Show resolved Hide resolved
processor/transformprocessor/README.md Outdated Show resolved Hide resolved
processor/transformprocessor/internal/common/functions.go Outdated Show resolved Hide resolved
processor/transformprocessor/internal/common/functions.go Outdated Show resolved Hide resolved
@TylerHelmuth
Copy link
Member Author

@dehaansa your review is my new favorite lol all typos should be fixed

processor/transformprocessor/README.md Outdated Show resolved Hide resolved
@TylerHelmuth
Copy link
Member Author

/cc @anuraaga. I opted to rename replace_wildcards to replace_match, bc I think it better describes what the function is doing and it aligns better with the function syntax standards. Since the function replaces the whole string not only the *s, and since the *s are being used to match the string, I think replace_match is the best name.

Copy link
Contributor

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

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

Thanks, looking forward to this function

@@ -31,6 +31,10 @@ the fields specified by the list of strings. e.g., `keep_keys(attributes, "http.

- `limit(target, limit)` - `target` is a path expression to a map type field. `limit` is a non-negative integer. The map will be mutated such that the number of items does not exceed the limit. e.g., `limit(attributes, 100)` will limit `attributes` to no more than 100 items. Which items are dropped is random.

- `replace_match(target, pattern, replacement)` - `target` is a path expression to a telemetry field, `pattern` is a string following [filepath.Match syntax](https://pkg.go.dev/path/filepath#Match), and `replacement` is a string. If `target` matches `pattern` it will get replaced with `replacement`. e.g., `replace_match(attributes["http.target"], "/user/*/list/*", "/user/{userId}/list/{listId}")`

- `replace_all_matches(target, pattern, replacement)` - `target` is a path expression to a map type field, `pattern` is a string following [filepath.Match syntax](https://pkg.go.dev/path/filepath#Match), and `replacement` is a string. Each string value in `target` that matches `pattern` will get replaced with `replacement`. e.g., `replace_all_matches(attributes, "/user/*/list/*", "/user/{userId}/list/{listId}")`
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if there is a significant use case for this, it's rare for many attributes to match the same string I guess. If just two or so which seems imaginable, two replace_match seems reasonable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably not a significant number of use cases, but I like the flexibility. Also a good example of function syntax standards.

processor/transformprocessor/internal/common/functions.go Outdated Show resolved Hide resolved
@TylerHelmuth
Copy link
Member Author

@open-telemetry/collector-contrib-approvers please review.

@TylerHelmuth
Copy link
Member Author

@open-telemetry/collector-contrib-maintainer please review. I'd like to get this in for the 0.52.0 release.

@djaglowski djaglowski merged commit 001c76b into open-telemetry:main May 23, 2022
@TylerHelmuth TylerHelmuth deleted the issue-8252-replace-wildcards branch May 23, 2022 23:46
kentquirk pushed a commit to McSick/opentelemetry-collector-contrib that referenced this pull request Jun 14, 2022
…ions (open-telemetry#10132)

* add replace_match and repalce_all_matches functions
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.

5 participants