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

[build] Build tracer with ReadyToRun #5962

Merged
merged 40 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
21b43ba
add fields to build schema
duncanista Aug 29, 2024
c529b4d
add `GetDefaultRuntimeIdentifier` method
duncanista Aug 29, 2024
e298952
add `PublishManagedTracerR2R`
duncanista Aug 29, 2024
1402dbd
add `BuildManagedTracerHomeR2R` and define readonlys
duncanista Aug 29, 2024
190beb0
add `build_linux_tracer_r2r` pipeline
duncanista Aug 29, 2024
3007341
target only `net6.0`
duncanista Aug 29, 2024
d39d92d
typo
duncanista Aug 29, 2024
146abd0
restore before publish
duncanista Aug 29, 2024
7b70721
add condition so it works with R2R
duncanista Aug 29, 2024
41c1004
revert adding suffix for universal
duncanista Aug 30, 2024
f356c79
typo
duncanista Aug 30, 2024
37b150a
update it to use a parameter, instead of multiple targets
duncanista Aug 30, 2024
1ddbb97
update pipeline
duncanista Aug 30, 2024
eeac770
see if this works in `ZipMonitoringHomeLinux`
duncanista Aug 30, 2024
3c1be3c
remove `-r2r` suffix
duncanista Aug 31, 2024
32b5dd4
add back suffix
duncanista Aug 31, 2024
88fe42c
maybe add `r2r` in profiler?
duncanista Aug 31, 2024
68f9f6c
maybe download binaries in right directory?
duncanista Aug 31, 2024
0a5f5da
Merge branch 'master' into jordan.gonzalez/ready-to-run/linux-deb
duncanista Sep 3, 2024
9f1cd5c
make `r2r` its own build
duncanista Sep 3, 2024
9a82f05
Merge branch 'jordan.gonzalez/ready-to-run/linux-deb' of ssh://github…
duncanista Sep 3, 2024
ab453f3
fmt
duncanista Sep 3, 2024
072e9e2
add `download-serverless-artifacts` job
duncanista Sep 3, 2024
02ee61f
modify serverless pipeline trigger
duncanista Sep 3, 2024
30dc340
add needs to layer trigger
duncanista Sep 3, 2024
8b1e323
add `UPSTREAM_REF` to pipeline
duncanista Sep 3, 2024
b5106c9
add r2r for `arm64`
duncanista Sep 3, 2024
262fb7d
download artifacts in gitlab for `arm64`
duncanista Sep 3, 2024
39efff1
restart `downloadUrl` on every artifact
duncanista Sep 3, 2024
c00ccab
add alpine runtime identifiers
duncanista Sep 4, 2024
5139c93
add `Build` so we can set dynamic parameter value
duncanista Sep 4, 2024
c57828d
Merge branch 'master' into jordan.gonzalez/ready-to-run/linux-deb
duncanista Sep 5, 2024
13379b9
remove changes in `missing-nullability-files.csv
duncanista Sep 5, 2024
b636d14
Merge branch 'jordan.gonzalez/ready-to-run/linux-deb' of ssh://github…
duncanista Sep 5, 2024
39155b4
remove changes for lambda
duncanista Sep 5, 2024
a0e7f3a
remove commented script
duncanista Sep 6, 2024
6d282f3
Update tracer/build/_build/Build.Utilities.cs
duncanista Sep 6, 2024
2e4794a
make `aws-lambda-layer` a manual job
duncanista Sep 6, 2024
6620c5d
Merge branch 'jordan.gonzalez/ready-to-run/linux-deb' of ssh://github…
duncanista Sep 6, 2024
106aa8c
Merge branch 'master' into jordan.gonzalez/ready-to-run/linux-deb
duncanista Sep 6, 2024
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
106 changes: 106 additions & 0 deletions .azure-pipelines/ultimate-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,69 @@ stages:
displayName: publish tracer and native loader test results
artifact: build_linux_tracer_unit_tests_results_$(artifactSuffix)_$(System.JobAttempt)

- stage: build_linux_tracer_r2r
dependsOn: [merge_commit_id]
variables:
targetShaId: $[ stageDependencies.merge_commit_id.fetch.outputs['set_sha.sha']]
targetBranch: $[ stageDependencies.merge_commit_id.fetch.outputs['set_sha.branch']]
jobs:
- template: steps/update-github-status-jobs.yml
parameters:
jobs: [build]

- job: build
timeoutInMinutes: 60 #default value
dependsOn: []
pool:
name: azure-linux-scale-set-2

steps:
- template: steps/clone-repo.yml
parameters:
targetShaId: $(targetShaId)
targetBranch: $(targetBranch)

- template: steps/run-in-docker.yml
parameters:
build: true
target: builder
baseImage: debian
command: "Clean CompileManagedLoader"
retryCountForRunCommand: 1

- template: steps/run-in-docker.yml
parameters:
build: true
target: builder
baseImage: centos7
useNativeSdkVersion: true
command: "BuildNativeTracerHome CompileTracerNativeTests RunTracerNativeTests"
retryCountForRunCommand: 1
apiKey: $(DD_LOGGER_DD_API_KEY)

- template: steps/run-in-docker.yml
parameters:
target: builder
baseImage: debian
command: "BuildManagedTracerHomeR2R ExtractDebugInfoLinux"
retryCountForRunCommand: 1

- publish: $(monitoringHome)
displayName: Uploading linux tracer home artifact
artifact: linux-tracer-home-linux-x64-r2r

- publish: $(System.DefaultWorkingDirectory)
displayName: Upload working directory after the build
artifact: build-linux-x64-r2r-working-directory

- publish: $(symbols)
displayName: Upload linux tracer symbols
artifact: linux-tracer-symbols-linux-x64-r2r

- publish: artifacts/build_data/tests
displayName: publish tracer and native loader test results
artifact: build_linux_tracer_unit_tests_results_linux-x64-r2r_$(System.JobAttempt)

- stage: build_linux_universal
dependsOn: [merge_commit_id]
variables:
Expand Down Expand Up @@ -657,6 +720,49 @@ stages:
displayName: Upload linux tracer symbols
artifact: linux-tracer-symbols-$(artifactSuffix)

- stage: build_arm64_tracer_r2r
dependsOn: [merge_commit_id]
variables:
targetShaId: $[ stageDependencies.merge_commit_id.fetch.outputs['set_sha.sha']]
targetBranch: $[ stageDependencies.merge_commit_id.fetch.outputs['set_sha.branch']]
jobs:
- template: steps/update-github-status-jobs.yml
parameters:
jobs: [build]

- job: build
timeoutInMinutes: 60 #default value
dependsOn: []

pool:
name: aws-arm64-auto-scaling
workspace:
clean: all
steps:
- template: steps/clone-repo.yml
parameters:
targetShaId: $(targetShaId)
targetBranch: $(targetBranch)
- template: steps/run-in-docker.yml
parameters:
build: true
target: builder
baseImage: debian
command: "Clean CompileManagedLoader BuildNativeTracerHome BuildManagedTracerHomeR2R ExtractDebugInfoLinux"
retryCountForRunCommand: 1

- publish: $(monitoringHome)
displayName: Uploading linux tracer home artifact
artifact: linux-tracer-home-linux-arm64-r2r

- publish: $(System.DefaultWorkingDirectory)
displayName: Upload working directory after the build
artifact: build-linux-arm64-r2r-working-directory

- publish: $(symbols)
displayName: Upload linux tracer symbols
artifact: linux-tracer-symbols-linux-arm64-r2r

- stage: build_arm64_profiler
dependsOn: [merge_commit_id]
variables:
Expand Down
31 changes: 31 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,37 @@ deploy_to_reliability_env:
rules:
- when: never # dd-trace-dotnet does not use reliability environment

download-serverless-artifacts:
stage: package
image: registry.ddbuild.io/docker:20.10.13-gbi-focal
tags: [ "arch:amd64" ]
needs: []
rules:
- if: $DOTNET_PACKAGE_VERSION
when: on_success
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(-prerelease)?$/' # Manually triggered as artifacts are from the Github release
when: manual
allow_failure: false
- when: delayed # Artifacts come from Azure pipeline, wait a reasonable time before polling
start_in: 15 minutes
script:
- .gitlab/download-serverless-artifacts.sh
artifacts:
expire_in: 2 weeks
paths:
- artifacts

aws-lambda-layer:
stage: package
needs: [download-serverless-artifacts]
trigger:
project: DataDog/dd-trace-dotnet-aws-lambda-layer
branch: jordan.gonzalez/add-gitlab-ci
strategy: depend
variables:
UPSTREAM_PIPELINE_ID: $CI_PIPELINE_ID
allow_failure: true

benchmark-serverless:
stage: benchmarks
image: registry.ddbuild.io/ci/serverless-tools:1
Expand Down
86 changes: 86 additions & 0 deletions .gitlab/download-serverless-artifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash
#
# This scripts downloads the necessary binaries to be used for the AWS Lambda Layer.
# This artifacts include: Tracer and ClrProfiler
#

set -eo pipefail

#Create a directory to store the files
target_dir=artifacts
mkdir -p $target_dir

# if [ -n "$CI_COMMIT_TAG" ] || [ -n "$DOTNET_PACKAGE_VERSION" ]; then
# echo "Downloading artifacts from Github"
# VERSION=${DOTNET_PACKAGE_VERSION:-${CI_COMMIT_TAG##v}} # Use DOTNET_PACKAGE_VERSION if it exists, otherwise use CI_COMMIT_TAG without the v

# for SUFFIX in "" ".arm64"; do
# curl --location --fail \
# --output $target_dir/datadog-dotnet-apm-${VERSION}${SUFFIX}.tar.gz \
# "https://github.com/DataDog/dd-trace-dotnet/releases/download/v${VERSION}/datadog-dotnet-apm-${VERSION}${SUFFIX}.tar.gz"
# done

# echo -n $VERSION > $target_dir/version.txt
# exit 0
# fi

branchName="refs/heads/$CI_COMMIT_BRANCH"

echo "Looking for azure devops PR builds for branch '$branchName' for commit '$CI_COMMIT_SHA' to start"

# We should _definitely_ have the build by now, so if not, there probably won't be one
# Check for PR builds first (as more likely to be "full" builds)
allBuildsForPrUrl="https://dev.azure.com/datadoghq/dd-trace-dotnet/_apis/build/builds?api-version=7.1&definitions=54&\$top=100&queryOrder=queueTimeDescending&reasonFilter=pullRequest"
buildId=$(curl -sS $allBuildsForPrUrl | jq --arg version $CI_COMMIT_SHA --arg branch $CI_COMMIT_BRANCH '.value[] | select(.triggerInfo["pr.sourceBranch"] == $branch and .triggerInfo["pr.sourceSha"] == $version) | .id' | head -n 1)

if [ -z "${buildId}" ]; then
echo "No PR builds found for commit '$CI_COMMIT_SHA' on branch '$branchName'. Checking for standalone builds..."
allBuildsForBranchUrl="https://dev.azure.com/datadoghq/dd-trace-dotnet/_apis/build/builds?api-version=7.1&definitions=54&\$top=10&queryOrder=queueTimeDescending&branchName=$branchName&reasonFilter=manual,individualCI"
buildId=$(curl -sS $allBuildsForBranchUrl | jq --arg version $CI_COMMIT_SHA '.value[] | select(.sourceVersion == $version and .reason != "schedule") | .id' | head -n 1)
fi

if [ -z "${buildId}" ]; then
echo "No build found for commit '$CI_COMMIT_SHA' on branch '$branchName' (including PRs)"
exit 1
fi

echo "Found build with id '$buildId' for commit '$CI_COMMIT_SHA' on branch '$branchName'"

architectures=("x64" "arm64")
for architecture in "${architectures[@]}"; do
echo "Looking for artifacts for architecture '$architecture'"

artifacts=("linux-tracer-home-linux-$architecture-r2r" "linux-universal-home-linux-$architecture")

# Now try to download the artifacts from the build
for artifactName in "${artifacts[@]}"; do
artifactsUrl="https://dev.azure.com/datadoghq/dd-trace-dotnet/_apis/build/builds/$buildId/artifacts?api-version=7.1&artifactName=$artifactName"

# Keep trying to get the artifact for 30 minutes
downloadUrl=""
TIMEOUT=1800
STARTED=0
until (( STARTED == TIMEOUT )) || [ ! -z "${downloadUrl}" ] ; do
Comment on lines +45 to +49
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI this will 30mins for the first artifact and then 30 mins for the next one too. That's prob not what we really want, but it's not a big deal, and prob not worth fixing frankly! :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine, I tested multiple times, and some artifacts were not available, so I think this is OK

echo "Checking for '$artifactName' at '$artifactsUrl'..."
# If the artifact doesn't exist, .resource.downloadUrl will be null, so we filter that out
downloadUrl=$(curl -s $artifactsUrl | jq -r '.resource.downloadUrl | select( . != null )')
sleep 100
(( STARTED += 100 ))
done
(( STARTED < TIMEOUT ))

if [ -z "${downloadUrl}" ]; then
echo "No downloadUrl found after 30 minutes for commit '$CI_COMMIT_SHA' on branch '$branchName'"
exit 1
fi

echo "Downloading '$artifactName' from '$downloadUrl'..."
curl -o $target_dir/artifacts.zip "$downloadUrl"
unzip $target_dir/artifacts.zip -d $target_dir/$architecture
mv $target_dir/$architecture/$artifactName/* $target_dir/$architecture
rm -rf $target_dir/artifacts.zip
rmdir $target_dir/$architecture/$artifactName
done
done

ls -l $target_dir
8 changes: 8 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@
"type": "string",
"description": "Root directory during build execution"
},
"RuntimeIdentifier": {
"type": "string",
"description": "RuntimeIdentifier sets the target platform for ReadyToRun assemblies in 'PublishManagedTracerR2R'.See https://learn.microsoft.com/en-us/dotnet/core/rid-catalog"
},
"SampleName": {
"type": "string",
"description": "The sample name to execute when running or building sample apps"
Expand Down Expand Up @@ -296,6 +300,7 @@
"BuildIisSampleApp",
"BuildLinuxIntegrationTests",
"BuildManagedTracerHome",
"BuildManagedTracerHomeR2R",
"BuildMsi",
"BuildNativeLoader",
"BuildNativeTracerHome",
Expand Down Expand Up @@ -405,6 +410,7 @@
"PublishDdDotnetSymbolsWindows",
"PublishIisSamples",
"PublishManagedTracer",
"PublishManagedTracerR2R",
"PublishNativeLoader",
"PublishNativeLoaderOsx",
"PublishNativeLoaderUnix",
Expand Down Expand Up @@ -515,6 +521,7 @@
"BuildIisSampleApp",
"BuildLinuxIntegrationTests",
"BuildManagedTracerHome",
"BuildManagedTracerHomeR2R",
"BuildMsi",
"BuildNativeLoader",
"BuildNativeTracerHome",
Expand Down Expand Up @@ -624,6 +631,7 @@
"PublishDdDotnetSymbolsWindows",
"PublishIisSamples",
"PublishManagedTracer",
"PublishManagedTracerR2R",
"PublishNativeLoader",
"PublishNativeLoaderOsx",
"PublishNativeLoaderUnix",
Expand Down
47 changes: 37 additions & 10 deletions tracer/build/_build/Build.Steps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,23 +639,50 @@ async Task DownloadWafVersion(string libddwafVersion = null, string uncompressFo
.EnableNoRestore()
.CombineWith(targetFrameworks, (p, framework) => p
.SetFramework(framework)
.SetOutput(MonitoringHomeDirectory / framework)));
.SetOutput(MonitoringHomeDirectory / framework))
);
});

Target PublishManagedTracerR2R => _ => _
.Unlisted()
.After(CompileManagedSrc)
.Executes(() =>
{
var targetFramework = TargetFramework.NET6_0;

// Needed as we need to restore with the RuntimeIdentifier
DotNetRestore(s => s
.SetProjectFile(Solution.GetProject(Projects.DatadogTraceMsBuild))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need this at all? 🤔 I'm about 90% sure you don't need this dll at all, and should be stripping it out of the layer. @tonyredondo can you confirm?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's stripped down later, but I want to make sure I build as close as possible to the current process, don't want to diverge much in case in the future we need to use some r2r binaries for other platforms like Azure!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for info, I believe this is literally only used if you're using the tracer as part of your build process, so I think there's basically no chance you'll need it 😃

.SetPublishReadyToRun(true)
.SetRuntime(RuntimeIdentifier)
);

DotNetPublish(s => s
.SetProject(Solution.GetProject(Projects.DatadogTraceMsBuild))
.SetConfiguration(BuildConfiguration)
.SetTargetPlatformAnyCPU()
.SetPublishReadyToRun(true)
.SetRuntime(RuntimeIdentifier)
.SetSelfContained(false)
.SetFramework(targetFramework)
.SetOutput(MonitoringHomeDirectory / targetFramework)
);
});

Target PublishNativeSymbolsWindows => _ => _
.Unlisted()
.OnlyWhenStatic(() => IsWin)
.After(CompileTracerNativeSrc, PublishManagedTracer)
.Executes(() =>
{
foreach (var architecture in ArchitecturesForPlatformForTracer)
{
.Unlisted()
.OnlyWhenStatic(() => IsWin)
.After(CompileTracerNativeSrc, PublishManagedTracer)
.Executes(() =>
{
foreach (var architecture in ArchitecturesForPlatformForTracer)
{
var source = NativeTracerProject.Directory / "bin" / BuildConfiguration / architecture.ToString() /
$"{NativeTracerProject.Name}.pdb";
var dest = SymbolsDirectory / $"win-{architecture}" / Path.GetFileName(source);
CopyFile(source, dest, FileExistsPolicy.Overwrite);
}
});
}
});

Target PublishDdDotnetSymbolsWindows => _ => _
.Unlisted()
Expand Down
18 changes: 17 additions & 1 deletion tracer/build/_build/Build.Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ partial class Build
.Executes(ReplaceReceivedFilesInSnapshots);

Target PrintSnapshotsDiff => _ => _
.Description("Prints snapshots differences from the current tests")
.Description("Prints snapshots differences --compatible-runtimes $compatible_runtimesxfrom the current tests")
duncanista marked this conversation as resolved.
Show resolved Hide resolved
.AssuredAfterFailure()
.OnlyWhenStatic(() => IsServerBuild)
.Executes(() =>
Expand Down Expand Up @@ -492,6 +492,22 @@ private static MSBuildTargetPlatform GetDefaultTargetPlatform()

return MSBuildTargetPlatform.x64;
}

private static string GetDefaultRuntimeIdentifier(bool isAlpine)
{
// https://learn.microsoft.com/en-us/dotnet/core/rid-catalog
return (Platform, (string)GetDefaultTargetPlatform()) switch
{
(PlatformFamily.Windows, "x86") => "win-x86",
(PlatformFamily.Windows, "x64") => "win-x64",

(PlatformFamily.Linux, "x64") => isAlpine ? "linux-musl-x64" : "linux-x64",
(PlatformFamily.Linux, "ARM64" or "ARM64EC") => isAlpine ? "linux-musl-arm64" : "linux-arm64",

(PlatformFamily.OSX, "ARM64" or "ARM64EC") => "osx-arm64",
_ => null
};
}

private static MSBuildTargetPlatform ARM64TargetPlatform = (MSBuildTargetPlatform)"ARM64";
private static MSBuildTargetPlatform ARM64ECTargetPlatform = (MSBuildTargetPlatform)"ARM64EC";
Expand Down
Loading
Loading