open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
3.01k stars 2.33k forks source link

Improve regex replacement. #34146

Open h0cheung opened 3 months ago

h0cheung commented 3 months ago

Component(s)

pkg/ottl

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

The standard regexp in Go is sometimes powerless, which make us hard to do some replacement.

For example, I want to replaces pure number path segment in a http url. I tried to use some expression: /\d+(/|$) to /?$1.

However, if there are continuous segments, they won't be replaced at once: /12/34/56/78 -> /?/34/?/78. As positive lookahead is not supported, the only workaround I find this to replace by this expression again, but it will cause 2x cpu usage.

(/\d+){1,}(/$) can match perfectly, but I can't find a way to replace each match of (/\d+) to /?.

Describe the solution you'd like

  1. Consider supporting some powerful regex engine, such as https://github.com/dlclark/regexp2. Let users choose which engine to use according to their needs.
  2. Enhance the functions to replacing each match of some expression ends with {x,}

Describe alternatives you've considered

No response

Additional context

No response

github-actions[bot] commented 3 months ago

Pinging code owners:

evan-bradley commented 3 months ago

I think it would likely make sense to offer a more powerful alternative regex engine for cases like this where the built-in Go engine isn't sufficient. We could probably add an engine or lang optional parameter to our functions to allow selecting what is used.

TylerHelmuth commented 2 months ago

Related to https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/32167

github-actions[bot] commented 1 week ago

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.