Skip to content
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

[Tracer] scrub _dd.agent_psr from test snapshots #5562

Merged
merged 11 commits into from
May 16, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public async Task VerifySpans(IImmutableList<MockSpan> spans, VerifySettings set
target.Tags[Tags.AppSecJson] = orderedAppSecJson;
}

return VerifyHelper.ScrubTags(target, target.Tags);
return VerifyHelper.ScrubStringTags(target, target.Tags);
});
});
settings.AddRegexScrubber(AppSecWafDuration, "_dd.appsec.waf.duration: 0.0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,26 @@ public static void InitializeGlobalSettings()
{
VerifierSettings.DerivePathInfo(
(sourceFile, projectDirectory, type, method) =>
{
return new(directory: Path.Combine(projectDirectory, "..", "snapshots"));
});
new PathInfo(directory: Path.Combine(projectDirectory, "..", "snapshots")));
}

public static VerifySettings GetSpanVerifierSettings(params object[] parameters) => GetSpanVerifierSettings(null, parameters);

public static VerifySettings GetCIVisibilitySpanVerifierSettings(params object[] parameters) => GetCIVisibilitySpanVerifierSettings(null, parameters);

public static VerifySettings GetSpanVerifierSettings(IEnumerable<(Regex RegexPattern, string Replacement)> scrubbers, object[] parameters)
=> GetSpanVerifierSettings(scrubbers, parameters, ScrubTags, null);
=> GetSpanVerifierSettings(scrubbers, parameters, ScrubStringTags, ScrubNumericTags, ciVisStringTagsScrubber: null, ciVisNumericTagsScrubber: null);

public static VerifySettings GetCIVisibilitySpanVerifierSettings(params object[] parameters) => GetCIVisibilitySpanVerifierSettings(null, parameters);

public static VerifySettings GetCIVisibilitySpanVerifierSettings(IEnumerable<(Regex RegexPattern, string Replacement)> scrubbers, object[] parameters)
=> GetSpanVerifierSettings(scrubbers, parameters, ScrubCIVisibilityTags, ScrubCIVisibilityTags, ScrubCIVisibilityMetrics, ScrubCIVisibilityMetrics);
=> GetSpanVerifierSettings(scrubbers, parameters, ScrubCIVisibilityTags, ScrubCIVisibilityMetrics, ScrubCIVisibilityTags, ScrubCIVisibilityMetrics);

public static VerifySettings GetSpanVerifierSettings(
IEnumerable<(Regex RegexPattern, string Replacement)> scrubbers,
object[] parameters,
ConvertMember<MockSpan, Dictionary<string, string>> tagsScrubber,
ConvertMember<MockCIVisibilityTest, Dictionary<string, string>> metaScrubber = null,
ConvertMember<MockSpan, Dictionary<string, double>> metricsSpanScrubber = null,
ConvertMember<MockCIVisibilityTest, Dictionary<string, double>> metricsScrubber = null)
ConvertMember<MockSpan, Dictionary<string, string>> apmStringTagsScrubber,
ConvertMember<MockSpan, Dictionary<string, double>> apmNumericTagsScrubber,
ConvertMember<MockCIVisibilityTest, Dictionary<string, string>> ciVisStringTagsScrubber,
ConvertMember<MockCIVisibilityTest, Dictionary<string, double>> ciVisNumericTagsScrubber)
{
var settings = new VerifySettings();

Expand All @@ -91,22 +89,28 @@ public static VerifySettings GetSpanVerifierSettings(
{
_.IgnoreMember<MockSpan>(s => s.Duration);
_.IgnoreMember<MockSpan>(s => s.Start);
_.MemberConverter<MockSpan, Dictionary<string, string>>(x => x.Tags, tagsScrubber);
if (metricsSpanScrubber is not null)

if (apmStringTagsScrubber is not null)
{
_.MemberConverter(x => x.Tags, apmStringTagsScrubber);
}

if (apmNumericTagsScrubber is not null)
{
_.MemberConverter<MockSpan, Dictionary<string, double>>(x => x.Metrics, metricsSpanScrubber);
_.MemberConverter(x => x.Metrics, apmNumericTagsScrubber);
}

_.IgnoreMember<MockCIVisibilityTest>(s => s.Duration);
_.IgnoreMember<MockCIVisibilityTest>(s => s.Start);
if (metaScrubber is not null)

if (ciVisStringTagsScrubber is not null)
{
_.MemberConverter<MockCIVisibilityTest, Dictionary<string, string>>(x => x.Meta, metaScrubber);
_.MemberConverter(x => x.Meta, ciVisStringTagsScrubber);
}

if (metricsScrubber is not null)
if (ciVisNumericTagsScrubber is not null)
{
_.MemberConverter<MockCIVisibilityTest, Dictionary<string, double>>(x => x.Metrics, metricsScrubber);
_.MemberConverter(x => x.Metrics, ciVisNumericTagsScrubber);
}
});

Expand Down Expand Up @@ -187,7 +191,7 @@ public static void AddSimpleScrubber(this VerifySettings settings, string oldVal
settings.AddScrubber(builder => ReplaceSimple(builder, oldValue, newValue));
}

public static Dictionary<string, string> ScrubTags(MockSpan span, Dictionary<string, string> tags)
public static Dictionary<string, string> ScrubStringTags(MockSpan span, Dictionary<string, string> tags)
{
return tags
// remove propagated tags because their positions in the snapshots are not stable
Expand All @@ -207,6 +211,20 @@ public static Dictionary<string, string> ScrubTags(MockSpan span, Dictionary<str
.ToDictionary(x => x.Key, x => x.Value);
}

public static Dictionary<string, double> ScrubNumericTags(MockSpan span, Dictionary<string, double> tags)
{
string[] ignoreKeys =
[
Metrics.SamplingAgentDecision,
// more coming soon
];

return tags
.Where(kvp => !ignoreKeys.Contains(kvp.Key))
.OrderBy(x => x.Key)
.ToDictionary(x => x.Key, x => x.Value);
}

public static Dictionary<string, string> ScrubCIVisibilityTags(MockSpan span, Dictionary<string, string> tags) => ScrubCIVisibilityTags(tags);

public static Dictionary<string, string> ScrubCIVisibilityTags(MockCIVisibilityTest span, Dictionary<string, string> tags) => ScrubCIVisibilityTags(tags);
Expand Down Expand Up @@ -265,6 +283,7 @@ public static Dictionary<string, string> ScrubCIVisibilityTags(Dictionary<string
public static Dictionary<string, double> ScrubCIVisibilityMetrics(Dictionary<string, double> metrics)
{
return metrics
.Where(kvp => kvp.Key != Metrics.SamplingAgentDecision)
.Select(
kvp => kvp.Key switch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ System.Exception: Exception of type 'System.Exception' was thrown.
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ at Samples.AspNetCoreMvc.Controllers.HomeController.StatusCodeTestString(String
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ at Samples.AspNetCoreMvc.Controllers.HomeController.ThrowException(),
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ System.Exception: Exception of type 'System.Exception' was thrown.
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ at Samples.AspNetCoreMvc.Controllers.HomeController.StatusCodeTestString(String
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ at Samples.AspNetCoreMvc.Controllers.HomeController.ThrowException(),
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ System.Exception: Exception of type 'System.Exception' was thrown.
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ at Samples.AspNetCoreMvc.Controllers.HomeController.StatusCodeTestString(String
},
Metrics: {
process_id: 0,
_dd.agent_psr: 1.0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
Expand Down
Loading
Loading