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 code coverage to the consolidated pipeline #1527

Merged
merged 32 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d50700e
WIP
kevingosse Jun 8, 2021
f43f393
Add code coverage to windows integration tests
kevingosse Jun 11, 2021
4b645ab
Change path and dump directory structure
kevingosse Jun 11, 2021
afff651
Change pool
kevingosse Jun 11, 2021
1193769
Enable coverage on Linux
kevingosse Jun 11, 2021
5c59395
Add collector to more projects
kevingosse Jun 14, 2021
fa1f198
Disable coverlet in OpenTracing integration tests
kevingosse Jun 14, 2021
852078c
Remove from Datadog.Trace.OpenTracing.Tests
kevingosse Jun 15, 2021
66e6c9f
Improvements
kevingosse Jun 15, 2021
cad11d2
Cleanup
kevingosse Jun 15, 2021
7a52cc4
Enable code coverage for unit tests
kevingosse Jun 15, 2021
399e664
Try fix strong naming error
kevingosse Jun 16, 2021
05d4857
Remove duplicate publish steps
kevingosse Jun 16, 2021
d457bdf
Extend coverage to all supported TFMs
kevingosse Jun 16, 2021
c7b85d4
Add missing dependencies to the coverage job
kevingosse Jun 17, 2021
a241ab5
Ignore auto properties
kevingosse Jun 18, 2021
d5c0782
Exclude unrelated assemblies
kevingosse Jun 18, 2021
09b2cfe
Add diagnostic messages
kevingosse Jun 21, 2021
b6e1dc5
Replace TFM exception with compile-time error
kevingosse Jun 21, 2021
7e18dc1
Make TFM conditions more robust
kevingosse Jun 21, 2021
8b8a172
Remove references to ClrProfiler in Samples
kevingosse Jun 22, 2021
a3d7db8
Try excluding the profiler from linux samples
kevingosse Jun 22, 2021
de8b36b
Fix diagnostic message
kevingosse Jun 22, 2021
47392f6
Exclude profiler in more projects
kevingosse Jun 23, 2021
b28d69c
Try killing gracefully the graphql process
kevingosse Jun 23, 2021
0a1c09a
Add shutdown handler to aspnetcore
kevingosse Jun 23, 2021
a15e0ff
Add coverage for GAC'd assemblies
kevingosse Jun 23, 2021
6d2ef30
Don't target incompatible versions
kevingosse Jun 28, 2021
16c29fb
Enable coverage on the remaining IIS Express tests
kevingosse Jun 29, 2021
a4b9877
Explicitly unload the appdomain
kevingosse Jul 1, 2021
3b4af8e
Address PR feedback
kevingosse Jul 6, 2021
6e9e0d2
Change schedule variable
kevingosse Jul 8, 2021
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
65 changes: 53 additions & 12 deletions .azure-pipelines/ultimate-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ stages:
- template: steps/install-dotnet.yml
- template: steps/restore-working-directory.yml

- script: build.cmd BuildAndRunManagedUnitTests
- script: build.cmd BuildAndRunManagedUnitTests --code-coverage
displayName: Build and Test

- publish: build_data
Expand All @@ -213,7 +213,7 @@ stages:
testResultsFormat: VSTest
testResultsFiles: build_data/results/**/*.trx
condition: succeededOrFailed()

- job: native
steps:
- template: steps/install-dotnet.yml
Expand Down Expand Up @@ -241,7 +241,7 @@ stages:
parameters:
artifact: build-macos-working-directory

- script: ./build.sh BuildAndRunManagedUnitTests
- script: ./build.sh BuildAndRunManagedUnitTests --code-coverage
displayName: Build and Test

- publish: build_data
Expand All @@ -254,6 +254,8 @@ stages:
testResultsFormat: VSTest
testResultsFiles: build_data/results/**/*.trx
condition: succeededOrFailed()



- stage: unit_tests_linux
condition: and(succeeded(), eq(variables['isScheduledBuild'], 'False'))
Expand All @@ -278,7 +280,7 @@ stages:
parameters:
build: true
baseImage: $(baseImage)
command: "BuildAndRunManagedUnitTests"
command: "BuildAndRunManagedUnitTests --code-coverage"

- publish: build_data
artifact: profiler-logs_unit_tests_linux_$(Agent.JobName)_$(System.JobAttempt)
Expand All @@ -290,6 +292,11 @@ stages:
testResultsFormat: VSTest
testResultsFiles: build_data/results/**/*.trx
condition: succeededOrFailed()

- task: PublishPipelineArtifact@1
inputs:
targetPath: 'build_data/results/'
continueOnError: true

- stage: unit_tests_arm64
condition: and(succeeded(), eq(variables['isScheduledBuild'], 'False'))
Expand Down Expand Up @@ -350,7 +357,7 @@ stages:
displayName: 'Start CosmosDB Emulator'
workingDirectory: $(Pipeline.Workspace)

- script: build.cmd BuildAndRunWindowsIntegrationTests --PrintDriveSpace
- script: build.cmd BuildAndRunWindowsIntegrationTests --PrintDriveSpace --code-coverage
displayName: Run integration tests

- task: PublishTestResults@2
Expand All @@ -359,6 +366,11 @@ stages:
testResultsFormat: VSTest
testResultsFiles: build_data/results/**/*.trx
condition: succeededOrFailed()

- task: PublishPipelineArtifact@1
inputs:
targetPath: 'build_data/results/'
continueOnError: true

- stage: integration_tests_windows_iis
condition: and(succeeded(), eq(variables['isScheduledBuild'], 'False'))
Expand Down Expand Up @@ -408,13 +420,7 @@ stages:
containerregistrytype: Container Registry
dockerComposeCommand: up -d IntegrationTests.IIS

- powershell: |
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publish = New-Object System.EnterpriseServices.Internal.Publish
Get-ChildItem $(tracerHome)/net45 -Filter *.dll | Foreach-Object { $publish.GacInstall($_.FullName) }
displayName: Add net45 Datadog.Trace.ClrProfiler.Managed assets to the GAC

- script: build.cmd RunWindowsIisIntegrationTests
- script: build.cmd RunWindowsIisIntegrationTests --code-coverage
displayName: RunWindowsIisIntegrationTests

- task: PublishTestResults@2
Expand All @@ -424,6 +430,11 @@ stages:
testResultsFiles: build_data/results/**/*.trx
condition: succeededOrFailed()

- task: PublishPipelineArtifact@1
inputs:
targetPath: 'build_data/results/'
continueOnError: true

- task: DockerCompose@0
displayName: docker-compose stop services
inputs:
Expand Down Expand Up @@ -932,3 +943,33 @@ stages:
displayName: Crank
env:
DD_SERVICE: dd-trace-dotnet
- stage: coverage
condition: and(succeeded(), eq(variables['isScheduledBuild'], 'False'))
dependsOn: [integration_tests_windows, integration_tests_windows_iis, integration_tests_linux, unit_tests_linux, unit_tests_macos, unit_tests_windows]
jobs:
- job: Windows
timeoutInMinutes: 30

pool:
vmImage: windows-2019

steps:
- template: steps/restore-working-directory.yml

- task: DownloadPipelineArtifact@2
inputs:
patterns: '**/coverage.cobertura.xml'
path: $(Build.SourcesDirectory)/cover

- task: reportgenerator@4
inputs:
reports: '$(Build.SourcesDirectory)\cover\**\coverage.cobertura.xml'
targetdir: '$(Build.SourcesDirectory)\coveragereport'
sourcedirs: '$(Build.SourcesDirectory);..'
reporttypes: 'Cobertura'

- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(Build.SourcesDirectory)/coveragereport/Cobertura.xml'
pathToSources: '$(Build.SourcesDirectory)'
74 changes: 51 additions & 23 deletions build/_build/Build.Steps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,32 @@ partial class Build

IEnumerable<MSBuildTargetPlatform> ArchitecturesForPlatform =>
Equals(Platform, MSBuildTargetPlatform.x64)
? new[] {MSBuildTargetPlatform.x64, MSBuildTargetPlatform.x86}
: new[] {MSBuildTargetPlatform.x86};
? new[] { MSBuildTargetPlatform.x64, MSBuildTargetPlatform.x86 }
: new[] { MSBuildTargetPlatform.x86 };

bool IsArm64 => RuntimeInformation.ProcessArchitecture == Architecture.Arm64;
string LinuxArchitectureIdentifier => IsArm64 ? "arm64" : Platform.ToString();

IEnumerable<string> LinuxPackageTypes => IsAlpine ? new[] {"tar"} : new[] {"deb", "rpm", "tar"};
IEnumerable<string> LinuxPackageTypes => IsAlpine ? new[] { "tar" } : new[] { "deb", "rpm", "tar" };

IEnumerable<Project> ProjectsToPack => new []
IEnumerable<Project> ProjectsToPack => new[]
{
Solution.GetProject(Projects.DatadogTrace),
Solution.GetProject(Projects.DatadogTraceOpenTracing),
};

Project[] ParallelIntegrationTests => new []
Project[] ParallelIntegrationTests => new[]
{
Solution.GetProject(Projects.TraceIntegrationTests),
Solution.GetProject(Projects.OpenTracingIntegrationTests),
};

Project[] ClrProfilerIntegrationTests => new []
Project[] ClrProfilerIntegrationTests => new[]
{
Solution.GetProject(Projects.ClrProfilerIntegrationTests)
};

readonly IEnumerable<TargetFramework> TargetFrameworks = new []
readonly IEnumerable<TargetFramework> TargetFrameworks = new[]
{
TargetFramework.NET45,
TargetFramework.NET461,
Expand Down Expand Up @@ -439,7 +439,7 @@ partial class Build

foreach (var packageType in LinuxPackageTypes)
{
var args = new []
var args = new[]
{
"-f",
"-s dir",
Expand Down Expand Up @@ -522,6 +522,7 @@ partial class Build
.SetTargetPlatformAnyCPU()
.SetDDEnvironmentVariables("dd-tracer-dotnet")
.EnableMemoryDumps()
.When(CodeCoverage, ConfigureCodeCoverage)
.CombineWith(testProjects, (x, project) => x
.EnableTrxLogOutput(GetResultsDirectory(project))
.SetProjectFile(project)));
Expand Down Expand Up @@ -623,18 +624,18 @@ partial class Build
&& !x.Contains("StackExchange.Redis.AssemblyConflict.LegacyProject")
&& !x.Contains("dependency-libs"));

// Allow restore here, otherwise things go wonky with runtime identifiers
// in some target frameworks. No, I don't know why
DotNetBuild(x => x
// .EnableNoRestore()
.EnableNoDependencies()
.SetConfiguration(BuildConfiguration)
.SetTargetPlatform(Platform)
.SetNoWarnDotNetCore3()
.When(!string.IsNullOrEmpty(NugetPackageDirectory), o =>
o.SetPackageDirectory(NugetPackageDirectory))
.CombineWith(regressionLibs, (x, project) => x
.SetProjectFile(project)));
// Allow restore here, otherwise things go wonky with runtime identifiers
// in some target frameworks. No, I don't know why
DotNetBuild(x => x
// .EnableNoRestore()
.EnableNoDependencies()
.SetConfiguration(BuildConfiguration)
.SetTargetPlatform(Platform)
.SetNoWarnDotNetCore3()
.When(!string.IsNullOrEmpty(NugetPackageDirectory), o =>
o.SetPackageDirectory(NugetPackageDirectory))
.CombineWith(regressionLibs, (x, project) => x
.SetProjectFile(project)));
});

Target CompileFrameworkReproductions => _ => _
Expand Down Expand Up @@ -734,7 +735,7 @@ _ when projectPath.ToString().Contains("Samples.OracleMDA") => false,
.SetProperty("DeployOnBuild", true)
.SetProperty("PublishProfile", publishProfile)
.SetMaxCpuCount(null)
.CombineWith(aspnetProjects, (c, project ) => c
.CombineWith(aspnetProjects, (c, project) => c
.SetTargetPath(project))
);
});
Expand All @@ -745,6 +746,7 @@ _ when projectPath.ToString().Contains("Samples.OracleMDA") => false,
.After(CompileIntegrationTests)
.After(CompileSamples)
.After(CompileFrameworkReproductions)
.After(BuildWindowsIntegrationTests)
.Requires(() => IsWin)
.Executes(() =>
{
Expand All @@ -760,6 +762,7 @@ _ when projectPath.ToString().Contains("Samples.OracleMDA") => false,
.EnableNoRestore()
.EnableNoBuild()
.When(!string.IsNullOrEmpty(Filter), c => c.SetFilter(Filter))
.When(CodeCoverage, ConfigureCodeCoverage)
.CombineWith(ParallelIntegrationTests, (s, project) => s
.EnableTrxLogOutput(GetResultsDirectory(project))
.SetProjectFile(project)), degreeOfParallelism: 4);
Expand All @@ -774,6 +777,7 @@ _ when projectPath.ToString().Contains("Samples.OracleMDA") => false,
.EnableNoRestore()
.EnableNoBuild()
.SetFilter(Filter ?? "(RunOnWindows=True|Category=Smoke)&LoadFromGAC!=True&IIS!=True")
.When(CodeCoverage, ConfigureCodeCoverage)
.CombineWith(ClrProfilerIntegrationTests, (s, project) => s
.EnableTrxLogOutput(GetResultsDirectory(project))
.SetProjectFile(project)));
Expand Down Expand Up @@ -801,9 +805,11 @@ _ when projectPath.ToString().Contains("Samples.OracleMDA") => false,
.SetDotnetPath(Platform)
.SetConfiguration(BuildConfiguration)
.SetTargetPlatform(Platform)
.When(Framework != null, o => o.SetFramework(Framework))
.EnableNoRestore()
.EnableNoBuild()
.SetFilter(Filter ?? "(RunOnWindows=True|Category=Smoke)&LoadFromGAC=True")
.When(CodeCoverage, ConfigureCodeCoverage)
.CombineWith(ClrProfilerIntegrationTests, (s, project) => s
.EnableTrxLogOutput(GetResultsDirectory(project))
.SetProjectFile(project)));
Expand Down Expand Up @@ -903,6 +909,8 @@ var name when multiApiProjects.Contains(name) => false,
.SetFramework(Framework)
// .SetTargetPlatform(Platform)
.SetNoWarnDotNetCore3()
.SetProperty("ExcludeManagedProfiler", "true")
.SetProperty("ExcludeNativeProfiler", "true")
.SetProperty("ManagedProfilerOutputDirectory", TracerHomeDirectory)
.When(TestAllPackageVersions, o => o.SetProperty("TestAllPackageVersions", "true"))
.When(!string.IsNullOrEmpty(NugetPackageDirectory), o => o.SetPackageDirectory(NugetPackageDirectory))
Expand Down Expand Up @@ -939,7 +947,7 @@ var name when multiApiProjects.Contains(name) => false,
{
// Build and restore for all versions
// Annoyingly this rebuilds everything again and again.
var targets = new [] { "RestoreSamplesForPackageVersionsOnly", "RestoreAndBuildSamplesForPackageVersionsOnly" };
var targets = new[] { "RestoreSamplesForPackageVersionsOnly", "RestoreAndBuildSamplesForPackageVersionsOnly" };

// /nowarn:NU1701 - Package 'x' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.1'.
DotNetMSBuild(x => x
Expand All @@ -949,6 +957,8 @@ var name when multiApiProjects.Contains(name) => false,
.SetProperty("TargetFramework", Framework.ToString())
.SetProperty("ManagedProfilerOutputDirectory", TracerHomeDirectory)
.SetProperty("BuildInParallel", "true")
.SetProperty("ExcludeManagedProfiler", "true")
.SetProperty("ExcludeNativeProfiler", "true")
.SetProcessArgumentConfigurator(arg => arg.Add("/nowarn:NU1701"))
.AddProcessEnvironmentVariable("TestAllPackageVersions", "true")
.When(TestAllPackageVersions, o => o.SetProperty("TestAllPackageVersions", "true"))
Expand Down Expand Up @@ -1031,6 +1041,7 @@ var name when multiApiProjects.Contains(name) => false,
.SetFilter(filter)
.When(TestAllPackageVersions, o => o
.SetProcessEnvironmentVariable("TestAllPackageVersions", "true"))
.When(CodeCoverage, ConfigureCodeCoverage)
.CombineWith(ParallelIntegrationTests, (s, project) => s
.EnableTrxLogOutput(GetResultsDirectory(project))
.SetProjectFile(project)),
Expand All @@ -1047,6 +1058,7 @@ var name when multiApiProjects.Contains(name) => false,
.SetFilter(filter)
.When(TestAllPackageVersions, o => o
.SetProcessEnvironmentVariable("TestAllPackageVersions", "true"))
.When(CodeCoverage, ConfigureCodeCoverage)
.CombineWith(ClrProfilerIntegrationTests, (s, project) => s
.EnableTrxLogOutput(GetResultsDirectory(project))
.SetProjectFile(project))
Expand Down Expand Up @@ -1079,6 +1091,22 @@ private void MoveLogsToBuildData()
}
}

private DotNetTestSettings ConfigureCodeCoverage(DotNetTestSettings settings)
{
var strongNameKeyPath = Solution.Directory / "Datadog.Trace.snk";

return settings.SetDataCollector("XPlat Code Coverage")
.SetProcessArgumentConfigurator(
args =>
args.Add("--")
.Add("RunConfiguration.DisableAppDomain=true") // https://github.com/coverlet-coverage/coverlet/issues/347
.Add("DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.SkipAutoProps=true")
.Add("DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura")
.Add($"DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.StrongNameKey=\"{strongNameKeyPath}\"")
.Add("DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Exclude=[*]Datadog.Trace.Vendors.*,")
.Add("DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Include=\"[Datadog.Trace.ClrProfiler.*]*,[Datadog.Trace]*,[Datadog.Trace.AspNet]*\""));
}

protected override void OnTargetStart(string target)
{
if (PrintDriveSpace)
Expand All @@ -1092,7 +1120,7 @@ protected override void OnTargetStart(string target)

static string PrettyPrint(long bytes)
{
var power = Math.Min((int) Math.Log(bytes, 1000), 4);
var power = Math.Min((int)Math.Log(bytes, 1000), 4);
var normalised = bytes / Math.Pow(1000, power);
return power switch
{
Expand Down
3 changes: 3 additions & 0 deletions build/_build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ partial class Build : NukeBuild
[Parameter("Override the default test filters for integration tests. (Optional)")]
readonly string Filter;

[Parameter("Enables code coverage")]
readonly bool CodeCoverage;

Target Info => _ => _
.Description("Describes the current configuration")
.Before(Clean, Restore, BuildTracerHome)
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ services:
args:
- DOTNETSDK_VERSION=${dotnetCoreSdk5Version:-5.0.103}
image: dd-trace-dotnet/${baseImage:-debian}-tester
command: dotnet /build/bin/Debug/_build.dll RunLinuxIntegrationTests --framework ${framework:-netcoreapp3.1}
command: dotnet /build/bin/Debug/_build.dll RunLinuxIntegrationTests --framework ${framework:-netcoreapp3.1} --code-coverage
volumes:
- ./:/project
environment:
Expand Down
1 change: 1 addition & 0 deletions nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="Azure" value="https://pkgs.dev.azure.com/datadoghq/dd-trace-dotnet/_packaging/Public_Feed/nuget/v3/index.json" />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public AspNetMvc4Tests(IisFixture iisFixture, ITestOutputHelper output, bool ena
}

_iisFixture = iisFixture;
_iisFixture.ShutdownPath = "/home/shutdown";
_iisFixture.TryStartIis(this, classicMode);
_testName = nameof(AspNetMvc4Tests)
+ (enableCallTarget ? ".CallSite" : ".CallTarget")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public AspNetMvc5Tests(IisFixture iisFixture, ITestOutputHelper output, bool ena
}

_iisFixture = iisFixture;
_iisFixture.ShutdownPath = "/home/shutdown";
_iisFixture.TryStartIis(this, classicMode);
_testName = nameof(AspNetMvc5Tests)
+ (enableCallTarget ? ".CallSite" : ".CallTarget")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public AspNetWebApi2Tests(IisFixture iisFixture, ITestOutputHelper output, bool
}

_iisFixture = iisFixture;
_iisFixture.ShutdownPath = "/home/shutdown";
_iisFixture.TryStartIis(this, classicMode);
_testName = nameof(AspNetWebApi2Tests)
+ (enableCallTarget ? ".CallSite" : ".CallTarget")
Expand Down
Loading