Skip to content

Commit fc4c69c

Browse files
committed
Create metric: appsec.waf.error
1 parent 375a464 commit fc4c69c

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

dd-java-agent/appsec/src/main/java/com/datadog/appsec/gateway/AppSecRequestContext.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ public class AppSecRequestContext implements DataBundle, Closeable {
130130
private volatile int raspInternalErrors;
131131
private volatile int raspInvalidObjectErrors;
132132
private volatile int raspInvalidArgumentErrors;
133+
private volatile int wafInternalErrors;
134+
private volatile int wafInvalidObjectErrors;
135+
private volatile int wafInvalidArgumentErrors;
133136

134137
// keep a reference to the last published usr.id
135138
private volatile String userId;
@@ -157,6 +160,17 @@ public class AppSecRequestContext implements DataBundle, Closeable {
157160
AtomicIntegerFieldUpdater.newUpdater(
158161
AppSecRequestContext.class, "raspInvalidArgumentErrors");
159162

163+
private static final AtomicIntegerFieldUpdater<AppSecRequestContext> WAF_INTERNAL_ERRORS_UPDATER =
164+
AtomicIntegerFieldUpdater.newUpdater(AppSecRequestContext.class, "wafInternalErrors");
165+
private static final AtomicIntegerFieldUpdater<AppSecRequestContext>
166+
WAF_INVALID_OBJECT_ERRORS_UPDATER =
167+
AtomicIntegerFieldUpdater.newUpdater(
168+
AppSecRequestContext.class, "wafInvalidObjectErrors");
169+
private static final AtomicIntegerFieldUpdater<AppSecRequestContext>
170+
WAF_INVALID_ARGUMENT_ERRORS_UPDATER =
171+
AtomicIntegerFieldUpdater.newUpdater(
172+
AppSecRequestContext.class, "wafInvalidArgumentErrors");
173+
160174
// to be called by the Event Dispatcher
161175
public void addAll(DataBundle newData) {
162176
for (Map.Entry<Address<?>, Object> entry : newData) {
@@ -222,6 +236,22 @@ public void increaseRaspErrorCode(int code) {
222236
}
223237
}
224238

239+
public void increaseWafErrorCode(int code) {
240+
switch (code) {
241+
case DD_WAF_RUN_INTERNAL_ERROR:
242+
WAF_INTERNAL_ERRORS_UPDATER.incrementAndGet(this);
243+
break;
244+
case DD_WAF_RUN_INVALID_OBJECT_ERROR:
245+
WAF_INVALID_OBJECT_ERRORS_UPDATER.incrementAndGet(this);
246+
break;
247+
case DD_WAF_RUN_INVALID_ARGUMENT_ERROR:
248+
WAF_INVALID_ARGUMENT_ERRORS_UPDATER.incrementAndGet(this);
249+
break;
250+
default:
251+
break;
252+
}
253+
}
254+
225255
public int getWafTimeouts() {
226256
return wafTimeouts;
227257
}
@@ -232,11 +262,11 @@ public int getRaspTimeouts() {
232262

233263
public int getRaspError(int code) {
234264
switch (code) {
235-
case -3:
265+
case DD_WAF_RUN_INTERNAL_ERROR:
236266
return raspInternalErrors;
237-
case -2:
267+
case DD_WAF_RUN_INVALID_OBJECT_ERROR:
238268
return raspInvalidObjectErrors;
239-
case -1:
269+
case DD_WAF_RUN_INVALID_ARGUMENT_ERROR:
240270
return raspInvalidArgumentErrors;
241271
default:
242272
return 0;

0 commit comments

Comments
 (0)