8000 Create metric: appsec.rasp.error by sezen-datadog · Pull Request #8364 · DataDog/dd-trace-java · GitHub
[go: up one dir, main page]

Skip to content

Cre 8000 ate metric: appsec.rasp.error #8364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
pr
  • Loading branch information
sezen-datadog committed Feb 14, 2025
commit c8581b22d22c3f328a86931e07efc7e07cb3d853
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public class AppSecRequestContext implements DataBundle, Closeable {
public static final Set<String> RESPONSE_HEADERS_ALLOW_LIST =
new TreeSet<>(
Arrays.asList("content-length", "content-type", "content-encoding", "content-language"));
private static final int DD_WAF_RUN_INTERNAL_ERROR = -3;
private static final int DD_WAF_RUN_INVALID_OBJECT_ERROR = -2;
private static final int DD_WAF_RUN_INVALID_ARGUMENT_ERROR = -1;
public static final int DD_WAF_RUN_INTERNAL_ERROR = -3;
public static final int DD_WAF_RUN_INVALID_OBJECT_ERROR = -2;
public static final int DD_WAF_RUN_INVALID_ARGUMENT_ERROR = -1;

static {
REQUEST_HEADERS_ALLOW_LIST.addAll(DEFAULT_REQUEST_HEADERS_ALLOW_LIST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,14 @@ class AppSecRequestContextSpecification extends DDSpecification {

def "test increase and get RaspErrors"() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more readable if you also use the constants in the tests :)

DD_WAF_RUN_INTERNAL_ERROR
DD_WAF_RUN_INVALID_OBJECT_ERROR
DD_WAF_RUN_INVALID_ARGUMENT_ERROR

when:
ctx.increaseRaspErrorCode(-3)
ctx.increaseRaspErrorCode(-3)
ctx.increaseRaspErrorCode(-2)
ctx.increaseRaspErrorCode(AppSecRequestContext.DD_WAF_RUN_INTERNAL_ERROR)
ctx.increaseRaspErrorCode(AppSecRequestContext.DD_WAF_RUN_INTERNAL_ERROR)
ctx.increaseRaspErrorCode(AppSecRequestContext.DD_WAF_RUN_INVALID_OBJECT_ERROR)

then:
ctx.getRaspError(-3) == 2
ctx.getRaspError(-2) == 1
ctx.getRaspError(-1) == 0
ctx.getRaspError(AppSecRequestContext.DD_WAF_RUN_INTERNAL_ERROR) == 2
ctx.getRaspError(AppSecRequestContext.DD_WAF_RUN_INVALID_OBJECT_ERROR) == 1
ctx.getRaspError(AppSecRequestContext.DD_WAF_RUN_INVALID_ARGUMENT_ERROR) == 0
ctx.getRaspError(0) == 0
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems that we can also use the constants for the codes in this test

< 8000 /div>

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import java.util.concurrent.TimeUnit

class WafMetricCollectorTest extends DDSpecification {

public static final int DD_WAF_RUN_INTERNAL_ERROR = -3
public static final int DD_WAF_RUN_INVALID_OBJECT_ERROR = -2

def "no metrics - drain empty list"() {
when:
WafMetricCollector.get().prepareMetrics()
Expand All @@ -32,8 +35,8 @@ class WafMetricCollectorTest extends DDSpecification {
WafMetricCollector.get().raspRuleMatch(RuleType.SQL_INJECTION)
WafMetricCollector.get().raspRuleEval(RuleType.SQL_INJECTION)
WafMetricCollector.get().raspTimeout(RuleType.SQL_INJECTION)
WafMetricCollector.get().raspErrorCode(RuleType.SHELL_INJECTION, -3)
WafMetricCollector.get().raspErrorCode(RuleType.SQL_INJECTION, -2)
WafMetricCollector.get().raspErrorCode(RuleType.SHELL_INJECTION, DD_WAF_RUN_INTERNAL_ERROR)
WafMetricCollector.get().raspErrorCode(RuleType.SQL_INJECTION, DD_WAF_RUN_INVALID_OBJECT_ERROR)

WafMetricCollector.get().prepareMetrics()

Expand Down Expand Up @@ -144,15 +147,20 @@ class WafMetricCollectorTest extends DDSpecification {
'rule_type:command_injection',
'rule_variant:shell',
'event_rules_version:rules.3',
'waf_error:-3'
'waf_error:' + DD_WAF_RUN_INTERNAL_ERROR
].toSet()

def raspInvalidObjectCode = (WafMetricCollector.RaspError)metrics[11]
raspInvalidObjectCode.type == 'count'
raspInvalidObjectCode.value == 1
raspInvalidObjectCode.namespace == 'appsec'
raspInvalidObjectCode.metricName == 'rasp.error'
raspInvalidObjectCode.tags.toSet() == ['rule_type:sql_injection', 'waf_version:waf_ver1', 'waf_error:-2'].toSet()
raspInvalidObjectCode.tags.toSet() == [
'rule_type:sql_injection',
'waf_version:waf_ver1',
'waf_error:' + DD_WAF_RUN_INVALID_OBJECT_ERROR
]
.toSet()
}

def "overflowing WafMetricCollector does not crash"() {
Expand Down Expand Up @@ -326,7 +334,7 @@ class WafMetricCollectorTest extends DDSpecification {
WafMetricCollector.get().raspRuleMatch(ruleType)
WafMetricCollector.get().raspRuleEval(ruleType)
WafMetricCollector.get().raspTimeout(ruleType)
WafMetricCollector.get().raspErrorCode(ruleType, -3)
WafMetricCollector.get().raspErrorCode(ruleType, DD_WAF_RUN_INTERNAL_ERROR)
WafMetricCollector.get().prepareMetrics()

then:
Expand Down Expand Up @@ -378,7 +386,7 @@ class WafMetricCollectorTest extends DDSpecification {
'rule_type:command_injection',
'rule_variant:' + ruleType.variant,
'event_rules_version:rules.1',
'waf_error:-3'
'waf_error:' + DD_WAF_RUN_INTERNAL_ERROR
].toSet()

where:
Expand Down
Loading
0