Skip to content

Commit ef6f9ce

Browse files
committed
Cleanup InstrumenterModule enablement
* All instrumentations now declare a target system which they fall under * We introduce COMMON as the system for instrumentations shared across all systems and SECURITY for instrumentations shared between APPSEC and IAST * We now log when an instrumentation has been disabled * Special enablement of security instrumentations shared between APPSEC and IAST has been moved to `isEnabled` which is now told the enabled systems
1 parent 22dfb2d commit ef6f9ce

File tree

51 files changed

+233
-145
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+233
-145
lines changed

dd-java-agent/agent-builder/src/main/java/datadog/trace/agent/tooling/AgentInstaller.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,18 @@ public static ClassFileTransformer installBytebuddyAgent(
200200

201201
int installedCount = 0;
202202
for (InstrumenterModule module : instrumenterModules) {
203-
if (!module.isApplicable(enabledSystems)) {
203+
if (!enabledSystems.contains(module.targetSystem())) {
204204
if (DEBUG) {
205205
log.debug("Not applicable - instrumentation.class={}", module.getClass().getName());
206206
}
207207
continue;
208208
}
209+
if (!module.isEnabled(enabledSystems)) {
210+
if (DEBUG) {
211+
log.debug("Not enabled - instrumentation.class={}", module.getClass().getName());
212+
}
213+
continue;
214+
}
209215
if (DEBUG) {
210216
log.debug("Loading - instrumentation.class={}", module.getClass().getName());
211217
}
@@ -291,7 +297,7 @@ public InstrumenterModule next() {
291297

292298
public static Set<InstrumenterModule.TargetSystem> getEnabledSystems() {
293299
EnumSet<InstrumenterModule.TargetSystem> enabledSystems =
294-
EnumSet.noneOf(InstrumenterModule.TargetSystem.class);
300+
EnumSet.of(InstrumenterModule.TargetSystem.COMMON);
295301
InstrumenterConfig cfg = InstrumenterConfig.get();
296302
if (cfg.isTraceEnabled()) {
297303
enabledSystems.add(InstrumenterModule.TargetSystem.TRACING);
@@ -300,9 +306,11 @@ public static Set<InstrumenterModule.TargetSystem> getEnabledSystems() {
300306
enabledSystems.add(InstrumenterModule.TargetSystem.PROFILING);
301307
}
302308
if (cfg.getAppSecActivation() != ProductActivation.FULLY_DISABLED) {
309+
enabledSystems.add(InstrumenterModule.TargetSystem.SECURITY);
303310
enabledSystems.add(InstrumenterModule.TargetSystem.APPSEC);
304311
}
305312
if (cfg.getIastActivation() != ProductActivation.FULLY_DISABLED) {
313+
enabledSystems.add(InstrumenterModule.TargetSystem.SECURITY);
306314
enabledSystems.add(InstrumenterModule.TargetSystem.IAST);
307315
}
308316
if (cfg.isCiVisibilityEnabled()) {

dd-java-agent/agent-builder/src/main/java/datadog/trace/agent/tooling/CombiningTransformerBuilder.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,15 @@ public CombiningTransformerBuilder(
9393

9494
/** Builds matchers and transformers for an instrumentation module and its members. */
9595
public void applyInstrumentation(InstrumenterModule module) {
96-
if (module.isEnabled()) {
97-
int instrumentationId = instrumenterIndex.instrumentationId(module);
98-
if (instrumentationId < 0) {
99-
// this is a non-indexed instrumentation configured at runtime
100-
instrumentationId = nextRuntimeInstrumentationId++;
101-
}
102-
InstrumenterState.registerInstrumentation(module, instrumentationId);
103-
prepareInstrumentation(module, instrumentationId);
104-
for (Instrumenter member : module.typeInstrumentations()) {
105-
buildTypeInstrumentation(member);
106-
}
96+
int instrumentationId = instrumenterIndex.instrumentationId(module);
97+
if (instrumentationId < 0) {
98+
// this is a non-indexed instrumentation configured at runtime
99+
instrumentationId = nextRuntimeInstrumentationId++;
100+
}
101+
InstrumenterState.registerInstrumentation(module, instrumentationId);
102+
prepareInstrumentation(module, instrumentationId);
103+
for (Instrumenter member : module.typeInstrumentations()) {
104+
buildTypeInstrumentation(member);
107105
}
108106
}
109107

dd-java-agent/agent-tooling/src/jmh/java/datadog/trace/agent/tooling/bytebuddy/csi/CallSiteBenchmarkInstrumentation.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ public CallSiteBenchmarkInstrumentation() {
1818
}
1919

2020
@Override
21-
public ElementMatcher<TypeDescription> callerType() {
22-
return CallSiteMatcher.INSTANCE;
21+
public TargetSystem targetSystem() {
22+
return TargetSystem.COMMON; // always active during this benchmark
2323
}
2424

2525
@Override
26-
public boolean isEnabled() {
27-
return "callSite".equals(System.getProperty("dd.benchmark.instrumentation", ""));
26+
public ElementMatcher<TypeDescription> callerType() {
27+
return CallSiteMatcher.INSTANCE;
2828
}
2929

3030
@Override
31-
public boolean isApplicable(final Set<TargetSystem> enabledSystems) {
32-
return true;
31+
public boolean isEnabled(Set<TargetSystem> enabledSystems) {
32+
return "callSite".equals(System.getProperty("dd.benchmark.instrumentation", ""));
3333
}
3434

3535
@Override

dd-java-agent/agent-tooling/src/jmh/java/datadog/trace/agent/tooling/bytebuddy/csi/CalleeBenchmarkInstrumentation.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ public String[] helperClassNames() {
3434
}
3535

3636
@Override
37-
public boolean isEnabled() {
38-
return "callee".equals(System.getProperty("dd.benchmark.instrumentation", ""));
37+
public TargetSystem targetSystem() {
38+
return TargetSystem.COMMON; // always active during this benchmark
3939
}
4040

4141
@Override
42-
public boolean isApplicable(final Set<TargetSystem> enabledSystems) {
43-
return true;
42+
public boolean isEnabled(Set<TargetSystem> enabledSystems) {
43+
return "callee".equals(System.getProperty("dd.benchmark.instrumentation", ""));
4444
}
4545

4646
public static class Muzzle extends ReferenceMatcher {}

dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/InstrumenterModule.java

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,13 @@ public abstract class InstrumenterModule implements Instrumenter {
3232
/**
3333
* Since several systems share the same instrumentation infrastructure in order to enable only the
3434
* applicable {@link Instrumenter instrumenters} on startup each {@linkplain InstrumenterModule}
35-
* must declare its target system. The systems currently supported include:
36-
*
37-
* <ul>
38-
* <li>{@link TargetSystem#TRACING tracing}
39-
* <li>{@link TargetSystem#PROFILING profiling}
40-
* <li>{@link TargetSystem#APPSEC appsec}
41-
* <li>{@link TargetSystem#IAST iast}
42-
* <li>{@link TargetSystem#CIVISIBILITY ci-visibility}
43-
* <li>{@link TargetSystem#USM usm}
44-
* </ul>
35+
* must declare its target system.
4536
*/
4637
public enum TargetSystem {
38+
COMMON, // instrumentation common to every system
4739
TRACING,
4840
PROFILING,
41+
SECURITY, // instrumentation shared between APPSEC and IAST
4942
APPSEC,
5043
IAST,
5144
CIVISIBILITY,
@@ -177,25 +170,16 @@ public Map<String, String> contextStore() {
177170
return emptyMap();
178171
}
179172

173+
public abstract TargetSystem targetSystem();
174+
180175
protected boolean defaultEnabled() {
181176
return InstrumenterConfig.get().isIntegrationsEnabled();
182177
}
183178

184-
public boolean isEnabled() {
179+
public boolean isEnabled(Set<TargetSystem> enabledSystems) {
185180
return enabled;
186181
}
187182

188-
/**
189-
* Indicates the applicability of an {@linkplain InstrumenterModule} to the given system.<br>
190-
*
191-
* @param enabledSystems a set of all the enabled target systems
192-
* @return {@literal true} if the set of enabled systems contains all the ones required by this
193-
* particular {@linkplain InstrumenterModule}
194-
*/
195-
public boolean isApplicable(Set<TargetSystem> enabledSystems) {
196-
return false;
197-
}
198-
199183
protected final boolean isShortcutMatchingEnabled(boolean defaultToShortcut) {
200184
return InstrumenterConfig.get()
201185
.isIntegrationShortcutMatchingEnabled(singletonList(name()), defaultToShortcut);
@@ -208,8 +192,8 @@ public Tracing(String instrumentationName, String... additionalNames) {
208192
}
209193

210194
@Override
211-
public boolean isApplicable(Set<TargetSystem> enabledSystems) {
212-
return enabledSystems.contains(TargetSystem.TRACING);
195+
public TargetSystem targetSystem() {
196+
return TargetSystem.TRACING;
213197
}
214198
}
215199

@@ -220,13 +204,13 @@ public Profiling(String instrumentationName, String... additionalNames) {
220204
}
221205

222206
@Override
223-
public boolean isApplicable(Set<TargetSystem> enabledSystems) {
224-
return enabledSystems.contains(TargetSystem.PROFILING);
207+
public TargetSystem targetSystem() {
208+
return TargetSystem.PROFILING;
225209
}
226210

227211
@Override
228-
public boolean isEnabled() {
229-
return super.isEnabled()
212+
public boolean isEnabled(Set<TargetSystem> enabledSystems) {
213+
return super.isEnabled(enabledSystems)
230214
&& !ConfigProvider.getInstance()
231215
.getBoolean(ProfilingConfig.PROFILING_ULTRA_MINIMAL, false);
232216
}
@@ -239,8 +223,8 @@ public AppSec(String instrumentationName, String... additionalNames) {
239223
}
240224

241225
@Override
242-
public boolean isApplicable(Set<TargetSystem> enabledSystems) {
243-
return enabledSystems.contains(TargetSystem.APPSEC);
226+
public TargetSystem targetSystem() {
227+
return TargetSystem.APPSEC;
244228
}
245229
}
246230

@@ -251,14 +235,22 @@ public Iast(String instrumentationName, String... additionalNames) {
251235
super(instrumentationName, additionalNames);
252236
}
253237

238+
@Override
239+
public TargetSystem targetSystem() {
240+
return TargetSystem.SECURITY;
241+
}
242+
254243
@Override
255244
public List<Instrumenter> typeInstrumentations() {
256245
preloadClassNames();
257246
return super.typeInstrumentations();
258247
}
259248

260249
@Override
261-
public boolean isApplicable(Set<TargetSystem> enabledSystems) {
250+
public boolean isEnabled(Set<TargetSystem> enabledSystems) {
251+
if (!super.isEnabled(enabledSystems)) {
252+
return false;
253+
}
262254
if (enabledSystems.contains(TargetSystem.IAST)) {
263255
return true;
264256
}
@@ -307,8 +299,8 @@ public Usm(String instrumentationName, String... additionalNames) {
307299
}
308300

309301
@Override
310-
public boolean isApplicable(Set<TargetSystem> enabledSystems) {
311-
return enabledSystems.contains(TargetSystem.USM);
302+
public TargetSystem targetSystem() {
303+
return TargetSystem.USM;
312304
}
313305
}
314306

@@ -319,8 +311,8 @@ public CiVisibility(String instrumentationName, String... additionalNames) {
319311
}
320312

321313
@Override
322-
public boolean isApplicable(Set<TargetSystem> enabledSystems) {
323-
return enabledSystems.contains(TargetSystem.CIVISIBILITY);
314+
public TargetSystem targetSystem() {
315+
return TargetSystem.CIVISIBILITY;
324316
}
325317
}
326318
}

dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/bytebuddy/csi/CallSiteInstrumentation.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public CallSiteInstrumentation(
2121
super(name, additionalNames);
2222
}
2323

24+
@Override
25+
public TargetSystem targetSystem() {
26+
return TargetSystem.SECURITY;
27+
}
28+
2429
@Override
2530
public void typeAdvice(TypeTransformer transformer) {
2631
transformer.applyAdvice(new CallSiteTransformer(name(), advices()));

dd-java-agent/agent-tooling/src/test/groovy/datadog/trace/agent/tooling/InstrumenterIndexTest.groovy

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import spock.lang.Shared
66
class InstrumenterIndexTest extends DDSpecification {
77

88
@Shared
9-
def unknownInstrumentation = new InstrumenterModule('unknown') {}
9+
def unknownInstrumentation = new InstrumenterModule('unknown') {
10+
@Override
11+
InstrumenterModule.TargetSystem targetSystem() {
12+
return InstrumenterModule.TargetSystem.COMMON
13+
}
14+
}
1015

1116
@Shared
1217
def unknownTransformation = new Instrumenter() {}

dd-java-agent/agent-tooling/src/test/java/datadog/trace/agent/test/TestIndexFirstModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ public TestIndexFirstModule() {
77
super("test-index-priority");
88
}
99

10+
@Override
11+
public TargetSystem targetSystem() {
12+
return TargetSystem.COMMON;
13+
}
14+
1015
@Override
1116
public int order() {
1217
return -100; // lower-values applied first

dd-java-agent/agent-tooling/src/test/java/datadog/trace/agent/test/TestIndexLastModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ public TestIndexLastModule() {
77
super("test-index-priority");
88
}
99

10+
@Override
11+
public TargetSystem targetSystem() {
12+
return TargetSystem.COMMON;
13+
}
14+
1015
@Override
1116
public int order() {
1217
return 100; // higher-values applied last

dd-java-agent/agent-tooling/src/test/java/datadog/trace/agent/test/TestIndexMultiModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ public TestIndexMultiModule() {
1111
super("test-index-multi");
1212
}
1313

14+
@Override
15+
public TargetSystem targetSystem() {
16+
return TargetSystem.COMMON;
17+
}
18+
1419
@Override
1520
public List<Instrumenter> typeInstrumentations() {
1621
return asList(

0 commit comments

Comments
 (0)