-
Notifications
You must be signed in to change notification settings - Fork 293
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
Use env-entry to add tags per webapp deployment #8138
Conversation
BenchmarksStartupLoadParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 13 metrics, 15 unstable metrics. Request duration reports for petclinicgantt
title petclinic - request duration [CI 0.99] : candidate=1.46.0-SNAPSHOT~8760af662e, baseline=1.46.0-SNAPSHOT~22458b3367
dateFormat X
axisFormat %s
section baseline
no_agent (1.352 ms) : 1333, 1371
. : milestone, 1352,
appsec (1.75 ms) : 1726, 1773
. : milestone, 1750,
appsec_no_iast (1.756 ms) : 1732, 1781
. : milestone, 1756,
iast (1.493 ms) : 1471, 1516
. : milestone, 1493,
profiling (1.55 ms) : 1524, 1576
. : milestone, 1550,
tracing (1.495 ms) : 1471, 1519
. : milestone, 1495,
section candidate
no_agent (1.353 ms) : 1332, 1373
. : milestone, 1353,
appsec (1.753 ms) : 1729, 1776
. : milestone, 1753,
appsec_no_iast (1.762 ms) : 1738, 1786
. : milestone, 1762,
iast (1.513 ms) : 1491, 1535
. : milestone, 1513,
profiling (1.517 ms) : 1491, 1542
. : milestone, 1517,
tracing (1.483 ms) : 1458, 1508
. : milestone, 1483,
Request duration reports for insecure-bankgantt
title insecure-bank - request duration [CI 0.99] : candidate=1.46.0-SNAPSHOT~8760af662e, baseline=1.46.0-SNAPSHOT~22458b3367
dateFormat X
axisFormat %s
section baseline
no_agent (375.877 µs) : 356, 396
. : milestone, 376,
iast (497.975 µs) : 476, 520
. : milestone, 498,
iast_FULL (654.463 µs) : 633, 676
. : milestone, 654,
iast_GLOBAL (523.144 µs) : 501, 545
. : milestone, 523,
iast_HARDCODED_SECRET_DISABLED (509.807 µs) : 488, 531
. : milestone, 510,
iast_INACTIVE (451.95 µs) : 431, 473
. : milestone, 452,
iast_TELEMETRY_OFF (485.844 µs) : 464, 508
. : milestone, 486,
tracing (452.364 µs) : 432, 473
. : milestone, 452,
section candidate
no_agent (387.029 µs) : 367, 407
. : milestone, 387,
iast (495.705 µs) : 474, 517
. : milestone, 496,
iast_FULL (656.797 µs) : 635, 678
. : milestone, 657,
iast_GLOBAL (528.483 µs) : 506, 551
. : milestone, 528,
iast_HARDCODED_SECRET_DISABLED (496.953 µs) : 475, 519
. : milestone, 497,
iast_INACTIVE (452.06 µs) : 431, 473
. : milestone, 452,
iast_TELEMETRY_OFF (486.401 µs) : 465, 508
. : milestone, 486,
tracing (450.263 µs) : 429, 471
. : milestone, 450,
DacapoParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 12 metrics, 0 unstable metrics. Execution time for tomcatgantt
title tomcat - execution time [CI 0.99] : candidate=1.46.0-SNAPSHOT~8760af662e, baseline=1.46.0-SNAPSHOT~22458b3367
dateFormat X
axisFormat %s
section baseline
no_agent (1.467 ms) : 1456, 1479
. : milestone, 1467,
appsec (2.35 ms) : 2307, 2392
. : milestone, 2350,
iast (2.097 ms) : 2043, 2151
. : milestone, 2097,
iast_GLOBAL (2.141 ms) : 2087, 2195
. : milestone, 2141,
profiling (1.948 ms) : 1906, 1991
. : milestone, 1948,
tracing (1.936 ms) : 1894, 1977
. : milestone, 1936,
section candidate
no_agent (1.472 ms) : 1460, 1483
. : milestone, 1472,
appsec (2.348 ms) : 2306, 2391
. : milestone, 2348,
iast (2.11 ms) : 2056, 2164
. : milestone, 2110,
iast_GLOBAL (2.139 ms) : 2085, 2194
. : milestone, 2139,
profiling (1.973 ms) : 1930, 2017
. : milestone, 1973,
tracing (1.944 ms) : 1902, 1986
. : milestone, 1944,
Execution time for biojavagantt
title biojava - execution time [CI 0.99] : candidate=1.46.0-SNAPSHOT~8760af662e, baseline=1.46.0-SNAPSHOT~22458b3367
dateFormat X
axisFormat %s
section baseline
no_agent (15.366 s) : 15366000, 15366000
. : milestone, 15366000,
appsec (15.161 s) : 15161000, 15161000
. : milestone, 15161000,
iast (18.675 s) : 18675000, 18675000
. : milestone, 18675000,
iast_GLOBAL (18.201 s) : 18201000, 18201000
. : milestone, 18201000,
profiling (14.906 s) : 14906000, 14906000
. : milestone, 14906000,
tracing (14.977 s) : 14977000, 14977000
. : milestone, 14977000,
section candidate
no_agent (15.457 s) : 15457000, 15457000
. : milestone, 15457000,
appsec (14.877 s) : 14877000, 14877000
. : milestone, 14877000,
iast (19.106 s) : 19106000, 19106000
. : milestone, 19106000,
iast_GLOBAL (18.009 s) : 18009000, 18009000
. : milestone, 18009000,
profiling (15.064 s) : 15064000, 15064000
. : milestone, 15064000,
tracing (15.002 s) : 15002000, 15002000
. : milestone, 15002000,
|
d3e1f2d
to
62f2214
Compare
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.
Few minor comments
internal-api/src/main/java/datadog/trace/api/ClassloaderConfigurationOverrides.java
Outdated
Show resolved
Hide resolved
dd-trace-core/src/main/java/datadog/trace/core/DDSpanContext.java
Outdated
Show resolved
Hide resolved
dd-java-agent/instrumentation/wildfly-9/src/test/java/test/ModulePatchInstrumentation.java
Show resolved
Hide resolved
764661d
to
8fce1cb
Compare
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.
Looks good from platform 👍 You might want to have some eyes from IDM too 😉
dd-java-agent/instrumentation/wildfly-9/src/test/java/test/ModulePatchInstrumentation.java
Show resolved
Hide resolved
|
||
public static class ContextualInfo { | ||
private final String serviceName; | ||
private final Map<String, Object> tags = new HashMap<>(); |
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.
Can tags be added concurrently by different threads, or added by one thread while queried by another?
If so then we'll either need a concurrent collection here, or add synchronization to methods accessing tags.
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.
This is not happening since there is 1 deployment per 1 classloader so it cannot happen. For this reason I preferred to use a regular map
internal-api/src/main/java/datadog/trace/api/ClassloaderConfigurationOverrides.java
Outdated
Show resolved
Hide resolved
internal-api/src/main/java/datadog/trace/api/ClassloaderConfigurationOverrides.java
Outdated
Show resolved
Hide resolved
internal-api/src/main/java/datadog/trace/api/ClassloaderConfigurationOverrides.java
Outdated
Show resolved
Hide resolved
return; | ||
} | ||
if (CAN_SPLIT_SERVICE_NAME_BY_DEPLOYMENT | ||
&& contextualInfo.serviceName != null |
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.
small inconsistency: here we're accessing the field, while the line below we're using the getter
also we access it several times in the same method, so consider pulling it into a local variable
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 extracted a local var. It should be better now
...in/java/datadog/trace/instrumentation/wildfly/ResourceReferenceProcessorInstrumentation.java
Outdated
Show resolved
Hide resolved
@@ -1602,10 +1611,16 @@ private DDSpanContext buildSpanContext() { | |||
if (serviceName == null) { | |||
serviceName = traceConfig.getPreferredServiceName(); | |||
} | |||
ClassloaderConfigurationOverrides.ContextualInfo contextualInfo = | |||
ClassloaderConfigurationOverrides.maybeGetContextualInfo(); |
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.
Previously we only called ClassloaderServiceNames
when the span or its parent didn't have a service name.
We're now calling maybeGetContextualInfo
unconditionally for every span which involves:
- a call to
Thread.currentThread().getContextClassLoader()
- a call to
WeakHashMap.get
Do we know how much overhead this could add to span creation? (a microbenchmark would be very helpful)
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 added a benchmark. Even if it can be quite little overhead, as discussed, I put a boolean flag to act as a no-op when the map is empty saving the extra computation in the general non jee case
private static final Function<ClassLoader, ContextualInfo> EMPTY_CONTEXTUAL_INFO_ADDER = | ||
ignored -> new ContextualInfo(null); | ||
|
||
private final WeakHashMap<ClassLoader, ContextualInfo> weakCache = new WeakHashMap<>(); |
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.
WeakHashMap
is not a concurrent collection - to be safe we should really wrap this in synchronizedMap
, but that would have performance implications given we're now accessing the map for every span.
There is WeakConcurrentMap
but we cannot use that directly in internal-api
because it would leak that implementation onto the application class-path. You might therefore need to move this cache to inside dd-trace-core
or somewhere similarly isolated.
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.
@mcculls thanks. I protected the write path with a lock. The read path is not needing to be thread safe. There could be parallel deployment needing to write the map. However the read are usually happening afterwards.
I also added a quick optimization using a volatile flag in order to skip any costly operation when the map is just empty
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.
Just one concern - we're now accessing the weak cache for every span regardless whether this feature is enabled or not. The current implementation used for the weak cache is not thread-safe and should really be wrapped in synchronizedMap
.
Given this I'd like to see some microbenchmarking done to check how much overhead this will add. (We also need to resolve whether synchronizedMap
is OK or should we consider using WeakConcurrentMap
indirectly - benchmarking will also help with that)
6c4e4d7
to
9423b4c
Compare
904bee2
to
762133c
Compare
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.
LGTM
…urationOverrides.java Co-authored-by: Bruce Bujon <PerfectSlayer@users.noreply.github.com>
…urationOverrides.java Co-authored-by: Stuart McCulloch <stuart.mcculloch@datadoghq.com>
…urationOverrides.java Co-authored-by: Stuart McCulloch <stuart.mcculloch@datadoghq.com>
762133c
to
e8e8281
Compare
* Use env-entry to add tags per webapp deployment * fix gradle file * Migrate to hasmethodadvice * exclude classes from coverage * codenarc * add more repos * jacoco * Update internal-api/src/main/java/datadog/trace/api/ClassloaderConfigurationOverrides.java Co-authored-by: Bruce Bujon <PerfectSlayer@users.noreply.github.com> * review * use our named * more coverage * Update internal-api/src/main/java/datadog/trace/api/ClassloaderConfigurationOverrides.java Co-authored-by: Stuart McCulloch <stuart.mcculloch@datadoghq.com> * Update internal-api/src/main/java/datadog/trace/api/ClassloaderConfigurationOverrides.java Co-authored-by: Stuart McCulloch <stuart.mcculloch@datadoghq.com> * review * add jmh * optimize * widen muzzle excludes * exclude lazy from branch coverage * clean * Do not set contextual service name if jee-split-by-deployment is not enabled --------- Co-authored-by: Bruce Bujon <PerfectSlayer@users.noreply.github.com> Co-authored-by: Stuart McCulloch <stuart.mcculloch@datadoghq.com>
What Does This Do
This PR concerns JEE web deployments only.
It adds the possibility to configure a set of tags to be added to each local root span per web deployment.
The tags are expressed as part of
env-entry
on theweb.xml
.A tag can be added by declaring an env entry bindable on the namespace
java:comp/env/datadog/tags/
An example:
This mechanism can also be used to configure a separate service name for each webapp since the tag
service
has a special meaning andTagInterceptor
use its value to set the service nameExample:
That feature works today only with tomcat 9+ and wildfly 9+ .
Motivation
Additional Notes
Contributor Checklist
type:
and (comp:
orinst:
) labels in addition to any usefull labelsclose
,fix
or any linking keywords when referencing an issue.Use
solves
instead, and assign the PR milestone to the issueJira ticket: [PROJ-IDENT]