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 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
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

# 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:
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,14 @@ 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 Identifiers](https://learn.microsoft.com/en-us/dotnet/core/rid-catalog)(RIDs).
Currently, only two RIDs are supported: `linux-x64` and `linux-musl-x64`.
By default `linux-x64` is used.
```bash
instrumentation.opentelemetry.io/inject-dotnet: "true"
instrumentation.opentelemetry.io/otel-dotnet-auto-runtime: "linux-x64" # for Linux glibc based images, this is default value and can be omitted
instrumentation.opentelemetry.io/otel-dotnet-auto-runtime: "linux-musl-x64" # 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
22 changes: 20 additions & 2 deletions pkg/instrumentation/dotnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,20 @@ 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"
)

// Supported .NET runtime identifiers (https://learn.microsoft.com/en-us/dotnet/core/rid-catalog), can be set by instrumentation.opentelemetry.io/inject-dotnet.
const (
dotNetRuntimeLinuxGlibc = "linux-x64"
dotNetRuntimeLinuxMusl = "linux-musl-x64"
)

func injectDotNetSDK(dotNetSpec v1alpha1.DotNet, pod corev1.Pod, index int) (corev1.Pod, error) {

// caller checks if there is at least one container.
Expand All @@ -62,6 +69,17 @@ 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 := ""
switch runtime {
case "", dotNetRuntimeLinuxGlibc:
coreClrProfilerPath = dotNetCoreClrProfilerGlibcPath
case dotNetRuntimeLinuxMusl:
coreClrProfilerPath = dotNetCoreClrProfilerMuslPath
default:
return pod, fmt.Errorf("provided instrumentation.opentelemetry.io/dotnet-runtime annotation value '%s' is not supported", runtime)
}

// inject .NET instrumentation spec env vars.
for _, env := range dotNetSpec.Env {
idx := getIndexOfEnv(container.Env, env.Name)
Expand All @@ -79,7 +97,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-x64",
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: dotNetRuntimeLinuxGlibc,
},
},
},
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: dotNetRuntimeLinuxGlibc,
},
},
},
err: nil,
},
{
name: "runtime linux-musl-x64",
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: dotNetRuntimeLinuxMusl,
},
},
},
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: dotNetRuntimeLinuxMusl,
},
},
},
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 'not-supported' 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: dotNetRuntimeLinuxMusl,
},
},
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: dotNetRuntimeLinuxMusl,
},
},
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
name: sidecar
spec:
mode: sidecar
config: |
receivers:
otlp:
protocols:
grpc:
http:
processors:

exporters:
logging:

service:
pipelines:
traces:
receivers: [otlp]
processors: []
exporters: [logging]
---
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
# Annotate the namespace to allow the application to run using an specific group and user in OpenShift
# https://docs.openshift.com/dedicated/authentication/managing-security-context-constraints.html
# This annotation has no effect in Kubernetes
- command: kubectl annotate namespace ${NAMESPACE} openshift.io/sa.scc.uid-range=1000/1000 --overwrite
- command: kubectl annotate namespace ${NAMESPACE} openshift.io/sa.scc.supplemental-groups=2000/1000 --overwrite
Loading
Loading