Skip to content

[AAP] Reduce waf config diagnostics log levels #7094

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 4 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ internal UpdateResult Update(IntPtr wafBuilderHandle, ConfigurationState configu

if (!_wafLibraryInvoker.BuilderRemoveConfig(wafBuilderHandle, path))
{
Log.Error("DDAS-0005-00: WAF builder: Config failed to be removed : {0}", path); // Check were all these error codes are defined
Log.Debug("WAF builder: Config failed to be removed : {0}", path); // Check were all these error codes are defined
}
}
}
Expand All @@ -160,7 +160,7 @@ internal UpdateResult Update(IntPtr wafBuilderHandle, ConfigurationState configu
var path = config.Key;
if (!_wafLibraryInvoker.BuilderAddOrUpdateConfig(wafBuilderHandle, path, ref configObj, ref diagnostics))
{
Log.Error("DDAS-0005-00: WAF builder: Config failed to load : {0}", path); // Check were all these error codes are defined
Log.Debug("WAF builder: Config failed to load : {0}", path); // Check were all these error codes are defined
}
}
}
Expand All @@ -186,29 +186,44 @@ internal UpdateResult Update(IntPtr wafBuilderHandle, ConfigurationState configu
result.ReportedDiagnostics.Rest.Warnings is { Count: > 0 })
{
var diags = result.ReportedDiagnostics;
var sb = StringBuilderCache.Acquire();
DumpStatsMessages(ref diags.Rules);
DumpStatsMessages(ref diags.Rest);

if (diags.HasErrors)
{
// This message should go to telemetry logs only, skipping the regular logs
Log.Debug("Some errors were found while applying waf configuration (RulesFile: {RulesFile})", rulesFile);
}
else
{
Log.Debug("Some warnings were found while applying waf configuration (RulesFile: {RulesFile})", rulesFile);
}

void DumpStatsMessages(ref WafStats stats)
{
DumpMessages(stats.Errors, "ERR: ");
DumpMessages(stats.Warnings, "WRN: ");
DumpMessages(stats.Errors, true);
DumpMessages(stats.Warnings, false);
}

void DumpMessages(IReadOnlyDictionary<string, object>? messages, string prefix)
void DumpMessages(IReadOnlyDictionary<string, object>? messages, bool isError)
{
if (messages is { Count: > 0 })
{
foreach (var item in messages)
{
sb.Append($"${prefix}{item.Key}: [{string.Join(", ", item.Value)}] ");
var message = $"{item.Key}: [{string.Join(", ", item.Value)}]";
if (isError)
{
// This message should go to telemetry logs only, skipping the regular logs
Log.Debug("rc::asm_dd::diagnostic Error: {Err}", message);
}
else
{
Log.Debug("rc::asm_dd::diagnostic Warning: {Err}", message);
}
}
}
}

var errorMess = StringBuilderCache.GetStringAndRelease(sb);
Log.Warning("Some issues were found while applying waf configuration (RulesFile: {RulesFile}): {ErroringRules}", rulesFile, errorMess);
}

if (result.Success && !updating)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public ReportedDiagnostics(IReadOnlyDictionary<string, object> errors)
{
Rules.Errors = errors;
}

public bool HasErrors => Rules.Errors is { Count: > 0 } || Rest.Errors is { Count: > 0 };
}

internal struct WafStats
Expand Down
Loading