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/telemetryquerylanguage] add replace_key_all_patterns function #12991

Merged

Conversation

fatsheep9146
Copy link
Contributor

Signed-off-by: Ziqi Zhao [email protected]

Description:
fix #12631

@TylerHelmuth
Copy link
Member

@fatsheep9146 can you break this into 2 PR, one for the function add and one to the transform processor? It'd be nice to do it all in one PR but any functions added to transformprocessor should have integration tests added to a signals processor_test.go and I think the PR would be too large.

@fatsheep9146
Copy link
Contributor Author

@fatsheep9146 can you break this into 2 PR, one for the function add and one to the transform processor? It'd be nice to do it all in one PR but any functions added to transformprocessor should have integration tests added to a signals processor_test.go and I think the PR would be too large.

I've removed it from transform processor, and I will submit second PR until this one is merged.

@fatsheep9146 fatsheep9146 force-pushed the replace-key-all-patterns branch from e683574 to ee91201 Compare August 15, 2022 09:48
@fatsheep9146
Copy link
Contributor Author

The integration test seems unrelated to this pr @TylerHelmuth

@TylerHelmuth
Copy link
Member

@bogdandrutu @kentquirk curious on your thoughts on this function. It will certainly meet the needs of the user to rename keys in bulk, but we'd end up with replace_match, replace_all_matches, replace_pattern, replace_all_patterns, and replace_key_all_patterns functions, all that are named similarly and do similar, but slightly different things.

For this particular use case we could instead update replace_all_patterns to take a new parameter (string or enum) that specifies whether the function applies to keys or values and update the logic accordingly. This would be a breaking change (which is ok bc the processor/tql is still in alpha), but would keep the number of functions lower.

@TylerHelmuth
Copy link
Member

For this particular use case we could instead update replace_all_patterns to take a new parameter (string or enum) that specifies whether the function applies to keys or values and update the logic accordingly.

@fatsheep9146 please update your implementation to match this comment instead of adding a new function.

@fatsheep9146 fatsheep9146 force-pushed the replace-key-all-patterns branch 2 times, most recently from 833423a to 060243e Compare August 24, 2022 15:22
@fatsheep9146
Copy link
Contributor Author

For this particular use case we could instead update replace_all_patterns to take a new parameter (string or enum) that specifies whether the function applies to keys or values and update the logic accordingly.

@fatsheep9146 please update your implementation to match this comment instead of adding a new function.

I already add a new parameter, please help review this =D @TylerHelmuth

@fatsheep9146 fatsheep9146 force-pushed the replace-key-all-patterns branch from 060243e to 279181d Compare August 29, 2022 06:00
@fatsheep9146
Copy link
Contributor Author

Please help review this again =D @TylerHelmuth

@fatsheep9146
Copy link
Contributor Author

All comments are fixed. @TylerHelmuth

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.

Thanks for doing this!

@fatsheep9146 fatsheep9146 force-pushed the replace-key-all-patterns branch from 0b586fd to 3f59475 Compare September 6, 2022 04:15
@fatsheep9146
Copy link
Contributor Author

@bogdandrutu Could you help review this?

Copy link
Member

@kentquirk kentquirk left a comment

Choose a reason for hiding this comment

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

This seems correct as is, but I wonder if it's worth trying to avoid some allocations in the general case.

stringVal := value.StringVal()
if compiledPattern.MatchString(stringVal) {
value.SetStringVal(compiledPattern.ReplaceAllLiteralString(stringVal, replacement))
updated.EnsureCapacity(attrs.Len())
Copy link
Member

Choose a reason for hiding this comment

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

I think it will be a fairly common occurrence that this function does no useful work -- that none of the attributes match the given pattern. Consequently, it might make sense, then, to do one of two things:

  • set a flag when the match succeeds, and only do the target.Set if it has succeeded at least once; this avoids rewriting target, although it doesn't avoid the allocation
  • do a pre-pass over the keys looking for a match, and if none is found exit without allocating the updated value

Is it worth it?

Copy link
Member

Choose a reason for hiding this comment

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

We haven't done serious benchmarks for OTTl or the transform processor yet, but we should. As both mature I say we should take performance improvements wherever we can find them.

Copy link
Member

Choose a reason for hiding this comment

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

Although I think the suggestion can be done in a future PR if you open an issue to call it out.

I think I'd also like to merge all the Replace functions into one.

@TylerHelmuth
Copy link
Member

TylerHelmuth commented Sep 22, 2022

@fatsheep9146 please address conflicts

@fatsheep9146 fatsheep9146 force-pushed the replace-key-all-patterns branch from 34bc53b to 9b47d83 Compare September 22, 2022 04:46
@fatsheep9146
Copy link
Contributor Author

fatsheep9146 commented Sep 22, 2022

@fatsheep9146 please address conflicts

I think the failed task is due to transformprocessor

make[2]: Entering directory '/home/runner/work/opentelemetry-collector-contrib/opentelemetry-collector-contrib/processor/transformprocessor'
Check License finished successfully
running misspell -error
golangci-lint run --allow-parallel-runners
make[2]: Leaving directory '/home/runner/work/opentelemetry-collector-contrib/opentelemetry-collector-contrib/processor/tailsamplingprocessor'
Error: internal/logs/processor_test.go:90:79: td.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).Attributes().InsertString undefined (type pcommon.Map has no field or method InsertString) (typecheck)
				td.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).Attributes().InsertString("url", "http://localhost/health")

Should I fix those in seperate prs? @TylerHelmuth

@TylerHelmuth
Copy link
Member

@fatsheep9146 Ya those errors don't seem correct. Attempt to fix in another PR, but I suspect if you create a new branch from main you won't see them.

@fatsheep9146
Copy link
Contributor Author

fatsheep9146 commented Sep 22, 2022

@fatsheep9146 Ya those errors don't seem correct. Attempt to fix in another PR, but I suspect if you create a new branch from main you won't see them.

Sorry, it's my mistake, the reason is that in transformprocessor test, I also fix some test for this feature, I will fix this.

@TylerHelmuth TylerHelmuth added the ready to merge Code review completed; ready to merge by maintainers label Sep 23, 2022
Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

Needs a rebase

@TylerHelmuth TylerHelmuth removed the ready to merge Code review completed; ready to merge by maintainers label Sep 23, 2022
@fatsheep9146 fatsheep9146 force-pushed the replace-key-all-patterns branch from 9bc8594 to 19630cc Compare September 24, 2022 01:03
@fatsheep9146
Copy link
Contributor Author

Needs a rebase

Rebase done, I think this is ready-to-merge. @codeboten @TylerHelmuth

@fatsheep9146 fatsheep9146 force-pushed the replace-key-all-patterns branch 2 times, most recently from 304a77d to c847139 Compare September 29, 2022 01:52
@fatsheep9146
Copy link
Contributor Author

fatsheep9146 commented Sep 29, 2022

@TylerHelmuth @codeboten Could you help add ready-to-merge label?

@bogdandrutu
Copy link
Member

Please add a changelog entry.

@fatsheep9146 fatsheep9146 force-pushed the replace-key-all-patterns branch from 10bc71a to c847139 Compare September 29, 2022 08:52
@TylerHelmuth
Copy link
Member

@fatsheep9146 please rebase.

@fatsheep9146 fatsheep9146 force-pushed the replace-key-all-patterns branch from 61a132e to d50ea13 Compare September 30, 2022 01:43
@TylerHelmuth TylerHelmuth added the ready to merge Code review completed; ready to merge by maintainers label Sep 30, 2022
@djaglowski djaglowski merged commit 2ba332a into open-telemetry:main Oct 6, 2022
@EddieEldridge
Copy link
Contributor

This is awesome, thanks so much everyone 🍾

shalper2 pushed a commit to shalper2/opentelemetry-collector-contrib that referenced this pull request Dec 6, 2022
…pen-telemetry#12991)

* [pkg/telemetryquerylanguage] enhance replace_all_patterns function
@plantfansam plantfansam mentioned this pull request Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge Code review completed; ready to merge by maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[processor/transform]: Allow transformation of Trace attribute keys
7 participants