Skip to content

Commit 66af130

Browse files
committed
WIP
1 parent 5b58772 commit 66af130

File tree

11 files changed

+157
-404
lines changed

11 files changed

+157
-404
lines changed

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/Configuration.java

Lines changed: 56 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Collection;
1313
import java.util.List;
1414
import java.util.Objects;
15+
import java.util.stream.Collectors;
1516

1617
/**
1718
* Stores debugger configuration for a service with: - Probe definitions - filters (allow/deny) -
@@ -22,6 +23,7 @@ public class Configuration {
2223
/** Stores classes & packages filtering (allow or deny lists) */
2324
public static class FilterList {
2425
private final List<String> packagePrefixes;
26+
2527
private final List<String> classes;
2628

2729
public FilterList(List<String> packagePrefixes, List<String> classes) {
@@ -46,8 +48,12 @@ public String toString() {
4648
@Generated
4749
@Override
4850
public boolean equals(Object o) {
49-
if (this == o) return true;
50-
if (o == null || getClass() != o.getClass()) return false;
51+
if (this == o) {
52+
return true;
53+
}
54+
if (o == null || getClass() != o.getClass()) {
55+
return false;
56+
}
5157
FilterList allowList = (FilterList) o;
5258
return Objects.equals(packagePrefixes, allowList.packagePrefixes)
5359
&& Objects.equals(classes, allowList.classes);
@@ -63,43 +69,26 @@ public int hashCode() {
6369
@Json(name = "id")
6470
private final String service;
6571

66-
private final Collection<MetricProbe> metricProbes;
67-
private final Collection<LogProbe> logProbes;
68-
private final Collection<SpanProbe> spanProbes;
69-
private final Collection<TriggerProbe> triggerProbes;
70-
private final Collection<SpanDecorationProbe> spanDecorationProbes;
72+
private final List<ProbeDefinition> probes = new ArrayList<>();
73+
7174
private final FilterList allowList;
75+
7276
private final FilterList denyList;
77+
7378
private final LogProbe.Sampling sampling;
7479

75-
public Configuration(String service, Collection<LogProbe> logProbes) {
76-
this(service, null, logProbes, null);
80+
public Configuration(String serviceName, List<ProbeDefinition> probes) {
81+
this(serviceName, probes, null, null, null);
7782
}
7883

7984
public Configuration(
8085
String serviceName,
81-
Collection<MetricProbe> metricProbes,
82-
Collection<LogProbe> logProbes,
83-
Collection<SpanProbe> spanProbes) {
84-
this(serviceName, metricProbes, logProbes, spanProbes, null, null, null, null, null);
85-
}
86-
87-
public Configuration(
88-
String serviceName,
89-
Collection<MetricProbe> metricProbes,
90-
Collection<LogProbe> logProbes,
91-
Collection<SpanProbe> spanProbes,
92-
Collection<TriggerProbe> triggerProbes,
93-
Collection<SpanDecorationProbe> spanDecorationProbes,
86+
List<ProbeDefinition> probes,
9487
FilterList allowList,
9588
FilterList denyList,
9689
LogProbe.Sampling sampling) {
9790
this.service = serviceName;
98-
this.metricProbes = metricProbes;
99-
this.logProbes = logProbes;
100-
this.spanProbes = spanProbes;
101-
this.triggerProbes = triggerProbes;
102-
this.spanDecorationProbes = spanDecorationProbes;
91+
this.probes.addAll(probes);
10392
this.allowList = allowList;
10493
this.denyList = denyList;
10594
this.sampling = sampling;
@@ -109,24 +98,32 @@ public String getService() {
10998
return service;
11099
}
111100

101+
@SuppressWarnings("unchecked")
102+
public <T extends ProbeDefinition> List<T> getProbes(Class<T> type) {
103+
return (List<T>)
104+
probes.stream()
105+
.filter(probe -> probe.getClass().isAssignableFrom(type))
106+
.collect(Collectors.toList());
107+
}
108+
112109
public Collection<MetricProbe> getMetricProbes() {
113-
return metricProbes;
110+
return getProbes(MetricProbe.class);
114111
}
115112

116113
public Collection<LogProbe> getLogProbes() {
117-
return logProbes;
114+
return getProbes(LogProbe.class);
118115
}
119116

120117
public Collection<SpanProbe> getSpanProbes() {
121-
return spanProbes;
118+
return getProbes(SpanProbe.class);
122119
}
123120

124121
public Collection<TriggerProbe> getTriggerProbes() {
125-
return triggerProbes;
122+
return getProbes(TriggerProbe.class);
126123
}
127124

128125
public Collection<SpanDecorationProbe> getSpanDecorationProbes() {
129-
return spanDecorationProbes;
126+
return getProbes(SpanDecorationProbe.class);
130127
}
131128

132129
public FilterList getAllowList() {
@@ -141,24 +138,8 @@ public LogProbe.Sampling getSampling() {
141138
return sampling;
142139
}
143140

144-
public Collection<ProbeDefinition> getDefinitions() {
145-
Collection<ProbeDefinition> result = new ArrayList<>();
146-
if (triggerProbes != null) {
147-
result.addAll(triggerProbes);
148-
}
149-
if (metricProbes != null) {
150-
result.addAll(metricProbes);
151-
}
152-
if (logProbes != null) {
153-
result.addAll(logProbes);
154-
}
155-
if (spanProbes != null) {
156-
result.addAll(spanProbes);
157-
}
158-
if (spanDecorationProbes != null) {
159-
result.addAll(spanDecorationProbes);
160-
}
161-
return result;
141+
public List<ProbeDefinition> getDefinitions() {
142+
return new ArrayList<>(probes);
162143
}
163144

164145
@Generated
@@ -167,10 +148,8 @@ public String toString() {
167148
return "DebuggerConfiguration{"
168149
+ "service="
169150
+ service
170-
+ ", metricProbes="
171-
+ metricProbes
172-
+ ", logProbes="
173-
+ logProbes
151+
+ ", probes="
152+
+ probes
174153
+ ", allowList="
175154
+ allowList
176155
+ ", denyList="
@@ -183,12 +162,15 @@ public String toString() {
183162
@Generated
184163
@Override
185164
public boolean equals(Object o) {
186-
if (this == o) return true;
187-
if (o == null || getClass() != o.getClass()) return false;
165+
if (this == o) {
166+
return true;
167+
}
168+
if (o == null || getClass() != o.getClass()) {
169+
return false;
170+
}
188171
Configuration that = (Configuration) o;
189172
return Objects.equals(service, that.service)
190-
&& Objects.equals(metricProbes, that.metricProbes)
191-
&& Objects.equals(logProbes, that.logProbes)
173+
&& Objects.equals(probes, that.probes)
192174
&& Objects.equals(allowList, that.allowList)
193175
&& Objects.equals(denyList, that.denyList)
194176
&& Objects.equals(sampling, that.sampling);
@@ -197,7 +179,7 @@ public boolean equals(Object o) {
197179
@Generated
198180
@Override
199181
public int hashCode() {
200-
return Objects.hash(service, metricProbes, logProbes, allowList, denyList, sampling);
182+
return Objects.hash(service, probes, allowList, denyList, sampling);
201183
}
202184

203185
public static Configuration.Builder builder() {
@@ -206,13 +188,13 @@ public static Configuration.Builder builder() {
206188

207189
public static class Builder {
208190
private String service = null;
209-
private List<MetricProbe> metricProbes = null;
210-
private List<LogProbe> logProbes = null;
211-
private List<SpanProbe> spanProbes = null;
212-
private List<TriggerProbe> triggerProbes = null;
213-
private List<SpanDecorationProbe> spanDecorationProbes = null;
191+
192+
private final List<ProbeDefinition> probes = new ArrayList<>();
193+
214194
private FilterList allowList = null;
195+
215196
private FilterList denyList = null;
197+
216198
private LogProbe.Sampling sampling = null;
217199

218200
public Configuration.Builder setService(String service) {
@@ -224,53 +206,12 @@ public Configuration.Builder add(Collection<? extends ProbeDefinition> definitio
224206
if (definitions == null) {
225207
return this;
226208
}
227-
for (ProbeDefinition definition : definitions) {
228-
if (definition instanceof MetricProbe) add((MetricProbe) definition);
229-
if (definition instanceof TriggerProbe) add((TriggerProbe) definition);
230-
if (definition instanceof LogProbe) add((LogProbe) definition);
231-
if (definition instanceof SpanProbe) add((SpanProbe) definition);
232-
if (definition instanceof SpanDecorationProbe) add((SpanDecorationProbe) definition);
233-
}
234-
return this;
235-
}
236-
237-
public Configuration.Builder add(MetricProbe probe) {
238-
if (metricProbes == null) {
239-
metricProbes = new ArrayList<>();
240-
}
241-
metricProbes.add(probe);
242-
return this;
243-
}
244-
245-
public Configuration.Builder add(LogProbe probe) {
246-
if (logProbes == null) {
247-
logProbes = new ArrayList<>();
248-
}
249-
logProbes.add(probe);
209+
probes.addAll(definitions);
250210
return this;
251211
}
252212

253-
public Configuration.Builder add(SpanProbe probe) {
254-
if (spanProbes == null) {
255-
spanProbes = new ArrayList<>();
256-
}
257-
spanProbes.add(probe);
258-
return this;
259-
}
260-
261-
public Configuration.Builder add(TriggerProbe probe) {
262-
if (triggerProbes == null) {
263-
triggerProbes = new ArrayList<>();
264-
}
265-
triggerProbes.add(probe);
266-
return this;
267-
}
268-
269-
public Configuration.Builder add(SpanDecorationProbe probe) {
270-
if (spanDecorationProbes == null) {
271-
spanDecorationProbes = new ArrayList<>();
272-
}
273-
spanDecorationProbes.add(probe);
213+
public Configuration.Builder add(ProbeDefinition probe) {
214+
probes.add(probe);
274215
return this;
275216
}
276217

@@ -282,63 +223,27 @@ public Configuration.Builder add(LogProbe.Sampling newSampling) {
282223
}
283224

284225
public Configuration.Builder addMetricProbes(Collection<MetricProbe> probes) {
285-
if (probes == null) {
286-
return this;
287-
}
288-
for (MetricProbe probe : probes) {
289-
add(probe);
290-
}
291-
return this;
226+
return add(probes);
292227
}
293228

294229
public Configuration.Builder addLogProbes(Collection<LogProbe> probes) {
295-
if (probes == null) {
296-
return this;
297-
}
298-
for (LogProbe probe : probes) {
299-
add(probe);
300-
}
301-
return this;
230+
return add(probes);
302231
}
303232

304233
public Builder addExceptionProbes(Collection<ExceptionProbe> probes) {
305-
if (probes == null) {
306-
return this;
307-
}
308-
for (ExceptionProbe probe : probes) {
309-
add(probe);
310-
}
311-
return this;
234+
return add(probes);
312235
}
313236

314237
public Configuration.Builder addSpanProbes(Collection<SpanProbe> probes) {
315-
if (probes == null) {
316-
return this;
317-
}
318-
for (SpanProbe probe : probes) {
319-
add(probe);
320-
}
321-
return this;
238+
return add(probes);
322239
}
323240

324241
public Configuration.Builder addTriggerProbes(Collection<TriggerProbe> probes) {
325-
if (probes == null) {
326-
return this;
327-
}
328-
for (TriggerProbe probe : probes) {
329-
add(probe);
330-
}
331-
return this;
242+
return add(probes);
332243
}
333244

334245
public Configuration.Builder addSpanDecorationProbes(Collection<SpanDecorationProbe> probes) {
335-
if (probes == null) {
336-
return this;
337-
}
338-
for (SpanDecorationProbe probe : probes) {
339-
add(probe);
340-
}
341-
return this;
246+
return add(probes);
342247
}
343248

344249
public Configuration.Builder addAllowList(FilterList newAllowList) {
@@ -386,16 +291,7 @@ public Configuration.Builder add(Configuration other) {
386291
}
387292

388293
public Configuration build() {
389-
return new Configuration(
390-
service,
391-
metricProbes,
392-
logProbes,
393-
spanProbes,
394-
triggerProbes,
395-
spanDecorationProbes,
396-
allowList,
397-
denyList,
398-
sampling);
294+
return new Configuration(service, probes, allowList, denyList, sampling);
399295
}
400296
}
401297
}

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/codeorigin/DefaultCodeOriginRecorder.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ private CodeOriginProbe createProbe(String fingerPrint, boolean entry, Where whe
7474
CodeOriginProbe probe;
7575
AgentSpan span = AgentTracer.activeSpan();
7676

77-
probe =
78-
new CodeOriginProbe(
79-
new ProbeId(UUID.randomUUID().toString(), 0), entry, where, maxUserFrames);
77+
probe = new CodeOriginProbe(new ProbeId(UUID.randomUUID().toString(), 0), entry, where);
8078
addFingerprint(fingerPrint, probe);
8179

8280
installProbe(probe);

0 commit comments

Comments
 (0)