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(ottl): Add a new ottl trim function that trims leading and trailing whitespace from a string #36400

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

Conversation

rnishtala-sumo
Copy link
Contributor

@rnishtala-sumo rnishtala-sumo commented Nov 16, 2024

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

Copy link
Member

@TylerHelmuth TylerHelmuth left a comment

Choose a reason for hiding this comment

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

Please add an entry to ottlfuncs/README for this new converter

@TylerHelmuth
Copy link
Member

@rnishtala-sumo can you add to the description the issue this PR closes

.chloggen/ottl-trim-function.yaml Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_trim.go Outdated Show resolved Hide resolved

```Trim(target, replacement)```

The `Trim` Converter removes the leading and trailing character (default: whitespace).
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd also add the default value description on the replacement argument docs

Copy link
Member

Choose a reason for hiding this comment

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

Yes. Take a look in this README how other Optional parameters are indicated (can use flatten as an example).


```Trim(target, replacement)```

The `Trim` Converter removes the leading and trailing character (default: whitespace).
Copy link
Member

Choose a reason for hiding this comment

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

Yes. Take a look in this README how other Optional parameters are indicated (can use flatten as an example).

if err != nil {
return nil, err
}
if replacement.IsEmpty() || replacementString == "" {
Copy link
Member

Choose a reason for hiding this comment

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

Above line 34, lets to a check for if replacement == "" and error if it is. Calling Trim(name, "") implies a nop, but we'd be trimming " ".

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.

5 participants