GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Create metric: appsec.waf.config_errors by sezen-datadog · Pull Request #8394 · DataDog/dd-trace-java

Create metric: appsec.waf.config_errors #8394

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.

Sign up for GitHub

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
sezen-datadog merged 3 commits into master from sezen.leblay/APPSEC-56480-config_errors
Jun 26, 2025

Uh oh!

There was an error while loading. Please reload this page.

Merged

Create metric: appsec.waf.config_errors #8394

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
022e3db
Create metric appsec.waf.config_errors
sezen-datadog Feb 14, 2025
e1b7f27
unit test
sezen-datadog Jun 25, 2025
d8434d3
Merge branch 'master' into sezen.leblay/APPSEC-56480-config_errors
sezen-datadog Jun 25, 2025
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

5 changes: 4 additions & 1 deletion 5 dd-java-agent/appsec/src/main/java/com/datadog/appsec/config/AppSecConfigServiceImpl.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import datadog.trace.api.ProductActivation;
import datadog.trace.api.UserIdCollectionMode;
import datadog.trace.api.telemetry.LogCollector;
import datadog.trace.api.telemetry.WafMetricCollector;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -263,7 +264,9 @@ private void handleWafUpdateResultReport(String configKey, Map<String, Object> r
"Invalid rule during waf config update for config key {}: {}",
configKey,
e.wafDiagnostics);

if (e.wafDiagnostics.getNumConfigError() > 0) {
WafMetricCollector.get().addWafConfigError(e.wafDiagnostics.getNumConfigError());
}
// TODO: Propagate diagostics back to remote config apply_error

initReporter.setReportForPublication(e.wafDiagnostics);
Expand Down
47 changes: 47 additions & 0 deletions 47 ...sec/src/test/groovy/com/datadog/appsec/config/AppSecConfigServiceImplSpecification.groovy
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import datadog.remoteconfig.state.ProductListener
import datadog.trace.api.Config
import datadog.trace.api.ProductActivation
import datadog.trace.api.UserIdCollectionMode
import datadog.trace.api.telemetry.WafMetricCollector
import datadog.trace.test.util.DDSpecification

import java.nio.file.Files
Expand Down Expand Up @@ -50,6 +51,7 @@ class AppSecConfigServiceImplSpecification extends DDSpecification {
AppSecModuleConfigurer.Reconfiguration reconf = Stub()
AppSecConfigServiceImpl appSecConfigService
SavedListeners listeners
protected static final ORIGINAL_METRIC_COLLECTOR = WafMetricCollector.get()

void cleanup() {
appSecConfigService?.close()
Expand Down Expand Up @@ -712,6 +714,51 @@ class AppSecConfigServiceImplSpecification extends DDSpecification {
AppSecSystem.active = true
}

void 'InvalidRuleSetException is thrown when rules are not configured correctly' () {
setup:
// Mock WafMetricCollector
WafMetricCollector wafMetricCollector = Mock(WafMetricCollector)
WafMetricCollector.INSTANCE = wafMetricCollector

// Create a temporary file with invalid WAF configuration
Path p = Files.createTempFile('appsec', '.json')
p.toFile() << '''{
"version": "2.2",
"rules": [
{
"id": "invalid-rule",
"name": "Invalid Rule",
"tags": {
"type": "invalid_type",
"category": "invalid_category"
},
"conditions": [
{
"operator": "invalid_operator",
"parameters": {
"invalid_param": "invalid_value"
}
}
],
"type": "invalid_type",
"data": []
}
]
}'''

when:
appSecConfigService.init()

then:
1 * config.getAppSecRulesFile() >> (p as String)
1 * wafMetricCollector.addWafConfigError(_ as Integer)
thrown RuntimeException

cleanup:
WafMetricCollector.INSTANCE = ORIGINAL_METRIC_COLLECTOR
p.toFile().delete()
}

private static AppSecFeatures autoUserInstrum(String mode) {
return new AppSecFeatures().tap { features ->
features.autoUserInstrum = new AppSecFeatures.AutoUserInstrum().tap { instrum ->
Expand Down
25 changes: 25 additions & 0 deletions 25 internal-api/src/main/java/datadog/trace/api/telemetry/WafMetricCollector.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private WafMetricCollector() {
new AtomicLongArray(LoginFramework.getNumValues());
private static final AtomicLongArray appSecSdkEventQueue =
new AtomicLongArray(LoginEvent.getNumValues() * LoginVersion.getNumValues());
private static final AtomicInteger wafConfigErrorCounter = new AtomicInteger();

/** WAF version that will be initialized with wafInit and reused for all metrics. */
private static String wafVersion = "";
Expand Down Expand Up @@ -353,6 +354,16 @@ public void prepareMetrics() {
}
}
}

// WAF config errors
int configErrors = wafConfigErrorCounter.getAndSet(0);
if (configErrors > 0) {
if (!rawMetricsQueue.offer(
new WafConfigError(
configErrors, WafMetricCollector.wafVersion, WafMetricCollector.rulesVersion))) {
return;
}
}
}

public abstract static class WafMetric extends MetricCollector.Metric {
Expand Down Expand Up @@ -448,6 +459,20 @@ public WafRequestsRawMetric(
}
}

public void addWafConfigError(int nbErrors) {
wafConfigErrorCounter.addAndGet(nbErrors);
}

public static class WafConfigError extends WafMetric {
public WafConfigError(final long counter, final String wafVersion, final String rulesVersion) {
super(
"waf.config_errors",
counter,
"waf_version:" + wafVersion,
"event_rules_version:" + rulesVersion);
}
}

public static class RaspRuleEval extends WafMetric {
public RaspRuleEval(final long counter, final RuleType ruleType, final String wafVersion) {
super(
Expand Down
22 changes: 22 additions & 0 deletions 22 internal-api/src/test/groovy/datadog/trace/api/telemetry/WafMetricCollectorTest.groovy
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,28 @@ class WafMetricCollectorTest extends DDSpecification {
[stringTooLong, listMapTooLarge, objectTooDeep] << allBooleanCombinations(3)
}

void 'test waf config error metrics'() {
given:
def collector = WafMetricCollector.get()

when:
collector.wafInit('waf_ver1', 'rules.1', true)
collector.addWafConfigError(5)
collector.addWafConfigError(3)
collector.prepareMetrics()

then:
def metrics = collector.drain()
def configErrorMetrics = metrics.findAll { it.metricName == 'waf.config_errors' }

final metric = configErrorMetrics[0]
metric.type == 'count'
metric.metricName == 'waf.config_errors'
metric.namespace == 'appsec'
metric.value == 8
metric.tags.toSet() == ['waf_version:waf_ver1', 'event_rules_version:rules.1'].toSet()
}

/**
* Helper method to generate all combinations of n boolean values.
*/
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.