Skip to content

Commit

Permalink
Update telemetryCollectorBase and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoEchevarria committed Oct 29, 2024
1 parent 683c1c6 commit 8373f2b
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ internal static partial class RaspRuleTypeExtensions
public static string ToStringFast(this Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType value)
=> value switch
{
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.Lfi => "waf_version;rule_type:lfi",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.Ssrf => "waf_version;rule_type:ssrf",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.SQlI => "waf_version;rule_type:sql_injection",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.CommandInjection => "waf_version;rule_type:command_injection",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.Lfi => "waf_version;event_rules_version;rule_type:lfi",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.Ssrf => "waf_version;event_rules_version;rule_type:ssrf",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.SQlI => "waf_version;event_rules_version;rule_type:sql_injection",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.CommandInjection => "waf_version;event_rules_version;rule_type:command_injection",
_ => value.ToString(),
};

Expand Down Expand Up @@ -81,9 +81,9 @@ public static string[] GetNames()
public static string[] GetDescriptions()
=> new []
{
"waf_version;rule_type:lfi",
"waf_version;rule_type:ssrf",
"waf_version;rule_type:sql_injection",
"waf_version;rule_type:command_injection",
"waf_version;event_rules_version;rule_type:lfi",
"waf_version;event_rules_version;rule_type:ssrf",
"waf_version;event_rules_version;rule_type:sql_injection",
"waf_version;event_rules_version;rule_type:command_injection",
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -562,20 +562,20 @@ private static AggregatedMetric[] GetCountBuffer()
new(new[] { "truncation_reason:list_or_map_too_large" }),
new(new[] { "truncation_reason:object_too_deep" }),
// rasp.rule.eval, index = 508
new(new[] { "waf_version", "rule_type:lfi" }),
new(new[] { "waf_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "rule_type:command_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:lfi" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:command_injection" }),
// rasp.rule.match, index = 512
new(new[] { "waf_version", "rule_type:lfi" }),
new(new[] { "waf_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "rule_type:command_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:lfi" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:command_injection" }),
// rasp.timeout, index = 516
new(new[] { "waf_version", "rule_type:lfi" }),
new(new[] { "waf_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "rule_type:command_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:lfi" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:command_injection" }),
// instrum.user_auth.missing_user_id, index = 520
new(new[] { "framework:aspnetcore_identity" }),
new(new[] { "framework:unknown" }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ internal static partial class RaspRuleTypeExtensions
public static string ToStringFast(this Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType value)
=> value switch
{
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.Lfi => "waf_version;rule_type:lfi",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.Ssrf => "waf_version;rule_type:ssrf",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.SQlI => "waf_version;rule_type:sql_injection",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.CommandInjection => "waf_version;rule_type:command_injection",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.Lfi => "waf_version;event_rules_version;rule_type:lfi",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.Ssrf => "waf_version;event_rules_version;rule_type:ssrf",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.SQlI => "waf_version;event_rules_version;rule_type:sql_injection",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.CommandInjection => "waf_version;event_rules_version;rule_type:command_injection",
_ => value.ToString(),
};

Expand Down Expand Up @@ -81,9 +81,9 @@ public static string[] GetNames()
public static string[] GetDescriptions()
=> new []
{
"waf_version;rule_type:lfi",
"waf_version;rule_type:ssrf",
"waf_version;rule_type:sql_injection",
"waf_version;rule_type:command_injection",
"waf_version;event_rules_version;rule_type:lfi",
"waf_version;event_rules_version;rule_type:ssrf",
"waf_version;event_rules_version;rule_type:sql_injection",
"waf_version;event_rules_version;rule_type:command_injection",
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -562,20 +562,20 @@ private static AggregatedMetric[] GetCountBuffer()
new(new[] { "truncation_reason:list_or_map_too_large" }),
new(new[] { "truncation_reason:object_too_deep" }),
// rasp.rule.eval, index = 508
new(new[] { "waf_version", "rule_type:lfi" }),
new(new[] { "waf_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "rule_type:command_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:lfi" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:command_injection" }),
// rasp.rule.match, index = 512
new(new[] { "waf_version", "rule_type:lfi" }),
new(new[] { "waf_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "rule_type:command_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:lfi" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:command_injection" }),
// rasp.timeout, index = 516
new(new[] { "waf_version", "rule_type:lfi" }),
new(new[] { "waf_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "rule_type:command_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:lfi" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:command_injection" }),
// instrum.user_auth.missing_user_id, index = 520
new(new[] { "framework:aspnetcore_identity" }),
new(new[] { "framework:unknown" }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ internal static partial class RaspRuleTypeExtensions
public static string ToStringFast(this Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType value)
=> value switch
{
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.Lfi => "waf_version;rule_type:lfi",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.Ssrf => "waf_version;rule_type:ssrf",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.SQlI => "waf_version;rule_type:sql_injection",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.CommandInjection => "waf_version;rule_type:command_injection",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.Lfi => "waf_version;event_rules_version;rule_type:lfi",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.Ssrf => "waf_version;event_rules_version;rule_type:ssrf",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.SQlI => "waf_version;event_rules_version;rule_type:sql_injection",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.CommandInjection => "waf_version;event_rules_version;rule_type:command_injection",
_ => value.ToString(),
};

Expand Down Expand Up @@ -81,9 +81,9 @@ public static string[] GetNames()
public static string[] GetDescriptions()
=> new []
{
"waf_version;rule_type:lfi",
"waf_version;rule_type:ssrf",
"waf_version;rule_type:sql_injection",
"waf_version;rule_type:command_injection",
"waf_version;event_rules_version;rule_type:lfi",
"waf_version;event_rules_version;rule_type:ssrf",
"waf_version;event_rules_version;rule_type:sql_injection",
"waf_version;event_rules_version;rule_type:command_injection",
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -562,20 +562,20 @@ private static AggregatedMetric[] GetCountBuffer()
new(new[] { "truncation_reason:list_or_map_too_large" }),
new(new[] { "truncation_reason:object_too_deep" }),
// rasp.rule.eval, index = 508
new(new[] { "waf_version", "rule_type:lfi" }),
new(new[] { "waf_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "rule_type:command_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:lfi" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:command_injection" }),
// rasp.rule.match, index = 512
new(new[] { "waf_version", "rule_type:lfi" }),
new(new[] { "waf_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "rule_type:command_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:lfi" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:command_injection" }),
// rasp.timeout, index = 516
new(new[] { "waf_version", "rule_type:lfi" }),
new(new[] { "waf_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "rule_type:command_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:lfi" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:command_injection" }),
// instrum.user_auth.missing_user_id, index = 520
new(new[] { "framework:aspnetcore_identity" }),
new(new[] { "framework:unknown" }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ internal static partial class RaspRuleTypeExtensions
public static string ToStringFast(this Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType value)
=> value switch
{
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.Lfi => "waf_version;rule_type:lfi",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.Ssrf => "waf_version;rule_type:ssrf",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.SQlI => "waf_version;rule_type:sql_injection",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.CommandInjection => "waf_version;rule_type:command_injection",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.Lfi => "waf_version;event_rules_version;rule_type:lfi",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.Ssrf => "waf_version;event_rules_version;rule_type:ssrf",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.SQlI => "waf_version;event_rules_version;rule_type:sql_injection",
Datadog.Trace.Telemetry.Metrics.MetricTags.RaspRuleType.CommandInjection => "waf_version;event_rules_version;rule_type:command_injection",
_ => value.ToString(),
};

Expand Down Expand Up @@ -81,9 +81,9 @@ public static string[] GetNames()
public static string[] GetDescriptions()
=> new []
{
"waf_version;rule_type:lfi",
"waf_version;rule_type:ssrf",
"waf_version;rule_type:sql_injection",
"waf_version;rule_type:command_injection",
"waf_version;event_rules_version;rule_type:lfi",
"waf_version;event_rules_version;rule_type:ssrf",
"waf_version;event_rules_version;rule_type:sql_injection",
"waf_version;event_rules_version;rule_type:command_injection",
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -562,20 +562,20 @@ private static AggregatedMetric[] GetCountBuffer()
new(new[] { "truncation_reason:list_or_map_too_large" }),
new(new[] { "truncation_reason:object_too_deep" }),
// rasp.rule.eval, index = 508
new(new[] { "waf_version", "rule_type:lfi" }),
new(new[] { "waf_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "rule_type:command_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:lfi" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:command_injection" }),
// rasp.rule.match, index = 512
new(new[] { "waf_version", "rule_type:lfi" }),
new(new[] { "waf_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "rule_type:command_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:lfi" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:command_injection" }),
// rasp.timeout, index = 516
new(new[] { "waf_version", "rule_type:lfi" }),
new(new[] { "waf_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "rule_type:command_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:lfi" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:ssrf" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:sql_injection" }),
new(new[] { "waf_version", "event_rules_version", "rule_type:command_injection" }),
// instrum.user_auth.missing_user_id, index = 520
new(new[] { "framework:aspnetcore_identity" }),
new(new[] { "framework:unknown" }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ namespace Datadog.Trace.Telemetry;

internal abstract partial class MetricsTelemetryCollectorBase
{
private static readonly string[] _unknownWafVersionTags = { "waf_version:unknown", "event_rules_version:unknown" };
private readonly TimeSpan _aggregationInterval;
private readonly Action? _aggregationNotification;
private readonly string[] _unknownWafVersionTags = { "waf_version:unknown", "event_rules_version:unknown" };
private readonly Task _aggregateTask;
private readonly TaskCompletionSource<bool> _processExit = new();
private string[]? _wafAndRulesVersionTags;
Expand Down Expand Up @@ -56,7 +56,7 @@ public Task DisposeAsync()
public void SetWafAndRulesVersion(string wafVersion, string? eventRulesVersion)
{
// Setting this an array so we can reuse it for multiple metrics
_wafAndRulesVersionTags = new[] { $"waf_version:{wafVersion}", $"event_rules_version:{eventRulesVersion}" };
_wafAndRulesVersionTags = new[] { $"waf_version:{wafVersion}", $"event_rules_version:{eventRulesVersion ?? "unknown"}" };
}

protected static AggregatedMetric[] GetPublicApiCountBuffer()
Expand Down
8 changes: 4 additions & 4 deletions tracer/src/Datadog.Trace/Telemetry/Metrics/MetricTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ public enum WafAnalysis
[EnumExtensions]
public enum RaspRuleType
{
[Description("waf_version;rule_type:lfi")] Lfi = 0,
[Description("waf_version;rule_type:ssrf")] Ssrf = 1,
[Description("waf_version;rule_type:sql_injection")] SQlI = 2,
[Description("waf_version;rule_type:command_injection")] CommandInjection = 3,
[Description("waf_version;event_rules_version;rule_type:lfi")] Lfi = 0,
[Description("waf_version;event_rules_version;rule_type:ssrf")] Ssrf = 1,
[Description("waf_version;event_rules_version;rule_type:sql_injection")] SQlI = 2,
[Description("waf_version;event_rules_version;rule_type:command_injection")] CommandInjection = 3,
}

public enum TruncationReason
Expand Down
Loading

0 comments on commit 8373f2b

Please sign in to comment.