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

[dotnet-auto] Add support for musl based images #2103

Merged
merged 16 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions .chloggen/1849-dotnet-auto-musl-support.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
component: autoinstrumentation

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: .NET Automatic Instrumentation support for alpine-based images
Kielek marked this conversation as resolved.
Show resolved Hide resolved

# One or more tracking issues related to the change
issues: [1849]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,13 @@ Python:
instrumentation.opentelemetry.io/inject-python: "true"
```

DotNet:
.NET:
.NET auto-instrumentation also honors an annotation that will be used to set the .NET runtime versions. There are two versions supported `linux-glibc` and `linux-musl`.
Kielek marked this conversation as resolved.
Show resolved Hide resolved
By default `linux-glibc` is used.
Kielek marked this conversation as resolved.
Show resolved Hide resolved
```bash
instrumentation.opentelemetry.io/inject-dotnet: "true"
instrumentation.opentelemetry.io/otel-dotnet-auto-runtime: "linux-glibc" # for Linux glibc based images, this is default value and can be omitted
instrumentation.opentelemetry.io/otel-dotnet-auto-runtime: "linux-musl" # for Linux musl based images
```

Go:
Expand Down
1 change: 1 addition & 0 deletions pkg/instrumentation/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
annotationInjectNodeJS = "instrumentation.opentelemetry.io/inject-nodejs"
annotationInjectPython = "instrumentation.opentelemetry.io/inject-python"
annotationInjectDotNet = "instrumentation.opentelemetry.io/inject-dotnet"
annotationDotNetRuntime = "instrumentation.opentelemetry.io/otel-dotnet-auto-runtime"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Annotation name is different than discussed in #1849
I have tried to make it compatible with nnotationGoExecPath

annotationInjectGo = "instrumentation.opentelemetry.io/inject-go"
annotationGoExecPath = "instrumentation.opentelemetry.io/otel-go-auto-target-exe"
annotationInjectSdk = "instrumentation.opentelemetry.io/inject-sdk"
Expand Down
19 changes: 17 additions & 2 deletions pkg/instrumentation/dotnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ const (
envDotNetOTelAutoHome = "OTEL_DOTNET_AUTO_HOME"
dotNetCoreClrEnableProfilingEnabled = "1"
dotNetCoreClrProfilerID = "{918728DD-259F-4A6A-AC2B-B85E1B658318}"
dotNetCoreClrProfilerPath = "/otel-auto-instrumentation/linux-x64/OpenTelemetry.AutoInstrumentation.Native.so"
dotNetCoreClrProfilerGlibcPath = "/otel-auto-instrumentation/linux-x64/OpenTelemetry.AutoInstrumentation.Native.so"
dotNetCoreClrProfilerMuslPath = "/otel-auto-instrumentation/linux-musl-x64/OpenTelemetry.AutoInstrumentation.Native.so"
dotNetAdditionalDepsPath = "/otel-auto-instrumentation/AdditionalDeps"
dotNetOTelAutoHomePath = "/otel-auto-instrumentation"
dotNetSharedStorePath = "/otel-auto-instrumentation/store"
dotNetStartupHookPath = "/otel-auto-instrumentation/net/OpenTelemetry.AutoInstrumentation.StartupHook.dll"
dotNetGlibcLinuxRuntime = "linux-glibc"
dotNetMuslLinuxRuntime = "linux-musl"
Kielek marked this conversation as resolved.
Show resolved Hide resolved
)

func injectDotNetSDK(dotNetSpec v1alpha1.DotNet, pod corev1.Pod, index int) (corev1.Pod, error) {
Expand All @@ -62,6 +65,18 @@ func injectDotNetSDK(dotNetSpec v1alpha1.DotNet, pod corev1.Pod, index int) (cor
return pod, errors.New("OTEL_DOTNET_AUTO_HOME environment variable is already set in the .NET instrumentation spec")
}

runtime := pod.Annotations[annotationDotNetRuntime]
coreClrProfilerPath := ""

Kielek marked this conversation as resolved.
Show resolved Hide resolved
switch runtime {
case "", dotNetGlibcLinuxRuntime:
coreClrProfilerPath = dotNetCoreClrProfilerGlibcPath
case dotNetMuslLinuxRuntime:
coreClrProfilerPath = dotNetCoreClrProfilerMuslPath
default:
return pod, errors.New("provided instrumentation.opentelemetry.io/dotnet-runtime annotation value is not supported")
Kielek marked this conversation as resolved.
Show resolved Hide resolved
}

// inject .NET instrumentation spec env vars.
for _, env := range dotNetSpec.Env {
idx := getIndexOfEnv(container.Env, env.Name)
Expand All @@ -79,7 +94,7 @@ func injectDotNetSDK(dotNetSpec v1alpha1.DotNet, pod corev1.Pod, index int) (cor

setDotNetEnvVar(container, envDotNetCoreClrProfiler, dotNetCoreClrProfilerID, doNotConcatEnvValues)

setDotNetEnvVar(container, envDotNetCoreClrProfilerPath, dotNetCoreClrProfilerPath, doNotConcatEnvValues)
setDotNetEnvVar(container, envDotNetCoreClrProfilerPath, coreClrProfilerPath, doNotConcatEnvValues)

setDotNetEnvVar(container, envDotNetStartupHook, dotNetStartupHookPath, concatEnvValues)

Expand Down
208 changes: 207 additions & 1 deletion pkg/instrumentation/dotnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
)
Expand Down Expand Up @@ -85,7 +86,7 @@ func TestInjectDotNetSDK(t *testing.T) {
},
{
Name: envDotNetCoreClrProfilerPath,
Value: dotNetCoreClrProfilerPath,
Value: dotNetCoreClrProfilerGlibcPath,
},
{
Name: envDotNetStartupHook,
Expand Down Expand Up @@ -365,6 +366,211 @@ func TestInjectDotNetSDK(t *testing.T) {
},
err: fmt.Errorf("OTEL_DOTNET_AUTO_HOME environment variable is already set in the .NET instrumentation spec"),
},
{
name: "runtime linux-glibc",
DotNet: v1alpha1.DotNet{Image: "foo/bar:1", Env: []corev1.EnvVar{}, Resources: testResourceRequirements},
pod: corev1.Pod{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{},
},
},
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
annotationDotNetRuntime: dotNetGlibcLinuxRuntime,
},
},
},
expected: corev1.Pod{
Spec: corev1.PodSpec{
Volumes: []corev1.Volume{
{
Name: volumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{
SizeLimit: &defaultVolumeLimitSize,
},
},
},
},
InitContainers: []corev1.Container{
{
Name: initContainerName,
Image: "foo/bar:1",
Command: []string{"cp", "-a", "/autoinstrumentation/.", "/otel-auto-instrumentation/"},
VolumeMounts: []corev1.VolumeMount{{
Name: volumeName,
MountPath: "/otel-auto-instrumentation",
}},
Resources: testResourceRequirements,
},
},
Containers: []corev1.Container{
{
VolumeMounts: []corev1.VolumeMount{
{
Name: volumeName,
MountPath: "/otel-auto-instrumentation",
},
},
Env: []corev1.EnvVar{
{
Name: envDotNetCoreClrEnableProfiling,
Value: dotNetCoreClrEnableProfilingEnabled,
},
{
Name: envDotNetCoreClrProfiler,
Value: dotNetCoreClrProfilerID,
},
{
Name: envDotNetCoreClrProfilerPath,
Value: dotNetCoreClrProfilerGlibcPath,
},
{
Name: envDotNetStartupHook,
Value: dotNetStartupHookPath,
},
{
Name: envDotNetAdditionalDeps,
Value: dotNetAdditionalDepsPath,
},
{
Name: envDotNetOTelAutoHome,
Value: dotNetOTelAutoHomePath,
},
{
Name: envDotNetSharedStore,
Value: dotNetSharedStorePath,
},
},
},
},
},
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
annotationDotNetRuntime: dotNetGlibcLinuxRuntime,
},
},
},
err: nil,
},
{
name: "runtime linux-musl",
DotNet: v1alpha1.DotNet{Image: "foo/bar:1", Env: []corev1.EnvVar{}, Resources: testResourceRequirements},
pod: corev1.Pod{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{},
},
},
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
annotationDotNetRuntime: dotNetMuslLinuxRuntime,
},
},
},
expected: corev1.Pod{
Spec: corev1.PodSpec{
Volumes: []corev1.Volume{
{
Name: volumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{
SizeLimit: &defaultVolumeLimitSize,
},
},
},
},
InitContainers: []corev1.Container{
{
Name: initContainerName,
Image: "foo/bar:1",
Command: []string{"cp", "-a", "/autoinstrumentation/.", "/otel-auto-instrumentation/"},
VolumeMounts: []corev1.VolumeMount{{
Name: volumeName,
MountPath: "/otel-auto-instrumentation",
}},
Resources: testResourceRequirements,
},
},
Containers: []corev1.Container{
{
VolumeMounts: []corev1.VolumeMount{
{
Name: volumeName,
MountPath: "/otel-auto-instrumentation",
},
},
Env: []corev1.EnvVar{
{
Name: envDotNetCoreClrEnableProfiling,
Value: dotNetCoreClrEnableProfilingEnabled,
},
{
Name: envDotNetCoreClrProfiler,
Value: dotNetCoreClrProfilerID,
},
{
Name: envDotNetCoreClrProfilerPath,
Value: dotNetCoreClrProfilerMuslPath,
},
{
Name: envDotNetStartupHook,
Value: dotNetStartupHookPath,
},
{
Name: envDotNetAdditionalDeps,
Value: dotNetAdditionalDepsPath,
},
{
Name: envDotNetOTelAutoHome,
Value: dotNetOTelAutoHomePath,
},
{
Name: envDotNetSharedStore,
Value: dotNetSharedStorePath,
},
},
},
},
},
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
annotationDotNetRuntime: dotNetMuslLinuxRuntime,
},
},
},
err: nil,
},
{
name: "runtime not-supported",
DotNet: v1alpha1.DotNet{Image: "foo/bar:1", Env: []corev1.EnvVar{}, Resources: testResourceRequirements},
pod: corev1.Pod{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{},
},
},
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
annotationDotNetRuntime: "not-supported",
},
},
},
expected: corev1.Pod{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{},
},
},
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
annotationDotNetRuntime: "not-supported",
},
},
},
err: fmt.Errorf("provided instrumentation.opentelemetry.io/dotnet-runtime annotation value is not supported"),
},
}

for _, test := range tests {
Expand Down
8 changes: 5 additions & 3 deletions pkg/instrumentation/podmutator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,8 @@ func TestMutatePod(t *testing.T) {
pod: corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
annotationInjectDotNet: "true",
annotationInjectDotNet: "true",
annotationDotNetRuntime: dotNetMuslLinuxRuntime,
},
},
Spec: corev1.PodSpec{
Expand All @@ -924,7 +925,8 @@ func TestMutatePod(t *testing.T) {
expected: corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
annotationInjectDotNet: "true",
annotationInjectDotNet: "true",
annotationDotNetRuntime: dotNetMuslLinuxRuntime,
},
},
Spec: corev1.PodSpec{
Expand Down Expand Up @@ -971,7 +973,7 @@ func TestMutatePod(t *testing.T) {
},
{
Name: envDotNetCoreClrProfilerPath,
Value: dotNetCoreClrProfilerPath,
Value: dotNetCoreClrProfilerMuslPath,
},
{
Name: envDotNetStartupHook,
Expand Down
2 changes: 1 addition & 1 deletion pkg/instrumentation/sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ func TestInjectDotNet(t *testing.T) {
},
{
Name: envDotNetCoreClrProfilerPath,
Value: dotNetCoreClrProfilerPath,
Value: dotNetCoreClrProfilerGlibcPath,
},
{
Name: envDotNetStartupHook,
Expand Down