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

Add additional tests for CI Visibility configuration behaviour #6513

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -3,6 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

using System;
using Datadog.Trace.Ci.Configuration;
using Datadog.Trace.Configuration;
using Datadog.Trace.Configuration.Telemetry;
Expand All @@ -14,6 +15,8 @@ namespace Datadog.Trace.Tests.Configuration
{
public class CIVisibilitySettingsTests : SettingsTestsBase
{
private static readonly string ExpectedExcludedSession = "/session/FakeSessionIdForPollingPurposes".ToUpperInvariant();

[Theory]
[MemberData(nameof(BooleanTestCases), null)]
public void Enabled(string value, bool? expected)
Expand Down Expand Up @@ -185,5 +188,107 @@ public void ForceAgentsEvpProxy(string value, string expected)

settings.ForceAgentsEvpProxy.Should().Be(expected);
}

[Theory]
[InlineData("some-service", "true")]
[InlineData(null, "false")]
public void AddsUserProvidedTestServiceTagToGlobalTags(string serviceName, string expectedTag)
{
var source = CreateConfigurationSource((ConfigurationKeys.ServiceName, serviceName));

var ciVisSettings = new CIVisibilitySettings(source, NullConfigurationTelemetry.Instance);
var tracerSettings = ciVisSettings.InitializeTracerSettings([source]);

tracerSettings.GlobalTags.Should()
.ContainKey(Datadog.Trace.Ci.Tags.CommonTags.UserProvidedTestServiceTag)
.WhoseValue.Should()
.Be(expectedTag);
}

[Fact]
public void ServiceNameIsNormalized()
{
var originalName = "My Service Name!";
var normalizedName = "my_service_name";

var source = CreateConfigurationSource((ConfigurationKeys.ServiceName, originalName));

var ciVisSettings = new CIVisibilitySettings(source, NullConfigurationTelemetry.Instance);
var tracerSettings = ciVisSettings.InitializeTracerSettings([source]);

tracerSettings.ServiceName.Should().Be(normalizedName);
}

[Fact]
public void AddsFakeSessionToExcludedHttpClientUrls()
{
var source = CreateConfigurationSource();

var ciVisSettings = new CIVisibilitySettings(source, NullConfigurationTelemetry.Instance);
var tracerSettings = ciVisSettings.InitializeTracerSettings([source]);

tracerSettings.HttpClientExcludedUrlSubstrings
.Should()
.Contain(ExpectedExcludedSession);
}

[Fact]
public void AddsFakeSessionToExcludedHttpClientUrls_WhenUrlsAlreadyExist()
{
var source = CreateConfigurationSource(
(ConfigurationKeys.HttpClientExcludedUrlSubstrings, "/some-url/path"));

var ciVisSettings = new CIVisibilitySettings(source, NullConfigurationTelemetry.Instance);
var tracerSettings = ciVisSettings.InitializeTracerSettings([source]);

tracerSettings.HttpClientExcludedUrlSubstrings
.Should()
.Contain(ExpectedExcludedSession);
}

[Fact]
public void AddsFakeSessionToExcludedHttpClientUrls_WhenRunningInAas()
{
var source = CreateConfigurationSource(
(ConfigurationKeys.AzureAppService.AzureAppServicesContextKey, "true"),
(ConfigurationKeys.HttpClientExcludedUrlSubstrings, "/some-url/path"));

var ciVisSettings = new CIVisibilitySettings(source, NullConfigurationTelemetry.Instance);
var tracerSettings = ciVisSettings.InitializeTracerSettings([source]);

tracerSettings.HttpClientExcludedUrlSubstrings
.Should()
.Contain(ExpectedExcludedSession);
}

[Fact]
public void WhenLogsEnabled_AddsDirectSubmission()
{
var source = CreateConfigurationSource(
(ConfigurationKeys.CIVisibility.Logs, "true"));

var ciVisSettings = new CIVisibilitySettings(source, NullConfigurationTelemetry.Instance);
var tracerSettings = ciVisSettings.InitializeTracerSettings([source]);

tracerSettings.LogSubmissionSettings
.EnabledIntegrationNames
.Should()
.Contain(nameof(IntegrationId.XUnit));
tracerSettings.LogSubmissionSettings.BatchPeriod.Should().Be(TimeSpan.FromSeconds(1));
}

[Fact]
public void WhenLogsNotEnabled_DoesNotAddDirectSubmission()
{
var source = CreateConfigurationSource();

var ciVisSettings = new CIVisibilitySettings(source, NullConfigurationTelemetry.Instance);
var tracerSettings = ciVisSettings.InitializeTracerSettings([source]);

tracerSettings.LogSubmissionSettings
.EnabledIntegrationNames
.Should()
.NotContain(nameof(IntegrationId.XUnit));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ public void Environment(string value, string expected)

[Theory]
[InlineData("test", null, null, "test")]
// This is the current behaviour - _should_ it be, or should the result be normalized, is a separate question...
[InlineData("My Service Name!", null, null, "My Service Name!")]
[InlineData("test", null, "ignored_otel", "test")]
[InlineData("test", "error", "ignored_otel", "test")]
[InlineData(null, "test", null, "test")]
Expand Down
Loading