Skip to content

Commit

Permalink
Fix NPE in RASP metrics (#7654)
Browse files Browse the repository at this point in the history
(cherry picked from commit 4ef9a80)
  • Loading branch information
smola committed Sep 23, 2024
1 parent 352673a commit ddb9de2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public class AppSecRequestContext implements DataBundle, Closeable {
// set after additive is set
private volatile PowerwafMetrics wafMetrics;
private volatile PowerwafMetrics raspMetrics;
private AtomicInteger raspMetricsCounter;
private final AtomicInteger raspMetricsCounter = new AtomicInteger(0);
private volatile boolean blocked;
private volatile int timeouts;

Expand Down Expand Up @@ -182,7 +182,6 @@ public Additive getOrCreateAdditive(PowerwafContext ctx, boolean createMetrics,
}
if (isRasp && raspMetrics == null) {
this.raspMetrics = ctx.createMetrics();
this.raspMetricsCounter = new AtomicInteger(0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ public void processTraceSegment(
segment.setTagTop(RASP_TOTAL_DURATION_US_TAG, raspMetrics.getTotalRunTimeNs() / 1000L);
segment.setTagTop(
RASP_TOTAL_DDWAF_RUN_DURATION_US_TAG, raspMetrics.getTotalDdwafRunTimeNs() / 1000L);
segment.setTagTop(RASP_RULE_EVAL, ctx.getRaspMetricsCounter().get());
final int raspCount = ctx.getRaspMetricsCounter().get();
if (raspCount > 0) {
segment.setTagTop(RASP_RULE_EVAL, raspCount);
}
}

String rulesVersion = this.rulesVersion;
Expand Down

0 comments on commit ddb9de2

Please sign in to comment.