1
1
package com .datadog .debugger .agent ;
2
2
3
- import com .datadog .debugger .probe .ExceptionProbe ;
4
3
import com .datadog .debugger .probe .LogProbe ;
5
4
import com .datadog .debugger .probe .MetricProbe ;
6
5
import com .datadog .debugger .probe .ProbeDefinition ;
12
11
import java .util .Collection ;
13
12
import java .util .List ;
14
13
import java .util .Objects ;
14
+ import java .util .stream .Collectors ;
15
+ import java .util .stream .Stream ;
15
16
16
17
/**
17
18
* Stores debugger configuration for a service with: - Probe definitions - filters (allow/deny) -
@@ -63,46 +64,47 @@ public int hashCode() {
63
64
@ Json (name = "id" )
64
65
private final String service ;
65
66
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 ;
67
+ private transient List <ProbeDefinition > probes = new ArrayList <>();
68
+ private Collection <MetricProbe > metricProbes = new ArrayList <>();
69
+ private Collection <LogProbe > logProbes = new ArrayList <>();
70
+ private Collection <SpanProbe > spanProbes = new ArrayList <>();
71
+ private Collection <TriggerProbe > triggerProbes = new ArrayList <>();
72
+ private Collection <SpanDecorationProbe > spanDecorationProbes = new ArrayList <>();
71
73
private final FilterList allowList ;
72
74
private final FilterList denyList ;
73
75
private final LogProbe .Sampling sampling ;
74
76
75
- public Configuration (String service , Collection < LogProbe > logProbes ) {
76
- this (service , null , logProbes , null );
77
+ public Configuration (String serviceName , List <? extends ProbeDefinition > probes ) {
78
+ this (serviceName , probes , null , null , null );
77
79
}
78
80
79
81
public Configuration (
80
82
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 ,
83
+ List <? extends ProbeDefinition > probes ,
94
84
FilterList allowList ,
95
85
FilterList denyList ,
96
86
LogProbe .Sampling sampling ) {
97
87
this .service = serviceName ;
98
- this .metricProbes = metricProbes ;
99
- this .logProbes = logProbes ;
100
- this .spanProbes = spanProbes ;
101
- this .triggerProbes = triggerProbes ;
102
- this .spanDecorationProbes = spanDecorationProbes ;
103
88
this .allowList = allowList ;
104
89
this .denyList = denyList ;
105
90
this .sampling = sampling ;
91
+ probes .forEach (this ::add );
92
+ }
93
+
94
+ private void add (ProbeDefinition p ) {
95
+ if (p instanceof LogProbe ) {
96
+ logProbes .add ((LogProbe ) p );
97
+ } else if (p instanceof MetricProbe ) {
98
+ metricProbes .add ((MetricProbe ) p );
99
+ } else if (p instanceof SpanProbe ) {
100
+ spanProbes .add ((SpanProbe ) p );
101
+ } else if (p instanceof SpanDecorationProbe ) {
102
+ spanDecorationProbes .add ((SpanDecorationProbe ) p );
103
+ } else if (p instanceof TriggerProbe ) {
104
+ triggerProbes .add ((TriggerProbe ) p );
105
+ } else {
106
+ probes .add (p );
107
+ }
106
108
}
107
109
108
110
public String getService () {
@@ -141,24 +143,12 @@ public LogProbe.Sampling getSampling() {
141
143
return sampling ;
142
144
}
143
145
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 ;
146
+ public List <ProbeDefinition > getDefinitions () {
147
+ return Stream .of (
148
+ triggerProbes , metricProbes , logProbes , spanProbes , spanDecorationProbes , probes )
149
+ .filter (Objects ::nonNull )
150
+ .flatMap (Collection ::stream )
151
+ .collect (Collectors .toList ());
162
152
}
163
153
164
154
@ Generated
@@ -167,10 +157,8 @@ public String toString() {
167
157
return "DebuggerConfiguration{"
168
158
+ "service="
169
159
+ service
170
- + ", metricProbes="
171
- + metricProbes
172
- + ", logProbes="
173
- + logProbes
160
+ + ", probes="
161
+ + getDefinitions ()
174
162
+ ", allowList="
175
163
+ allowList
176
164
+ ", denyList="
@@ -183,12 +171,15 @@ public String toString() {
183
171
@ Generated
184
172
@ Override
185
173
public boolean equals (Object o ) {
186
- if (this == o ) return true ;
187
- if (o == null || getClass () != o .getClass ()) return false ;
174
+ if (this == o ) {
175
+ return true ;
176
+ }
177
+ if (o == null || getClass () != o .getClass ()) {
178
+ return false ;
179
+ }
188
180
Configuration that = (Configuration ) o ;
189
181
return Objects .equals (service , that .service )
190
- && Objects .equals (metricProbes , that .metricProbes )
191
- && Objects .equals (logProbes , that .logProbes )
182
+ && Objects .equals (probes , that .probes )
192
183
&& Objects .equals (allowList , that .allowList )
193
184
&& Objects .equals (denyList , that .denyList )
194
185
&& Objects .equals (sampling , that .sampling );
@@ -197,7 +188,7 @@ public boolean equals(Object o) {
197
188
@ Generated
198
189
@ Override
199
190
public int hashCode () {
200
- return Objects .hash (service , metricProbes , logProbes , allowList , denyList , sampling );
191
+ return Objects .hash (service , probes , allowList , denyList , sampling );
201
192
}
202
193
203
194
public static Configuration .Builder builder () {
@@ -206,13 +197,13 @@ public static Configuration.Builder builder() {
206
197
207
198
public static class Builder {
208
199
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 ;
200
+
201
+ private final List <ProbeDefinition > probes = new ArrayList <>();
202
+
214
203
private FilterList allowList = null ;
204
+
215
205
private FilterList denyList = null ;
206
+
216
207
private LogProbe .Sampling sampling = null ;
217
208
218
209
public Configuration .Builder setService (String service ) {
@@ -224,53 +215,14 @@ public Configuration.Builder add(Collection<? extends ProbeDefinition> definitio
224
215
if (definitions == null ) {
225
216
return this ;
226
217
}
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
- }
218
+ probes .addAll (definitions );
234
219
return this ;
235
220
}
236
221
237
- public Configuration .Builder add (MetricProbe probe ) {
238
- if ( metricProbes == null ) {
239
- metricProbes = new ArrayList <>( );
222
+ public Configuration .Builder add (ProbeDefinition ... probes ) {
223
+ for ( ProbeDefinition probe : probes ) {
224
+ this . probes . add ( probe );
240
225
}
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 );
250
- return this ;
251
- }
252
-
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 );
274
226
return this ;
275
227
}
276
228
@@ -281,66 +233,6 @@ public Configuration.Builder add(LogProbe.Sampling newSampling) {
281
233
return this ;
282
234
}
283
235
284
- 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 ;
292
- }
293
-
294
- 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 ;
302
- }
303
-
304
- 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 ;
312
- }
313
-
314
- 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 ;
322
- }
323
-
324
- 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 ;
332
- }
333
-
334
- 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 ;
342
- }
343
-
344
236
public Configuration .Builder addAllowList (FilterList newAllowList ) {
345
237
if (newAllowList == null ) {
346
238
return this ;
@@ -370,32 +262,8 @@ public Configuration.Builder setSampling(LogProbe.Sampling sampling) {
370
262
return this ;
371
263
}
372
264
373
- public Configuration .Builder add (Configuration other ) {
374
- if (other .service != null ) {
375
- this .service = other .service ;
376
- }
377
- addMetricProbes (other .getMetricProbes ());
378
- addLogProbes (other .getLogProbes ());
379
- addSpanProbes (other .getSpanProbes ());
380
- addTriggerProbes (other .getTriggerProbes ());
381
- addSpanDecorationProbes (other .getSpanDecorationProbes ());
382
- addAllowList (other .getAllowList ());
383
- addDenyList (other .getDenyList ());
384
- add (other .getSampling ());
385
- return this ;
386
- }
387
-
388
265
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 );
266
+ return new Configuration (service , probes , allowList , denyList , sampling );
399
267
}
400
268
}
401
269
}
0 commit comments