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 an ottl function that allows for the trimming of whitespaces or other specified symbols from an attribute #34100

Open
robbavey opened this issue Jul 16, 2024 · 7 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed pkg/ottl priority:p3 Lowest

Comments

@robbavey
Copy link

Component(s)

pkg/ottl

Is your feature request related to a problem? Please describe.

I would like a simple way to trim whitespace from an attribute

Describe the solution you'd like

I would like to be able to trim data from an existing attribute

For example

A field test exists in an event, which contains the string " this is a test ".

I would like to be able to transform this using an ottl function trim, that I would define as trim(attribute["test"]), which would trim this down to "this is a test".

By default, this would use the unicode definition of whitespace, but we would also allow an alternative version trim(attribute, symbols)
I would also like to be able to set my own definition of whitespace, by providing a string containing the symbols I would like to trim.

Describe alternatives you've considered

A user could do this using the existing replace_all_patterns function, but this is a common enough function that it may warrant a standalone function. Additionally, we can be unambiguous that we replace the Unicode definition of whitespace by default.

Additional context

No response

@robbavey robbavey added enhancement New feature or request needs triage New item requiring triage labels Jul 16, 2024
@robbavey robbavey changed the title Add an ottl function that allows for the trimming of whitespaces or other specified symbols from an attribute [pkg/ottl] Add an ottl function that allows for the trimming of whitespaces or other specified symbols from an attribute Jul 16, 2024
Copy link
Contributor

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@evan-bradley
Copy link
Contributor

@robbavey Thanks for the thorough proposal. Can you go into any detail about the situations you've seen where you've had to do trimming like this?

As for a trim function vs. using regular expressions, I think the following would cover this, and could be used as a template for custom prefix/suffix trimming: (^[\s\p{Zs}]+)|([\s\p{Zs}]+$). I'll admit that a function is more readable than a regular expression, but I want to make sure we think this will be used often enough to be worth having an additional function.

@robbavey
Copy link
Author

@evan-bradley In general, I'm an advocate of simplicity for users, and removing places where they can accidentally craft an incorrect, or poorly performing regex (eg supplying an unanchored regex).

We see use of it a decent amount in Elasticsearch ingest pipelines used in Elastic integrations

@odubajDT
Copy link
Contributor

Hi, is this ticket free for grab? Or it needs more discussion if it's worth implementing? I find it as a good idea

@TylerHelmuth
Copy link
Member

Copy link
Contributor

github-actions bot commented Oct 7, 2024

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@github-actions github-actions bot added the Stale label Oct 7, 2024
@sjpalf
Copy link

sjpalf commented Oct 9, 2024

I really dislike bots that close issues (especially after 60 days which isn't that long at all)

@github-actions github-actions bot removed the Stale label Oct 10, 2024
@TylerHelmuth TylerHelmuth added help wanted Extra attention is needed good first issue Good for newcomers priority:p3 Lowest labels Nov 15, 2024
TylerHelmuth added a commit that referenced this issue Dec 20, 2024
…ing whitespace from a string (#36400)

#### Description

A field test exists in an event, which contains the string " this is a
test ".

I would like to be able to transform this using an ottl function trim,
that I would define as trim(attribute["test"]), which would trim this
down to "this is a test".

- Trim(" this is a test ") results in `this is a test`

Link to the issue -
#34100

---------

Co-authored-by: Tyler Helmuth <[email protected]>
Co-authored-by: Evan Bradley <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed pkg/ottl priority:p3 Lowest
Projects
None yet
Development

No branches or pull requests

5 participants