-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add smoke test for config builder instrumentation issue (#6224)
## Summary of changes Adds a smoke test for the issue fixed in #6147 ## Reason for change The issue in #6147 is complex and subtle, with a high risk of regression, so we want to have smoke tests to catch it` ## Implementation details Add a sample app very similar to the one tested with in #6147. Without the fix, [the test fails with](https://dev.azure.com/datadoghq/dd-trace-dotnet/_build/results?buildId=166792&view=results) ```html <b> Description: </b>An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. <br><br> <b> Parser Error Message: </b>The configBuilder 'CustomBuilder' failed while processing the configuration section 'appSettings'.: The ConfigurationBuilder 'CustomBuilder[Microsoft.Configuration.ConfigurationBuilders.CustomConfigBuilder]' has recursively re-entered processing of the 'appSettings' section.<br><br> ``` After the fix (now merged) the tests pass ## Test coverage This is primarily a smoke test, so we confirm - The sites are running and responding to HTTP requests correctly - We instrument the application (it has logs) - There are no errors in the logs ## Other details For some reason, I had massive issues getting the app to "recognize" the `DD_TRACE_AGENT_URL=http://test-agent.windows:8126` env var setting that's required to talk to the test agent. I have no idea why, and the only resolution I could find was to use powershell to set the variables inside the docker image --------- Co-authored-by: Kevin Gosse <[email protected]>
- Loading branch information
1 parent
bf5333d
commit 64c02f7
Showing
27 changed files
with
2,025 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
tracer/build/_build/docker/iis.multipleappsindomain.dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2022 | ||
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] | ||
|
||
# Copy IIS websites | ||
ADD tracer/test/test-applications/aspnet/Samples.AspNet.MultipleAppsInDomain/bin/Release/publish MultipleAppsInDomain | ||
|
||
# Set up multiple apps in single domain with custom config IIS websites | ||
ARG ENABLE_32_BIT | ||
ENV ENABLE_32_BIT=${ENABLE_32_BIT:-false} | ||
|
||
RUN c:\Windows\System32\inetsrv\appcmd add apppool /name:mutliAppPool /managedRuntimeVersion:"v4.0" /managedPipelineMode:"Integrated" /enable32bitapponwin64:$env:ENABLE_32_BIT | ||
|
||
# The SetEnvironmentVariable() calls shouldn't _need_ to be here - we should be able to do it just | ||
# using docker-compose, but I can't get that to work for some inexplicable reason, no matter | ||
# what I do, so here we are. | ||
RUN Remove-WebSite -Name 'Default Web Site'; \ | ||
Write-Host "Created app pool with 32 bit reg key: $env:ENABLE_32_BIT"; \ | ||
Write-Host "Creating multi app domain sites"; \ | ||
[System.Environment]::SetEnvironmentVariable('DD_TRACE_AGENT_URL', 'http://test-agent.windows:8126', [System.EnvironmentVariableTarget]::Machine); \ | ||
[System.Environment]::SetEnvironmentVariable('DD_TRACE_AGENT_URL', 'http://test-agent.windows:8126', [System.EnvironmentVariableTarget]::Process); \ | ||
[System.Environment]::SetEnvironmentVariable('DD_TRACE_AGENT_URL', 'http://test-agent.windows:8126', [System.EnvironmentVariableTarget]::User); \ | ||
New-Website -Name 'MultiAppPoolWithCustomConfig1' -ApplicationPool mutliAppPool -Port 8081 -PhysicalPath 'c:\MultipleAppsInDomain'; \ | ||
New-Website -Name 'MultiAppPoolWithCustomConfig2' -ApplicationPool mutliAppPool -Port 8082 -PhysicalPath 'c:\MultipleAppsInDomain'; | ||
|
||
# Install the .NET Tracer MSI | ||
ARG DOTNET_TRACER_MSI | ||
ADD $DOTNET_TRACER_MSI ./datadog-apm.msi | ||
RUN Start-Process -Wait msiexec -ArgumentList '/qn /i datadog-apm.msi' | ||
|
||
# Restart IIS | ||
RUN net stop /y was; \ | ||
net start w3svc | ||
|
||
EXPOSE 80 |
98 changes: 98 additions & 0 deletions
98
...dog.Trace.ClrProfiler.IntegrationTests/IIS/MultipleAppsInDomainWithCustomConfigBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// <copyright file="MultipleAppsInDomainWithCustomConfigBuilder.cs" company="Datadog"> | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. | ||
// </copyright> | ||
|
||
#if NETFRAMEWORK | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Datadog.Trace.Configuration.Telemetry; | ||
using Datadog.Trace.Logging; | ||
using FluentAssertions; | ||
using Newtonsoft.Json; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Datadog.Trace.ClrProfiler.IntegrationTests.IIS; | ||
|
||
public class MultipleAppsInDomainWithCustomConfigBuilder(ITestOutputHelper output) | ||
{ | ||
[SkippableFact] | ||
[Trait("RunOnWindows", "True")] | ||
[Trait("IIS", "True")] | ||
[Trait("MSI", "True")] | ||
public async Task ApplicationDoesNotReturnErrors() | ||
{ | ||
const string App1Url = "http://localhost:8081"; | ||
const string App2Url = "http://localhost:8082"; | ||
|
||
var intervalMilliseconds = 500; | ||
var intervals = 5; | ||
var serverReady = false; | ||
var client = new HttpClient() | ||
{ | ||
Timeout = TimeSpan.FromSeconds(30), // yes, this is a long time, but we're running this in CI, in windows containers... | ||
}; | ||
|
||
// wait for server to be ready to receive requests | ||
while (intervals-- > 0) | ||
{ | ||
try | ||
{ | ||
output.WriteLine($"Sending warmup request to App 1 {App1Url}"); | ||
var serverReadyResponse = await client.GetAsync(App1Url); | ||
serverReady = serverReadyResponse.StatusCode == HttpStatusCode.OK; | ||
} | ||
catch | ||
{ | ||
// ignore | ||
} | ||
|
||
if (serverReady) | ||
{ | ||
output.WriteLine("The server is ready."); | ||
break; | ||
} | ||
|
||
Thread.Sleep(intervalMilliseconds); | ||
} | ||
|
||
// Send request to app 1 | ||
var responseMessage = await client.GetAsync(App1Url); | ||
var response = await responseMessage.Content.ReadAsStringAsync(); | ||
output.WriteLine($"Received response from app1 at {App1Url}: {response}"); | ||
responseMessage.StatusCode.Should().Be(HttpStatusCode.OK); | ||
|
||
var app1Result = JsonConvert.DeserializeObject<Results>(response); | ||
app1Result.Pid.Should().NotBe(0); | ||
app1Result.AppConfig.Should().ContainKey("DummyKey1").WhoseValue.Should().Be("DummyValue1 - from custom config"); | ||
|
||
// Send request to app 2 | ||
responseMessage = await client.GetAsync(App2Url); | ||
response = await responseMessage.Content.ReadAsStringAsync(); | ||
output.WriteLine($"Received response from app2 at {App2Url}: {response}"); | ||
responseMessage.StatusCode.Should().Be(HttpStatusCode.OK); | ||
|
||
var app2Result = JsonConvert.DeserializeObject<Results>(response); | ||
app2Result.Pid.Should().Be(app1Result.Pid); | ||
app2Result.AppConfig.Should().ContainKey("DummyKey1").WhoseValue.Should().Be("DummyValue1 - from custom config"); | ||
|
||
// verify we have some logs, so we know instrumentation happened | ||
var logDirectory = Path.Combine(DatadogLoggingFactory.GetLogDirectory(NullConfigurationTelemetry.Instance), "MultipleAppsInDomain"); | ||
output.WriteLine($"Reading files from {logDirectory}"); | ||
Directory.GetFiles(logDirectory).Should().NotBeEmpty(); | ||
} | ||
|
||
public class Results | ||
{ | ||
public int Pid { get; set; } | ||
|
||
public Dictionary<string, string> AppConfig { get; set; } | ||
} | ||
} | ||
#endif |
28 changes: 28 additions & 0 deletions
28
...est-applications/aspnet/Samples.AspNet.MultipleAppsInDomain/Controllers/HomeController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Web.Mvc; | ||
|
||
namespace Samples.AspNet.MultipleAppsInDomain.Controllers | ||
{ | ||
public class HomeController : Controller | ||
{ | ||
public ActionResult Index() | ||
{ | ||
var results = new Results(); | ||
results.Pid = Process.GetCurrentProcess().Id; | ||
results.AppConfig = new Dictionary<string, string>(); | ||
foreach(var key in System.Configuration.ConfigurationManager.AppSettings.AllKeys) | ||
{ | ||
results.AppConfig[key] = System.Configuration.ConfigurationManager.AppSettings[key]; | ||
} | ||
|
||
return Json(results, JsonRequestBehavior.AllowGet); | ||
} | ||
|
||
public class Results | ||
{ | ||
public int Pid { get; set; } | ||
public Dictionary<string, string> AppConfig { get; set; } | ||
} | ||
} | ||
} |
Oops, something went wrong.