-
Notifications
You must be signed in to change notification settings - Fork 311
Use prefix trie for proxy ignores #8678
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
...va-agent/agent-tooling/src/jmh/java/datadog/trace/agent/tooling/ProxyIgnoreBenchmark.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package datadog.trace.agent.tooling; | ||
|
||
import datadog.trace.agent.tooling.bytebuddy.matcher.ProxyIgnoredClassNameTrie; | ||
import java.util.concurrent.TimeUnit; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Param; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
/* | ||
Benchmark (className) Mode Cnt Score Error Units | ||
ProxyIgnoreBenchmark.useContains org.springframework.util.ConcurrentReferenceHashMap$4 thrpt 2 0.007 ops/ns | ||
ProxyIgnoreBenchmark.useContains java.lang.invoke.LambdaForm$DMH/0x00007fe9f0388000 thrpt 2 0.008 ops/ns | ||
ProxyIgnoreBenchmark.useContains org.springframework.core.annotation.RepeatableContainers$StandardRepeatableContainers$$Lambda$315/0x00007fe9f03adc70 thrpt 2 0.003 ops/ns | ||
ProxyIgnoreBenchmark.useContains datadog.test.package.redis.RedisTemplateProvider$$TestCGLIB$$FastClass$$0 thrpt 2 0.025 ops/ns | ||
ProxyIgnoreBenchmark.useTrie org.springframework.util.ConcurrentReferenceHashMap$4 thrpt 2 0.026 ops/ns | ||
ProxyIgnoreBenchmark.useTrie java.lang.invoke.LambdaForm$DMH/0x00007fe9f0388000 thrpt 2 0.026 ops/ns | ||
ProxyIgnoreBenchmark.useTrie org.springframework.core.annotation.RepeatableContainers$StandardRepeatableContainers$$Lambda$315/0x00007fe9f03adc70 thrpt 2 0.009 ops/ns | ||
ProxyIgnoreBenchmark.useTrie datadog.test.package.redis.RedisTemplateProvider$$TestCGLIB$$FastClass$$0 thrpt 2 0.029 ops/ns | ||
*/ | ||
@State(Scope.Benchmark) | ||
@BenchmarkMode(Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@Measurement(iterations = 2, time = 5, timeUnit = TimeUnit.SECONDS) | ||
@Warmup(iterations = 1) | ||
@Fork(value = 1) | ||
public class ProxyIgnoreBenchmark { | ||
@Param({ | ||
"org.springframework.util.ConcurrentReferenceHashMap$4", | ||
"java.lang.invoke.LambdaForm$DMH/0x00007fe9f0388000", | ||
"org.springframework.core.annotation.RepeatableContainers$StandardRepeatableContainers$$Lambda$315/0x00007fe9f03adc70", | ||
// worst case for trie based | ||
"datadog.test.package.redis.RedisTemplateProvider$$TestCGLIB$$FastClass$$0" | ||
}) | ||
public String className; | ||
|
||
@Benchmark | ||
public void useContains(Blackhole bh) { | ||
if (className.indexOf('$') > -1) { | ||
if (className.contains("$JaxbAccessor") | ||
|| className.contains("CGLIB$$") | ||
|| className.contains("$__sisu") | ||
|| className.contains("$$EnhancerByGuice$$") | ||
|| className.contains("$$EnhancerByProxool$$") | ||
|| className.contains("$$$view") | ||
|| className.contains("$$$endpoint") // jboss mdb proxies | ||
|| className.contains("$$_Weld") | ||
|| className.contains("_$$_jvst")) { | ||
bh.consume(true); | ||
} | ||
} | ||
} | ||
|
||
@Benchmark | ||
public void useTrie(Blackhole bh) { | ||
int last = -1; | ||
int idx; | ||
while (true) { | ||
idx = className.indexOf('$', last + 1); | ||
if (idx < 0) { | ||
break; | ||
} | ||
if (last < 0 && className.contains("CGLIB$$")) { | ||
break; | ||
} | ||
if (idx == last + 1) { | ||
// skip the trie if consecutive $$ since, to be efficient, we can match prefixes from the | ||
// first dollar | ||
last = idx; | ||
continue; | ||
} | ||
last = idx; | ||
if (ProxyIgnoredClassNameTrie.apply(className, idx) >= 0) { | ||
return; | ||
} | ||
} | ||
bh.consume(true); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...ain/resources/datadog/trace/agent/tooling/bytebuddy/matcher/proxy_ignored_class_name.trie
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Generates 'ProxyIgnoredClassNameTrie.java' | ||
|
||
# This file lists classes that are considered as proxy hence ignored. | ||
# The trie will be matched starting from the first '$' char included. | ||
# Use 0 to allow transformation of packages or classes beneath ignored packages | ||
# Use 1 to ignore. | ||
# End lines with '*' to match any trailing char if needed. | ||
|
||
# 0 = global allows | ||
# 1 = system-level ignores | ||
|
||
# --------- ALLOW SHORTCUTS ----------- | ||
|
||
# lambda factory generated classes are not proxies | ||
0 $$Lambda$* | ||
|
||
# -------- SYSTEM-LEVEL IGNORES -------- | ||
|
||
1 $$weld* | ||
1 $JaxbAccessor* | ||
1 $__sisu* | ||
1 $$EnhancerByGuice$$* | ||
1 $$EnhancerByProxool$$* | ||
1 $$$view* | ||
# jboss mdb proxies | ||
1 $$$endpoint* | ||
1 $$_Weld* | ||
1 $$_jvst* | ||
1 $$SpringCGLIB$$* |
20 changes: 20 additions & 0 deletions
20
...rc/test/groovy/datadog/trace/agent/tooling/bytebuddy/matcher/ProxyClassIgnoresTest.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package datadog.trace.agent.tooling.bytebuddy.matcher | ||
|
||
import datadog.trace.test.util.DDSpecification | ||
|
||
class ProxyClassIgnoresTest extends DDSpecification { | ||
def 'test #clsName exclusion'() { | ||
given: | ||
def result = ProxyClassIgnores.isIgnored(clsName) | ||
expect: | ||
result == excluded | ||
where: | ||
clsName | excluded | ||
'org.springframework.util.ConcurrentReferenceHashMap$4' | false | ||
'io.github.resilience4j.springboot3.circuitbreaker.autoconfigure.CircuitBreakerAutoConfiguration$CircuitBreakerEndpointAutoConfiguration$$SpringCGLIB$$0' | true | ||
'io.micrometer.core.instrument.config.NamingConvention$$Lambda$1415' | false | ||
'com.package.name.Class$JaxbAccessorF_variablename' | true | ||
'my.package.Resource$Proxy$_$$_Weld$EnterpriseProxy' | true | ||
'com.abc.MyResourceImpl$$EnhancerByGuice$$69175a50' | true | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about calling the
isIgnored()
method and consume this result instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to have it clearly copied to that specifc bench since thing can change