Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/main/java/io/sqreen/powerwaf/ByteBufferSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import java.math.BigDecimal;

import io.sqreen.powerwaf.metrics.InputTruncatedType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -94,7 +93,7 @@ private static void doSerialize(Arena arena, Powerwaf.Limits limits, PWArgsBuffe
parameterName.length(), limits.maxStringSize);
parameterName = parameterName.substring(0, limits.maxStringSize);
if (metrics != null) {
metrics.incrementWafInputsTruncatedCount(InputTruncatedType.STRING_TOO_LONG);
metrics.incrementWafInputsTruncatedStringTooLongCount();
// TODO - ADD METRIC FOR UNTRUNCATED SIZE
}
}
Expand All @@ -111,14 +110,14 @@ private static void doSerialize(Arena arena, Powerwaf.Limits limits, PWArgsBuffe
LOGGER.debug("Ignoring element, for maxElements was exceeded");
}
if (metrics != null) {
metrics.incrementWafInputsTruncatedCount(InputTruncatedType.LIST_MAP_TOO_LARGE);
metrics.incrementWafInputsTruncatedListMapTooLargeCount();
}
} else if (depthRemaining <= 0) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Ignoring element, for maxDepth was exceeded");
}
if (metrics != null) {
metrics.incrementWafInputsTruncatedCount(InputTruncatedType.OBJECT_TOO_DEEP);
metrics.incrementWafInputsTruncatedObjectTooDeepCount();
}
}
// write empty map
Expand All @@ -139,7 +138,7 @@ private static void doSerialize(Arena arena, Powerwaf.Limits limits, PWArgsBuffe
svalue.length(), limits.maxStringSize);
svalue = svalue.subSequence(0, limits.maxStringSize);
if (metrics != null) {
metrics.incrementWafInputsTruncatedCount(InputTruncatedType.STRING_TOO_LONG);
metrics.incrementWafInputsTruncatedStringTooLongCount();
// TODO - ADD METRIC FOR UNTRUNCATED SIZE
}
}
Expand Down
47 changes: 20 additions & 27 deletions src/main/java/io/sqreen/powerwaf/PowerwafMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

package io.sqreen.powerwaf;

import io.sqreen.powerwaf.metrics.InputTruncatedType;

import java.util.concurrent.atomic.AtomicLong;

public class PowerwafMetrics {
Expand All @@ -35,32 +33,27 @@ public long getTotalDdwafRunTimeNs() {
return totalDdwafRunTimeNs.get();
}

public long getWafInputsTruncatedCount(InputTruncatedType type) {
switch (type) {
case STRING_TOO_LONG:
return wafInputsTruncatedStringTooLongCount.get();
case LIST_MAP_TOO_LARGE:
return wafInputsTruncatedListMapTooLargeCount.get();
case OBJECT_TOO_DEEP:
return wafInputsTruncatedObjectTooDeepCount.get();
default:
return 0L;
}
public long getWafInputsTruncatedStringTooLongCount() {
return wafInputsTruncatedStringTooLongCount.get();
}

public long getWafInputsTruncatedListMapTooLargeCount() {
return wafInputsTruncatedListMapTooLargeCount.get();
}

public long getWafInputsTruncatedObjectTooDeepCount() {
return wafInputsTruncatedObjectTooDeepCount.get();
}

protected void incrementWafInputsTruncatedStringTooLongCount() {
wafInputsTruncatedStringTooLongCount.incrementAndGet();
}

protected void incrementWafInputsTruncatedListMapTooLargeCount() {
wafInputsTruncatedListMapTooLargeCount.incrementAndGet();
}

protected void incrementWafInputsTruncatedCount(InputTruncatedType type) {
switch (type) {
case STRING_TOO_LONG:
wafInputsTruncatedStringTooLongCount.incrementAndGet();
return;
case LIST_MAP_TOO_LARGE:
wafInputsTruncatedListMapTooLargeCount.incrementAndGet();
return;
case OBJECT_TOO_DEEP:
wafInputsTruncatedObjectTooDeepCount.incrementAndGet();
return;
default:
return;
}
protected void incrementWafInputsTruncatedObjectTooDeepCount() {
wafInputsTruncatedObjectTooDeepCount.incrementAndGet();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

package io.sqreen.powerwaf

import io.sqreen.powerwaf.metrics.InputTruncatedType
import org.junit.After
import org.junit.Before
import org.junit.Test
Expand Down Expand Up @@ -383,8 +382,8 @@ class ByteBufferSerializerTests implements PowerwafTrait {
}

private void assertMetrics(Long countStringTooLong, Long countListMapTooLarge, Long countObjectTooDeep) {
assertThat(metrics.getWafInputsTruncatedCount(InputTruncatedType.STRING_TOO_LONG), is(countStringTooLong))
assertThat(metrics.getWafInputsTruncatedCount(InputTruncatedType.LIST_MAP_TOO_LARGE), is(countListMapTooLarge))
assertThat(metrics.getWafInputsTruncatedCount(InputTruncatedType.OBJECT_TOO_DEEP), is(countObjectTooDeep))
assertThat(metrics.wafInputsTruncatedStringTooLongCount, is(countStringTooLong))
assertThat(metrics.wafInputsTruncatedListMapTooLargeCount, is(countListMapTooLarge))
assertThat(metrics.wafInputsTruncatedObjectTooDeepCount, is(countObjectTooDeep))
}
}