From 2969467c89d1823451885fc9fda3dcfaf30143fc Mon Sep 17 00:00:00 2001 From: Mitali Salvi <44349099+mitali-salvi@users.noreply.github.com> Date: Wed, 8 May 2024 15:51:58 -0400 Subject: [PATCH 01/14] Add support for dotnet instrumentation (#168) --- Dockerfile | 3 +- Makefile | 3 +- main.go | 8 ++++- pkg/instrumentation/auto/config.go | 3 ++ pkg/instrumentation/auto/config_test.go | 9 +++++ pkg/instrumentation/defaultinstrumentation.go | 20 +++++++++++ .../defaultinstrumentation_test.go | 33 +++++++++++++++++++ pkg/instrumentation/podmutator_test.go | 18 ++++++++++ versions.txt | 2 ++ 9 files changed, 96 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 22c723c25..57e479d38 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,11 +26,12 @@ ARG VERSION_DATE ARG AGENT_VERSION ARG AUTO_INSTRUMENTATION_JAVA_VERSION ARG AUTO_INSTRUMENTATION_PYTHON_VERSION +ARG AUTO_INSTRUMENTATION_DOTNET_VERSION ARG DCMG_EXPORTER_VERSION ARG NEURON_MONITOR_VERSION # Build -RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -ldflags="-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.agent=${AGENT_VERSION} -X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${AUTO_INSTRUMENTATION_PYTHON_VERSION} -X ${VERSION_PKG}.dcgmExporter=${DCMG_EXPORTER_VERSION} -X ${VERSION_PKG}.neuronMonitor=${NEURON_MONITOR_VERSION}" -a -o manager main.go +RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -ldflags="-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.agent=${AGENT_VERSION} -X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${AUTO_INSTRUMENTATION_PYTHON_VERSION} -X ${VERSION_PKG}.autoInstrumentationDotNet=${AUTO_INSTRUMENTATION_DOTNET_VERSION} -X ${VERSION_PKG}.dcgmExporter=${DCMG_EXPORTER_VERSION} -X ${VERSION_PKG}.neuronMonitor=${NEURON_MONITOR_VERSION}" -a -o manager main.go # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details diff --git a/Makefile b/Makefile index 4d21b1154..f93b2d162 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ VERSION_PKG ?= "github.com/aws/amazon-cloudwatch-agent-operator/internal/version AGENT_VERSION ?= "$(shell grep -v '\#' versions.txt | grep cloudwatch-agent | awk -F= '{print $$2}')" AUTO_INSTRUMENTATION_JAVA_VERSION ?= "$(shell grep -v '\#' versions.txt | grep aws-otel-java-instrumentation | awk -F= '{print $$2}')" AUTO_INSTRUMENTATION_PYTHON_VERSION ?= "$(shell grep -v '\#' versions.txt | grep aws-otel-python-instrumentation | awk -F= '{print $$2}')" +AUTO_INSTRUMENTATION_DOTNET_VERSION ?= "$(shell grep -v '\#' versions.txt | grep aws-otel-dotnet-instrumentation | awk -F= '{print $$2}')" DCGM_EXPORTER_VERSION ?= "$(shell grep -v '\#' versions.txt | grep dcgm-exporter | awk -F= '{print $$2}')" NEURON_MONITOR_VERSION ?= "$(shell grep -v '\#' versions.txt | grep neuron-monitor | awk -F= '{print $$2}')" @@ -153,7 +154,7 @@ generate: controller-gen api-docs # buildx is used to ensure same results for arm based systems (m1/2 chips) .PHONY: container container: - docker buildx build --load --platform linux/${ARCH} -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg AGENT_VERSION=${AGENT_VERSION} --build-arg AUTO_INSTRUMENTATION_JAVA_VERSION=${AUTO_INSTRUMENTATION_JAVA_VERSION} --build-arg AUTO_INSTRUMENTATION_PYTHON_VERSION=${AUTO_INSTRUMENTATION_PYTHON_VERSION} --build-arg DCGM_EXPORTER_VERSION=${DCGM_EXPORTER_VERSION} --build-arg NEURON_MONITOR_VERSION=${NEURON_MONITOR_VERSION} . + docker buildx build --load --platform linux/${ARCH} -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg AGENT_VERSION=${AGENT_VERSION} --build-arg AUTO_INSTRUMENTATION_JAVA_VERSION=${AUTO_INSTRUMENTATION_JAVA_VERSION} --build-arg AUTO_INSTRUMENTATION_PYTHON_VERSION=${AUTO_INSTRUMENTATION_PYTHON_VERSION} --build-arg AUTO_INSTRUMENTATION_DOTNET_VERSION=${AUTO_INSTRUMENTATION_DOTNET_VERSION} --build-arg DCGM_EXPORTER_VERSION=${DCGM_EXPORTER_VERSION} --build-arg NEURON_MONITOR_VERSION=${NEURON_MONITOR_VERSION} . # Push the container image, used only for local dev purposes .PHONY: container-push diff --git a/main.go b/main.go index 34b1909ab..cf76f4372 100644 --- a/main.go +++ b/main.go @@ -48,6 +48,7 @@ const ( cloudwatchAgentImageRepository = "public.ecr.aws/cloudwatch-agent/cloudwatch-agent" autoInstrumentationJavaImageRepository = "public.ecr.aws/aws-observability/adot-autoinstrumentation-java" autoInstrumentationPythonImageRepository = "public.ecr.aws/aws-observability/adot-autoinstrumentation-python" + autoInstrumentationDotNetImageRepository = "ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-dotnet" dcgmExporterImageRepository = "nvcr.io/nvidia/k8s/dcgm-exporter" neuronMonitorImageRepository = "public.ecr.aws/neuron" ) @@ -98,6 +99,7 @@ func main() { agentImage string autoInstrumentationJava string autoInstrumentationPython string + autoInstrumentationDotNet string autoAnnotationConfigStr string webhookPort int tlsOpt tlsConfig @@ -111,14 +113,16 @@ func main() { stringFlagOrEnv(&agentImage, "agent-image", "RELATED_IMAGE_COLLECTOR", fmt.Sprintf("%s:%s", cloudwatchAgentImageRepository, v.AmazonCloudWatchAgent), "The default CloudWatch Agent image. This image is used when no image is specified in the CustomResource.") stringFlagOrEnv(&autoInstrumentationJava, "auto-instrumentation-java-image", "RELATED_IMAGE_AUTO_INSTRUMENTATION_JAVA", fmt.Sprintf("%s:%s", autoInstrumentationJavaImageRepository, v.AutoInstrumentationJava), "The default OpenTelemetry Java instrumentation image. This image is used when no image is specified in the CustomResource.") stringFlagOrEnv(&autoInstrumentationPython, "auto-instrumentation-python-image", "RELATED_IMAGE_AUTO_INSTRUMENTATION_PYTHON", fmt.Sprintf("%s:%s", autoInstrumentationPythonImageRepository, v.AutoInstrumentationPython), "The default OpenTelemetry Python instrumentation image. This image is used when no image is specified in the CustomResource.") + stringFlagOrEnv(&autoInstrumentationDotNet, "auto-instrumentation-dotnet-image", "RELATED_IMAGE_AUTO_INSTRUMENTATION_DOTNET", fmt.Sprintf("%s:%s", autoInstrumentationDotNetImageRepository, v.AutoInstrumentationDotNet), "The default OpenTelemetry Dotnet instrumentation image. This image is used when no image is specified in the CustomResource.") stringFlagOrEnv(&autoAnnotationConfigStr, "auto-annotation-config", "AUTO_ANNOTATION_CONFIG", "", "The configuration for auto-annotation.") stringFlagOrEnv(&dcgmExporterImage, "dcgm-exporter-image", "RELATED_IMAGE_DCGM_EXPORTER", fmt.Sprintf("%s:%s", dcgmExporterImageRepository, v.DcgmExporter), "The default DCGM Exporter image. This image is used when no image is specified in the CustomResource.") stringFlagOrEnv(&neuronMonitorImage, "neuron-monitor-image", "RELATED_IMAGE_NEURON_MONITOR", fmt.Sprintf("%s:%s", neuronMonitorImageRepository, v.NeuronMonitor), "The default Neuron monitor image. This image is used when no image is specified in the CustomResource.") pflag.Parse() - // set java instrumentation java image in environment variable to be used for default instrumentation + // set supported language instrumentation images in environment variable to be used for default instrumentation os.Setenv("AUTO_INSTRUMENTATION_JAVA", autoInstrumentationJava) os.Setenv("AUTO_INSTRUMENTATION_PYTHON", autoInstrumentationPython) + os.Setenv("AUTO_INSTRUMENTATION_DOTNET", autoInstrumentationDotNet) logger := zap.New(zap.UseFlagOptions(&opts)) ctrl.SetLogger(logger) @@ -128,6 +132,7 @@ func main() { "cloudwatch-agent", agentImage, "auto-instrumentation-java", autoInstrumentationJava, "auto-instrumentation-python", autoInstrumentationPython, + "auto-instrumentation-dotnet", autoInstrumentationDotNet, "dcgm-exporter", dcgmExporterImage, "neuron-monitor", neuronMonitorImage, "build-date", v.BuildDate, @@ -142,6 +147,7 @@ func main() { config.WithCollectorImage(agentImage), config.WithAutoInstrumentationJavaImage(autoInstrumentationJava), config.WithAutoInstrumentationPythonImage(autoInstrumentationPython), + config.WithAutoInstrumentationDotNetImage(autoInstrumentationDotNet), config.WithDcgmExporterImage(dcgmExporterImage), config.WithNeuronMonitorImage(neuronMonitorImage), ) diff --git a/pkg/instrumentation/auto/config.go b/pkg/instrumentation/auto/config.go index c6c4b46de..30ade1eef 100644 --- a/pkg/instrumentation/auto/config.go +++ b/pkg/instrumentation/auto/config.go @@ -10,6 +10,7 @@ import "github.com/aws/amazon-cloudwatch-agent-operator/pkg/instrumentation" type AnnotationConfig struct { Java AnnotationResources `json:"java"` Python AnnotationResources `json:"python"` + DotNet AnnotationResources `json:"dotnet"` } func (c AnnotationConfig) getResources(instType instrumentation.Type) AnnotationResources { @@ -18,6 +19,8 @@ func (c AnnotationConfig) getResources(instType instrumentation.Type) Annotation return c.Java case instrumentation.TypePython: return c.Python + case instrumentation.TypeDotNet: + return c.DotNet default: return AnnotationResources{} } diff --git a/pkg/instrumentation/auto/config_test.go b/pkg/instrumentation/auto/config_test.go index d6aa8187e..1300ad9dc 100644 --- a/pkg/instrumentation/auto/config_test.go +++ b/pkg/instrumentation/auto/config_test.go @@ -25,6 +25,12 @@ func TestConfig(t *testing.T) { DaemonSets: []string{"ds2"}, StatefulSets: []string{"ss2"}, }, + DotNet: AnnotationResources{ + Namespaces: []string{"n3"}, + Deployments: []string{"d3"}, + DaemonSets: []string{"ds3"}, + StatefulSets: []string{"ss3"}, + }, } assert.Equal(t, cfg.Java, cfg.getResources(instrumentation.TypeJava)) assert.Equal(t, []string{"n1"}, getNamespaces(cfg.Java)) @@ -32,5 +38,8 @@ func TestConfig(t *testing.T) { assert.Equal(t, cfg.Python, cfg.getResources(instrumentation.TypePython)) assert.Equal(t, []string{"ds2"}, getDaemonSets(cfg.Python)) assert.Equal(t, []string{"ss2"}, getStatefulSets(cfg.Python)) + assert.Equal(t, cfg.DotNet, cfg.getResources(instrumentation.TypeDotNet)) + assert.Equal(t, []string{"ds3"}, getDaemonSets(cfg.DotNet)) + assert.Equal(t, []string{"ss3"}, getStatefulSets(cfg.DotNet)) assert.Equal(t, AnnotationResources{}, cfg.getResources("invalidType")) } diff --git a/pkg/instrumentation/defaultinstrumentation.go b/pkg/instrumentation/defaultinstrumentation.go index fbdae8390..7d7ad4592 100644 --- a/pkg/instrumentation/defaultinstrumentation.go +++ b/pkg/instrumentation/defaultinstrumentation.go @@ -33,6 +33,10 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig) (*v1alpha1.Instr if !ok { return nil, errors.New("unable to determine python instrumentation image") } + dotNetInstrumentationImage, ok := os.LookupEnv("AUTO_INSTRUMENTATION_DOTNET") + if !ok { + return nil, errors.New("unable to determine dotnet instrumentation image") + } // set protocol by checking cloudwatch agent config for tls setting exporterPrefix := httpPrefix @@ -90,6 +94,22 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig) (*v1alpha1.Instr {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, }, + // temporary environment variables. Need to be updated with the latest values + DotNet: v1alpha1.DotNet{ + Image: dotNetInstrumentationImage, + Env: []corev1.EnvVar{ + {Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, + {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent.amazon-cloudwatch:2000"}, + {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, + {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, + {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: exporterPrefix + "cloudwatch-agent.amazon-cloudwatch:4316/v1/traces"}, + {Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: exporterPrefix + "cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, + {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, + {Name: "OTEL_DOTNET_DISTRO", Value: "aws_distro"}, + {Name: "OTEL_DOTNET_CONFIGURATOR", Value: "aws_configurator"}, + {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, + }, + }, }, }, nil } diff --git a/pkg/instrumentation/defaultinstrumentation_test.go b/pkg/instrumentation/defaultinstrumentation_test.go index b91affa9f..e766349bc 100644 --- a/pkg/instrumentation/defaultinstrumentation_test.go +++ b/pkg/instrumentation/defaultinstrumentation_test.go @@ -18,6 +18,7 @@ import ( func Test_getDefaultInstrumentation(t *testing.T) { os.Setenv("AUTO_INSTRUMENTATION_JAVA", defaultJavaInstrumentationImage) os.Setenv("AUTO_INSTRUMENTATION_PYTHON", defaultPythonInstrumentationImage) + os.Setenv("AUTO_INSTRUMENTATION_DOTNET", defaultDotNetInstrumentationImage) httpInst := &v1alpha1.Instrumentation{ Status: v1alpha1.InstrumentationStatus{}, @@ -66,6 +67,22 @@ func Test_getDefaultInstrumentation(t *testing.T) { {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, }, + // temporary environment variables. Need to be updated with the latest values + DotNet: v1alpha1.DotNet{ + Image: defaultDotNetInstrumentationImage, + Env: []corev1.EnvVar{ + {Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, + {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent.amazon-cloudwatch:2000"}, + {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, + {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, + {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/traces"}, + {Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, + {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, + {Name: "OTEL_DOTNET_DISTRO", Value: "aws_distro"}, + {Name: "OTEL_DOTNET_CONFIGURATOR", Value: "aws_configurator"}, + {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, + }, + }, }, } httpsInst := &v1alpha1.Instrumentation{ @@ -115,6 +132,22 @@ func Test_getDefaultInstrumentation(t *testing.T) { {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, }, + // temporary environment variables. Need to be updated with the latest values + DotNet: v1alpha1.DotNet{ + Image: defaultDotNetInstrumentationImage, + Env: []corev1.EnvVar{ + {Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, + {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent.amazon-cloudwatch:2000"}, + {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, + {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, + {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "https://cloudwatch-agent.amazon-cloudwatch:4316/v1/traces"}, + {Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: "https://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, + {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, + {Name: "OTEL_DOTNET_DISTRO", Value: "aws_distro"}, + {Name: "OTEL_DOTNET_CONFIGURATOR", Value: "aws_configurator"}, + {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, + }, + }, }, } diff --git a/pkg/instrumentation/podmutator_test.go b/pkg/instrumentation/podmutator_test.go index 617482461..05763ade5 100644 --- a/pkg/instrumentation/podmutator_test.go +++ b/pkg/instrumentation/podmutator_test.go @@ -25,11 +25,13 @@ import ( const ( defaultJavaInstrumentationImage = "test.registry/adot-autoinstrumentation-java:test-tag" defaultPythonInstrumentationImage = "test.registry/adot-autoinstrumentation-python:test-tag" + defaultDotNetInstrumentationImage = "test.registry/adot-autoinstrumentation-dotnet:test-tag" ) func TestGetInstrumentationInstanceFromNameSpaceDefault(t *testing.T) { os.Setenv("AUTO_INSTRUMENTATION_JAVA", defaultJavaInstrumentationImage) os.Setenv("AUTO_INSTRUMENTATION_PYTHON", defaultPythonInstrumentationImage) + os.Setenv("AUTO_INSTRUMENTATION_DOTNET", defaultDotNetInstrumentationImage) defaultInst := &v1alpha1.Instrumentation{ Status: v1alpha1.InstrumentationStatus{}, @@ -78,6 +80,22 @@ func TestGetInstrumentationInstanceFromNameSpaceDefault(t *testing.T) { {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, }, + // temporary environment variables. Need to be updated with the latest values + DotNet: v1alpha1.DotNet{ + Image: defaultDotNetInstrumentationImage, + Env: []corev1.EnvVar{ + {Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, + {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent.amazon-cloudwatch:2000"}, + {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, + {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, + {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/traces"}, + {Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, + {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, + {Name: "OTEL_DOTNET_DISTRO", Value: "aws_distro"}, + {Name: "OTEL_DOTNET_CONFIGURATOR", Value: "aws_configurator"}, + {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, + }, + }, }, } namespace := corev1.Namespace{ diff --git a/versions.txt b/versions.txt index eb65bd2b1..5ef92e63e 100644 --- a/versions.txt +++ b/versions.txt @@ -7,6 +7,8 @@ operator=1.3.1 # Represents the current release of ADOT language instrumentation. aws-otel-java-instrumentation=v1.32.1 aws-otel-python-instrumentation=v0.1.1 +# This needs to be updated with the latest release of ADOT SDK +aws-otel-dotnet-instrumentation=1.6.0 dcgm-exporter=3.3.3-3.3.1-ubuntu22.04 neuron-monitor=1.0.0 \ No newline at end of file From bc0157de92f5abf2bf5237ed0aa7d4f2465b3780 Mon Sep 17 00:00:00 2001 From: lisguo Date: Fri, 21 Jun 2024 11:18:27 -0400 Subject: [PATCH 02/14] Test --- main.go | 2 +- versions.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index cf76f4372..bde60515d 100644 --- a/main.go +++ b/main.go @@ -48,7 +48,7 @@ const ( cloudwatchAgentImageRepository = "public.ecr.aws/cloudwatch-agent/cloudwatch-agent" autoInstrumentationJavaImageRepository = "public.ecr.aws/aws-observability/adot-autoinstrumentation-java" autoInstrumentationPythonImageRepository = "public.ecr.aws/aws-observability/adot-autoinstrumentation-python" - autoInstrumentationDotNetImageRepository = "ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-dotnet" + autoInstrumentationDotNetImageRepository = "162283822697.dkr.ecr.us-west-1.amazonaws.com/dotnet/adot-dotnet-linux" dcgmExporterImageRepository = "nvcr.io/nvidia/k8s/dcgm-exporter" neuronMonitorImageRepository = "public.ecr.aws/neuron" ) diff --git a/versions.txt b/versions.txt index 89f400f1e..605cfa8b1 100644 --- a/versions.txt +++ b/versions.txt @@ -8,7 +8,7 @@ operator=1.4.1 aws-otel-java-instrumentation=v1.32.2 aws-otel-python-instrumentation=v0.2.0 # This needs to be updated with the latest release of ADOT SDK -aws-otel-dotnet-instrumentation=1.6.0 +aws-otel-dotnet-instrumentation=latest dcgm-exporter=3.3.3-3.3.1-ubuntu22.04 neuron-monitor=1.0.0 \ No newline at end of file From 191e50ff34e34c76039099bfc36fd0ad00160e27 Mon Sep 17 00:00:00 2001 From: lisguo Date: Fri, 21 Jun 2024 14:02:06 -0400 Subject: [PATCH 03/14] Check if the pod is on windows and append -windows to the instrumentation image --- main.go | 2 +- pkg/instrumentation/defaultinstrumentation.go | 18 +++++++++++++----- pkg/instrumentation/javaagent.go | 2 +- pkg/instrumentation/podmutator.go | 11 ++++++++--- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index bde60515d..387ad2d84 100644 --- a/main.go +++ b/main.go @@ -48,7 +48,7 @@ const ( cloudwatchAgentImageRepository = "public.ecr.aws/cloudwatch-agent/cloudwatch-agent" autoInstrumentationJavaImageRepository = "public.ecr.aws/aws-observability/adot-autoinstrumentation-java" autoInstrumentationPythonImageRepository = "public.ecr.aws/aws-observability/adot-autoinstrumentation-python" - autoInstrumentationDotNetImageRepository = "162283822697.dkr.ecr.us-west-1.amazonaws.com/dotnet/adot-dotnet-linux" + autoInstrumentationDotNetImageRepository = "162283822697.dkr.ecr.us-west-1.amazonaws.com/adot-autoinstrumentation-dotnet" dcgmExporterImageRepository = "nvcr.io/nvidia/k8s/dcgm-exporter" neuronMonitorImageRepository = "public.ecr.aws/neuron" ) diff --git a/pkg/instrumentation/defaultinstrumentation.go b/pkg/instrumentation/defaultinstrumentation.go index 7e8eb510d..6b67489c8 100644 --- a/pkg/instrumentation/defaultinstrumentation.go +++ b/pkg/instrumentation/defaultinstrumentation.go @@ -24,7 +24,7 @@ const ( httpsPrefix = "https://" ) -func getDefaultInstrumentation(agentConfig *adapters.CwaConfig) (*v1alpha1.Instrumentation, error) { +func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod bool) (*v1alpha1.Instrumentation, error) { javaInstrumentationImage, ok := os.LookupEnv("AUTO_INSTRUMENTATION_JAVA") if !ok { return nil, errors.New("unable to determine java instrumentation image") @@ -47,7 +47,7 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig) (*v1alpha1.Instr } } - return &v1alpha1.Instrumentation{ + instrumentation := &v1alpha1.Instrumentation{ Status: v1alpha1.InstrumentationStatus{}, TypeMeta: metav1.TypeMeta{ APIVersion: defaultAPIVersion, @@ -100,12 +100,12 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig) (*v1alpha1.Instr DotNet: v1alpha1.DotNet{ Image: dotNetInstrumentationImage, Env: []corev1.EnvVar{ - {Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, + {Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"}, {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent.amazon-cloudwatch:2000"}, {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: exporterPrefix + "cloudwatch-agent.amazon-cloudwatch:4316/v1/traces"}, - {Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: exporterPrefix + "cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, + {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: exporterPrefix + "cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, {Name: "OTEL_DOTNET_DISTRO", Value: "aws_distro"}, {Name: "OTEL_DOTNET_CONFIGURATOR", Value: "aws_configurator"}, @@ -113,5 +113,13 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig) (*v1alpha1.Instr }, }, }, - }, nil + } + + if isWindowsPod { + //instrumentation.Spec.Java.Image = instrumentation.Spec.Java.Image + "-windows" + //instrumentation.Spec.Python.Image = instrumentation.Spec.Python.Image + "-windows" + instrumentation.Spec.NodeJS.Image = instrumentation.Spec.NodeJS.Image + "-windows" + } + + return instrumentation, nil } diff --git a/pkg/instrumentation/javaagent.go b/pkg/instrumentation/javaagent.go index 6f1d2b4c5..391590976 100644 --- a/pkg/instrumentation/javaagent.go +++ b/pkg/instrumentation/javaagent.go @@ -66,7 +66,7 @@ func injectJavaagent(javaSpec v1alpha1.Java, pod corev1.Pod, index int) (corev1. }}) command := commandLinux - if pod.Spec.NodeSelector["kubernetes.io/os"] == "windows" { + if isWindowsPod(pod) { command = commandWindows } diff --git a/pkg/instrumentation/podmutator.go b/pkg/instrumentation/podmutator.go index 9e6a59f37..2e893a2f2 100644 --- a/pkg/instrumentation/podmutator.go +++ b/pkg/instrumentation/podmutator.go @@ -369,7 +369,7 @@ func (pm *instPodMutator) getInstrumentationInstance(ctx context.Context, ns cor } if strings.EqualFold(instValue, "true") { - return pm.selectInstrumentationInstanceFromNamespace(ctx, ns) + return pm.selectInstrumentationInstanceFromNamespace(ctx, ns, isWindowsPod(pod)) } var instNamespacedName types.NamespacedName @@ -388,7 +388,7 @@ func (pm *instPodMutator) getInstrumentationInstance(ctx context.Context, ns cor return otelInst, nil } -func (pm *instPodMutator) selectInstrumentationInstanceFromNamespace(ctx context.Context, ns corev1.Namespace) (*v1alpha1.Instrumentation, error) { +func (pm *instPodMutator) selectInstrumentationInstanceFromNamespace(ctx context.Context, ns corev1.Namespace, isWindowsPod bool) (*v1alpha1.Instrumentation, error) { var otelInsts v1alpha1.InstrumentationList if err := pm.Client.List(ctx, &otelInsts, client.InNamespace(ns.Name)); err != nil { return nil, err @@ -402,7 +402,8 @@ func (pm *instPodMutator) selectInstrumentationInstanceFromNamespace(ctx context if err != nil { pm.Logger.Error(err, "unable to retrieve cloudwatch agent config for instrumentation") } - return getDefaultInstrumentation(config) + + return getDefaultInstrumentation(config, isWindowsPod) case s > 1: return nil, errMultipleInstancesPossible default: @@ -420,3 +421,7 @@ func GetAmazonCloudWatchAgentResource(ctx context.Context, c client.Client, name return *cr } + +func isWindowsPod(pod corev1.Pod) bool { + return pod.Spec.NodeSelector["kubernetes.io/os"] == "windows" +} From 69c7e92994a206507d654c40a48b326c1befd79d Mon Sep 17 00:00:00 2001 From: lisguo Date: Fri, 21 Jun 2024 14:25:24 -0400 Subject: [PATCH 04/14] Refactor default instrumentation logic to use windows service --- pkg/instrumentation/defaultinstrumentation.go | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/pkg/instrumentation/defaultinstrumentation.go b/pkg/instrumentation/defaultinstrumentation.go index 6b67489c8..dce4f4448 100644 --- a/pkg/instrumentation/defaultinstrumentation.go +++ b/pkg/instrumentation/defaultinstrumentation.go @@ -5,6 +5,7 @@ package instrumentation import ( "errors" + "fmt" "os" corev1 "k8s.io/api/core/v1" @@ -20,8 +21,8 @@ const ( defaultNamespace = "default" defaultKind = "Instrumentation" - httpPrefix = "http://" - httpsPrefix = "https://" + http = "http" + https = "https" ) func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod bool) (*v1alpha1.Instrumentation, error) { @@ -37,17 +38,25 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo if !ok { return nil, errors.New("unable to determine dotnet instrumentation image") } + cloudwatchAgentServiceEndpoint := "cloudwatch-agent.amazon-cloudwatch" + + if isWindowsPod { + //javaInstrumentationImage = javaInstrumentationImage + "-windows" + //pythonInstrumentationImage = pythonInstrumentationImage + "-windows" + dotNetInstrumentationImage = dotNetInstrumentationImage + "-windows" + cloudwatchAgentServiceEndpoint = "cloudwatch-agent-windows.amazon-cloudwatch.svc.cluster.local" + } // set protocol by checking cloudwatch agent config for tls setting - exporterPrefix := httpPrefix + exporterPrefix := http if agentConfig != nil { appSignalsConfig := agentConfig.GetApplicationSignalsConfig() if appSignalsConfig != nil && appSignalsConfig.TLS != nil { - exporterPrefix = httpsPrefix + exporterPrefix = https } } - instrumentation := &v1alpha1.Instrumentation{ + return &v1alpha1.Instrumentation{ Status: v1alpha1.InstrumentationStatus{}, TypeMeta: metav1.TypeMeta{ APIVersion: defaultAPIVersion, @@ -69,12 +78,12 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo Env: []corev1.EnvVar{ {Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, //TODO: remove in favor of new name once safe {Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"}, - {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent.amazon-cloudwatch:2000"}, + {Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=http://%s:2000", cloudwatchAgentServiceEndpoint)}, {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, - {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: exporterPrefix + "cloudwatch-agent.amazon-cloudwatch:4316/v1/traces"}, - {Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: exporterPrefix + "cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, //TODO: remove in favor of new name once safe - {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: exporterPrefix + "cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, + {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/traces", exporterPrefix, cloudwatchAgentServiceEndpoint)}, + {Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/metrics", exporterPrefix, cloudwatchAgentServiceEndpoint)}, //TODO: remove in favor of new name once safe + {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/metrics", exporterPrefix, cloudwatchAgentServiceEndpoint)}, {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, @@ -84,12 +93,12 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo Env: []corev1.EnvVar{ {Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, //TODO: remove in favor of new name once safe {Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"}, - {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent.amazon-cloudwatch:2000"}, + {Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=http://%s:2000", cloudwatchAgentServiceEndpoint)}, {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, - {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: exporterPrefix + "cloudwatch-agent.amazon-cloudwatch:4316/v1/traces"}, - {Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: exporterPrefix + "cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, //TODO: remove in favor of new name once safe - {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: exporterPrefix + "cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, + {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/traces", exporterPrefix, cloudwatchAgentServiceEndpoint)}, + {Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/metrics", exporterPrefix, cloudwatchAgentServiceEndpoint)}, //TODO: remove in favor of new name once safe + {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/metrics", exporterPrefix, cloudwatchAgentServiceEndpoint)}, {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, {Name: "OTEL_PYTHON_DISTRO", Value: "aws_distro"}, {Name: "OTEL_PYTHON_CONFIGURATOR", Value: "aws_configurator"}, @@ -101,11 +110,11 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo Image: dotNetInstrumentationImage, Env: []corev1.EnvVar{ {Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"}, - {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent.amazon-cloudwatch:2000"}, + {Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=http://%s:2000", cloudwatchAgentServiceEndpoint)}, {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, - {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: exporterPrefix + "cloudwatch-agent.amazon-cloudwatch:4316/v1/traces"}, - {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: exporterPrefix + "cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, + {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/traces", exporterPrefix, cloudwatchAgentServiceEndpoint)}, + {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/metrics", exporterPrefix, cloudwatchAgentServiceEndpoint)}, {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, {Name: "OTEL_DOTNET_DISTRO", Value: "aws_distro"}, {Name: "OTEL_DOTNET_CONFIGURATOR", Value: "aws_configurator"}, @@ -113,13 +122,5 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo }, }, }, - } - - if isWindowsPod { - //instrumentation.Spec.Java.Image = instrumentation.Spec.Java.Image + "-windows" - //instrumentation.Spec.Python.Image = instrumentation.Spec.Python.Image + "-windows" - instrumentation.Spec.NodeJS.Image = instrumentation.Spec.NodeJS.Image + "-windows" - } - - return instrumentation, nil + }, nil } From 251843fcdeb75039e71da75a785d06d304007ba5 Mon Sep 17 00:00:00 2001 From: lisguo Date: Fri, 21 Jun 2024 14:56:17 -0400 Subject: [PATCH 05/14] Fix command for .net --- pkg/instrumentation/dotnet.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/instrumentation/dotnet.go b/pkg/instrumentation/dotnet.go index 73874611e..9fc6267d3 100644 --- a/pkg/instrumentation/dotnet.go +++ b/pkg/instrumentation/dotnet.go @@ -31,6 +31,7 @@ const ( dotnetVolumeName = volumeName + "-dotnet" dotnetInitContainerName = initContainerName + "-dotnet" dotnetInstrMountPath = "/otel-auto-instrumentation-dotnet" + dotnetInstrMountPathWindows = "\\otel-auto-instrumentation-dotnet" ) // Supported .NET runtime identifiers (https://learn.microsoft.com/en-us/dotnet/core/rid-catalog), can be set by instrumentation.opentelemetry.io/inject-dotnet. @@ -39,6 +40,11 @@ const ( dotNetRuntimeLinuxMusl = "linux-musl-x64" ) +var ( + commandLinux = []string{"cp", "-a", "/autoinstrumentation/.", dotnetInstrMountPath} + commandWindows = []string{"CMD", "/c", "xcopy", "/e", "autoinstrumentation\\*", dotnetInstrMountPathWindows} +) + func injectDotNetSDK(dotNetSpec v1alpha1.DotNet, pod corev1.Pod, index int, runtime string) (corev1.Pod, error) { // caller checks if there is at least one container. @@ -113,10 +119,15 @@ func injectDotNetSDK(dotNetSpec v1alpha1.DotNet, pod corev1.Pod, index int, runt }, }}) + command := commandLinux + if isWindowsPod(pod) { + command = commandWindows + } + pod.Spec.InitContainers = append(pod.Spec.InitContainers, corev1.Container{ Name: dotnetInitContainerName, Image: dotNetSpec.Image, - Command: []string{"cp", "-a", "/autoinstrumentation/.", dotnetInstrMountPath}, + Command: command, Resources: dotNetSpec.Resources, VolumeMounts: []corev1.VolumeMount{{ Name: dotnetVolumeName, From d8309d701d73a89d1d5657c76bcf0bbb3e17e213 Mon Sep 17 00:00:00 2001 From: lisguo Date: Fri, 21 Jun 2024 14:58:58 -0400 Subject: [PATCH 06/14] Fix variable name conflict --- pkg/instrumentation/dotnet.go | 8 ++++---- pkg/instrumentation/javaagent.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/instrumentation/dotnet.go b/pkg/instrumentation/dotnet.go index 9fc6267d3..040276af0 100644 --- a/pkg/instrumentation/dotnet.go +++ b/pkg/instrumentation/dotnet.go @@ -41,8 +41,8 @@ const ( ) var ( - commandLinux = []string{"cp", "-a", "/autoinstrumentation/.", dotnetInstrMountPath} - commandWindows = []string{"CMD", "/c", "xcopy", "/e", "autoinstrumentation\\*", dotnetInstrMountPathWindows} + dotNetCommandLinux = []string{"cp", "-a", "/autoinstrumentation/.", dotnetInstrMountPath} + dotNetCommandWindows = []string{"CMD", "/c", "xcopy", "/e", "autoinstrumentation\\*", dotnetInstrMountPathWindows} ) func injectDotNetSDK(dotNetSpec v1alpha1.DotNet, pod corev1.Pod, index int, runtime string) (corev1.Pod, error) { @@ -119,9 +119,9 @@ func injectDotNetSDK(dotNetSpec v1alpha1.DotNet, pod corev1.Pod, index int, runt }, }}) - command := commandLinux + command := dotNetCommandLinux if isWindowsPod(pod) { - command = commandWindows + command = dotNetCommandWindows } pod.Spec.InitContainers = append(pod.Spec.InitContainers, corev1.Container{ diff --git a/pkg/instrumentation/javaagent.go b/pkg/instrumentation/javaagent.go index 391590976..f7565fd88 100644 --- a/pkg/instrumentation/javaagent.go +++ b/pkg/instrumentation/javaagent.go @@ -19,8 +19,8 @@ const ( ) var ( - commandLinux = []string{"cp", "/javaagent.jar", javaInstrMountPath + "/javaagent.jar"} - commandWindows = []string{"CMD", "/c", "copy", "javaagent.jar", javaInstrMountPathWindows} + javaCommandLinux = []string{"cp", "/javaagent.jar", javaInstrMountPath + "/javaagent.jar"} + javaCommandWindows = []string{"CMD", "/c", "copy", "javaagent.jar", javaInstrMountPathWindows} ) func injectJavaagent(javaSpec v1alpha1.Java, pod corev1.Pod, index int) (corev1.Pod, error) { @@ -65,9 +65,9 @@ func injectJavaagent(javaSpec v1alpha1.Java, pod corev1.Pod, index int) (corev1. }, }}) - command := commandLinux + command := javaCommandLinux if isWindowsPod(pod) { - command = commandWindows + command = javaCommandWindows } pod.Spec.InitContainers = append(pod.Spec.InitContainers, corev1.Container{ From 8ed7a75aea25f9eea3f12e330ce97a8796a4aba1 Mon Sep 17 00:00:00 2001 From: lisguo Date: Fri, 21 Jun 2024 15:30:47 -0400 Subject: [PATCH 07/14] Change env variables for .NET on windows --- pkg/instrumentation/dotnet.go | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/pkg/instrumentation/dotnet.go b/pkg/instrumentation/dotnet.go index 040276af0..37c0626e9 100644 --- a/pkg/instrumentation/dotnet.go +++ b/pkg/instrumentation/dotnet.go @@ -31,7 +31,15 @@ const ( dotnetVolumeName = volumeName + "-dotnet" dotnetInitContainerName = initContainerName + "-dotnet" dotnetInstrMountPath = "/otel-auto-instrumentation-dotnet" - dotnetInstrMountPathWindows = "\\otel-auto-instrumentation-dotnet" +) + +const ( + dotNetCoreClrProfilerPathWindows = "C:\\otel-auto-instrumentation-dotnet\\win-x64\\OpenTelemetry.AutoInstrumentation.Native.dll" + dotNetAdditionalDepsPathWindows = "C:\\otel-auto-instrumentation-dotnet\\AdditionalDeps" + dotNetOTelAutoHomePathWindows = "C:\\otel-auto-instrumentation-dotnet" + dotNetSharedStorePathWindows = "C:\\otel-auto-instrumentation-dotnet\\store" + dotNetStartupHookPathWindows = "C:\\otel-auto-instrumentation-dotnet\\net\\OpenTelemetry.AutoInstrumentation.StartupHook.dll" + dotnetInstrMountPathWindows = "\\otel-auto-instrumentation-dotnet" ) // Supported .NET runtime identifiers (https://learn.microsoft.com/en-us/dotnet/core/rid-catalog), can be set by instrumentation.opentelemetry.io/inject-dotnet. @@ -91,18 +99,20 @@ func injectDotNetSDK(dotNetSpec v1alpha1.DotNet, pod corev1.Pod, index int, runt ) setDotNetEnvVar(container, envDotNetCoreClrEnableProfiling, dotNetCoreClrEnableProfilingEnabled, doNotConcatEnvValues) - setDotNetEnvVar(container, envDotNetCoreClrProfiler, dotNetCoreClrProfilerID, doNotConcatEnvValues) - - setDotNetEnvVar(container, envDotNetCoreClrProfilerPath, coreClrProfilerPath, doNotConcatEnvValues) - - setDotNetEnvVar(container, envDotNetStartupHook, dotNetStartupHookPath, concatEnvValues) - - setDotNetEnvVar(container, envDotNetAdditionalDeps, dotNetAdditionalDepsPath, concatEnvValues) - - setDotNetEnvVar(container, envDotNetOTelAutoHome, dotNetOTelAutoHomePath, doNotConcatEnvValues) - - setDotNetEnvVar(container, envDotNetSharedStore, dotNetSharedStorePath, concatEnvValues) + if isWindowsPod(pod) { + setDotNetEnvVar(container, envDotNetCoreClrProfilerPath, dotNetCoreClrProfilerPathWindows, doNotConcatEnvValues) + setDotNetEnvVar(container, envDotNetStartupHook, dotNetStartupHookPathWindows, concatEnvValues) + setDotNetEnvVar(container, envDotNetAdditionalDeps, dotNetAdditionalDepsPathWindows, concatEnvValues) + setDotNetEnvVar(container, envDotNetOTelAutoHome, dotNetOTelAutoHomePathWindows, doNotConcatEnvValues) + setDotNetEnvVar(container, envDotNetSharedStore, dotNetSharedStorePathWindows, concatEnvValues) + } else { + setDotNetEnvVar(container, envDotNetCoreClrProfilerPath, coreClrProfilerPath, doNotConcatEnvValues) + setDotNetEnvVar(container, envDotNetStartupHook, dotNetStartupHookPath, concatEnvValues) + setDotNetEnvVar(container, envDotNetAdditionalDeps, dotNetAdditionalDepsPath, concatEnvValues) + setDotNetEnvVar(container, envDotNetOTelAutoHome, dotNetOTelAutoHomePath, doNotConcatEnvValues) + setDotNetEnvVar(container, envDotNetSharedStore, dotNetSharedStorePath, concatEnvValues) + } container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{ Name: dotnetVolumeName, From 694a1af9d969dff594bdafb816d809fe2a11154d Mon Sep 17 00:00:00 2001 From: lisguo Date: Fri, 21 Jun 2024 16:10:36 -0400 Subject: [PATCH 08/14] Add OTEL_DOTNET_AUTO_PLUGINS env variable --- pkg/instrumentation/dotnet.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/instrumentation/dotnet.go b/pkg/instrumentation/dotnet.go index 37c0626e9..eb608bb22 100644 --- a/pkg/instrumentation/dotnet.go +++ b/pkg/instrumentation/dotnet.go @@ -20,6 +20,7 @@ const ( envDotNetSharedStore = "DOTNET_SHARED_STORE" envDotNetStartupHook = "DOTNET_STARTUP_HOOKS" envDotNetOTelAutoHome = "OTEL_DOTNET_AUTO_HOME" + envDotNetAutoPlugins = "OTEL_DOTNET_AUTO_PLUGINS" dotNetCoreClrEnableProfilingEnabled = "1" dotNetCoreClrProfilerID = "{918728DD-259F-4A6A-AC2B-B85E1B658318}" dotNetCoreClrProfilerGlibcPath = "/otel-auto-instrumentation-dotnet/linux-x64/OpenTelemetry.AutoInstrumentation.Native.so" @@ -28,6 +29,7 @@ const ( dotNetOTelAutoHomePath = "/otel-auto-instrumentation-dotnet" dotNetSharedStorePath = "/otel-auto-instrumentation-dotnet/store" dotNetStartupHookPath = "/otel-auto-instrumentation-dotnet/net/OpenTelemetry.AutoInstrumentation.StartupHook.dll" + dotNetAutoPlugins = "AWS.OpenTelemetry.AutoInstrumentation.Plugin, AWS.OpenTelemetry.AutoInstrumentation" dotnetVolumeName = volumeName + "-dotnet" dotnetInitContainerName = initContainerName + "-dotnet" dotnetInstrMountPath = "/otel-auto-instrumentation-dotnet" @@ -98,6 +100,7 @@ func injectDotNetSDK(dotNetSpec v1alpha1.DotNet, pod corev1.Pod, index int, runt concatEnvValues = true ) + setDotNetEnvVar(container, envDotNetAutoPlugins, dotNetAutoPlugins, doNotConcatEnvValues) setDotNetEnvVar(container, envDotNetCoreClrEnableProfiling, dotNetCoreClrEnableProfilingEnabled, doNotConcatEnvValues) setDotNetEnvVar(container, envDotNetCoreClrProfiler, dotNetCoreClrProfilerID, doNotConcatEnvValues) if isWindowsPod(pod) { From 0cf563a7bbad05ed29ed85bdafae6a55cd8f1500 Mon Sep 17 00:00:00 2001 From: lisguo Date: Wed, 26 Jun 2024 13:00:33 -0400 Subject: [PATCH 09/14] Use headless service for windows --- pkg/instrumentation/defaultinstrumentation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/instrumentation/defaultinstrumentation.go b/pkg/instrumentation/defaultinstrumentation.go index dce4f4448..46f137e7e 100644 --- a/pkg/instrumentation/defaultinstrumentation.go +++ b/pkg/instrumentation/defaultinstrumentation.go @@ -44,7 +44,7 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo //javaInstrumentationImage = javaInstrumentationImage + "-windows" //pythonInstrumentationImage = pythonInstrumentationImage + "-windows" dotNetInstrumentationImage = dotNetInstrumentationImage + "-windows" - cloudwatchAgentServiceEndpoint = "cloudwatch-agent-windows.amazon-cloudwatch.svc.cluster.local" + cloudwatchAgentServiceEndpoint = "cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local" } // set protocol by checking cloudwatch agent config for tls setting From 91cc6a717d81eb647a283c2491b06a85ba2f6f98 Mon Sep 17 00:00:00 2001 From: lisguo Date: Thu, 11 Jul 2024 15:00:47 -0400 Subject: [PATCH 10/14] Remove windows specific tags. Use v0.0.0 of adot .net image --- main.go | 2 +- pkg/instrumentation/defaultinstrumentation.go | 12 ++++-------- versions.txt | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 387ad2d84..1c3d2e215 100644 --- a/main.go +++ b/main.go @@ -48,7 +48,7 @@ const ( cloudwatchAgentImageRepository = "public.ecr.aws/cloudwatch-agent/cloudwatch-agent" autoInstrumentationJavaImageRepository = "public.ecr.aws/aws-observability/adot-autoinstrumentation-java" autoInstrumentationPythonImageRepository = "public.ecr.aws/aws-observability/adot-autoinstrumentation-python" - autoInstrumentationDotNetImageRepository = "162283822697.dkr.ecr.us-west-1.amazonaws.com/adot-autoinstrumentation-dotnet" + autoInstrumentationDotNetImageRepository = "public.ecr.aws/aws-observability/adot-autoinstrumentation-dotnet" dcgmExporterImageRepository = "nvcr.io/nvidia/k8s/dcgm-exporter" neuronMonitorImageRepository = "public.ecr.aws/neuron" ) diff --git a/pkg/instrumentation/defaultinstrumentation.go b/pkg/instrumentation/defaultinstrumentation.go index 46f137e7e..a9af8546c 100644 --- a/pkg/instrumentation/defaultinstrumentation.go +++ b/pkg/instrumentation/defaultinstrumentation.go @@ -38,12 +38,9 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo if !ok { return nil, errors.New("unable to determine dotnet instrumentation image") } - cloudwatchAgentServiceEndpoint := "cloudwatch-agent.amazon-cloudwatch" + cloudwatchAgentServiceEndpoint := "cloudwatch-agent.amazon-cloudwatch" if isWindowsPod { - //javaInstrumentationImage = javaInstrumentationImage + "-windows" - //pythonInstrumentationImage = pythonInstrumentationImage + "-windows" - dotNetInstrumentationImage = dotNetInstrumentationImage + "-windows" cloudwatchAgentServiceEndpoint = "cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local" } @@ -78,7 +75,7 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo Env: []corev1.EnvVar{ {Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, //TODO: remove in favor of new name once safe {Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"}, - {Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=http://%s:2000", cloudwatchAgentServiceEndpoint)}, + {Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=%s://%s:2000", exporterPrefix, cloudwatchAgentServiceEndpoint)}, {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/traces", exporterPrefix, cloudwatchAgentServiceEndpoint)}, @@ -93,7 +90,7 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo Env: []corev1.EnvVar{ {Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, //TODO: remove in favor of new name once safe {Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"}, - {Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=http://%s:2000", cloudwatchAgentServiceEndpoint)}, + {Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=%s://%s:2000", exporterPrefix, cloudwatchAgentServiceEndpoint)}, {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/traces", exporterPrefix, cloudwatchAgentServiceEndpoint)}, @@ -105,12 +102,11 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, }, - // temporary environment variables. Need to be updated with the latest values DotNet: v1alpha1.DotNet{ Image: dotNetInstrumentationImage, Env: []corev1.EnvVar{ {Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"}, - {Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=http://%s:2000", cloudwatchAgentServiceEndpoint)}, + {Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=%s://%s:2000", exporterPrefix, cloudwatchAgentServiceEndpoint)}, {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/traces", exporterPrefix, cloudwatchAgentServiceEndpoint)}, diff --git a/versions.txt b/versions.txt index 605cfa8b1..bc2a7b83b 100644 --- a/versions.txt +++ b/versions.txt @@ -8,7 +8,7 @@ operator=1.4.1 aws-otel-java-instrumentation=v1.32.2 aws-otel-python-instrumentation=v0.2.0 # This needs to be updated with the latest release of ADOT SDK -aws-otel-dotnet-instrumentation=latest +aws-otel-dotnet-instrumentation=v0.0.0 dcgm-exporter=3.3.3-3.3.1-ubuntu22.04 neuron-monitor=1.0.0 \ No newline at end of file From 9faca1f887f42bf5623acf44c1404fa5a247ab5a Mon Sep 17 00:00:00 2001 From: lisguo Date: Fri, 12 Jul 2024 13:13:17 -0400 Subject: [PATCH 11/14] Fix unit tests. Run linter --- pkg/instrumentation/defaultinstrumentation.go | 7 +- .../defaultinstrumentation_test.go | 188 ++++++++++++++++-- pkg/instrumentation/dotnet.go | 2 - pkg/instrumentation/podmutator_test.go | 74 +------ 4 files changed, 183 insertions(+), 88 deletions(-) diff --git a/pkg/instrumentation/defaultinstrumentation.go b/pkg/instrumentation/defaultinstrumentation.go index a9af8546c..f2015106d 100644 --- a/pkg/instrumentation/defaultinstrumentation.go +++ b/pkg/instrumentation/defaultinstrumentation.go @@ -75,7 +75,7 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo Env: []corev1.EnvVar{ {Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, //TODO: remove in favor of new name once safe {Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"}, - {Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=%s://%s:2000", exporterPrefix, cloudwatchAgentServiceEndpoint)}, + {Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=%s://%s:2000", http, cloudwatchAgentServiceEndpoint)}, {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/traces", exporterPrefix, cloudwatchAgentServiceEndpoint)}, @@ -90,7 +90,7 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo Env: []corev1.EnvVar{ {Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, //TODO: remove in favor of new name once safe {Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"}, - {Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=%s://%s:2000", exporterPrefix, cloudwatchAgentServiceEndpoint)}, + {Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=%s://%s:2000", http, cloudwatchAgentServiceEndpoint)}, {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/traces", exporterPrefix, cloudwatchAgentServiceEndpoint)}, @@ -106,7 +106,7 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo Image: dotNetInstrumentationImage, Env: []corev1.EnvVar{ {Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"}, - {Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=%s://%s:2000", exporterPrefix, cloudwatchAgentServiceEndpoint)}, + {Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=%s://%s:2000", http, cloudwatchAgentServiceEndpoint)}, {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/traces", exporterPrefix, cloudwatchAgentServiceEndpoint)}, @@ -115,6 +115,7 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_DOTNET_DISTRO", Value: "aws_distro"}, {Name: "OTEL_DOTNET_CONFIGURATOR", Value: "aws_configurator"}, {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, + {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.OpenTelemetry.AutoInstrumentation.Plugin, AWS.OpenTelemetry.AutoInstrumentation"}, }, }, }, diff --git a/pkg/instrumentation/defaultinstrumentation_test.go b/pkg/instrumentation/defaultinstrumentation_test.go index 68c6fccb9..f86df36fd 100644 --- a/pkg/instrumentation/defaultinstrumentation_test.go +++ b/pkg/instrumentation/defaultinstrumentation_test.go @@ -15,7 +15,7 @@ import ( "github.com/aws/amazon-cloudwatch-agent-operator/internal/manifests/collector/adapters" ) -func Test_getDefaultInstrumentation(t *testing.T) { +func Test_getDefaultInstrumentationLinux(t *testing.T) { os.Setenv("AUTO_INSTRUMENTATION_JAVA", defaultJavaInstrumentationImage) os.Setenv("AUTO_INSTRUMENTATION_PYTHON", defaultPythonInstrumentationImage) os.Setenv("AUTO_INSTRUMENTATION_DOTNET", defaultDotNetInstrumentationImage) @@ -69,20 +69,20 @@ func Test_getDefaultInstrumentation(t *testing.T) { {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, }, - // temporary environment variables. Need to be updated with the latest values DotNet: v1alpha1.DotNet{ Image: defaultDotNetInstrumentationImage, Env: []corev1.EnvVar{ - {Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, + {Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"}, {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent.amazon-cloudwatch:2000"}, {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/traces"}, - {Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, + {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, {Name: "OTEL_DOTNET_DISTRO", Value: "aws_distro"}, {Name: "OTEL_DOTNET_CONFIGURATOR", Value: "aws_configurator"}, {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, + {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.OpenTelemetry.AutoInstrumentation.Plugin, AWS.OpenTelemetry.AutoInstrumentation"}, }, }, }, @@ -136,20 +136,20 @@ func Test_getDefaultInstrumentation(t *testing.T) { {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, }, - // temporary environment variables. Need to be updated with the latest values DotNet: v1alpha1.DotNet{ Image: defaultDotNetInstrumentationImage, Env: []corev1.EnvVar{ - {Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, + {Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"}, {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent.amazon-cloudwatch:2000"}, {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "https://cloudwatch-agent.amazon-cloudwatch:4316/v1/traces"}, - {Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: "https://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, + {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "https://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, {Name: "OTEL_DOTNET_DISTRO", Value: "aws_distro"}, {Name: "OTEL_DOTNET_CONFIGURATOR", Value: "aws_configurator"}, {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, + {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.OpenTelemetry.AutoInstrumentation.Plugin, AWS.OpenTelemetry.AutoInstrumentation"}, }, }, }, @@ -165,12 +165,12 @@ func Test_getDefaultInstrumentation(t *testing.T) { wantErr bool }{ { - name: "appsignals-http", + name: "application-signals-http", args: args{ agentConfig: &adapters.CwaConfig{ Logs: &adapters.Logs{ LogMetricsCollected: &adapters.LogMetricsCollected{ - AppSignals: &adapters.AppSignals{}, + ApplicationSignals: &adapters.AppSignals{}, }, }, }, @@ -179,12 +179,12 @@ func Test_getDefaultInstrumentation(t *testing.T) { wantErr: false, }, { - name: "appsignals-https", + name: "application-signals-https", args: args{ agentConfig: &adapters.CwaConfig{ Logs: &adapters.Logs{ LogMetricsCollected: &adapters.LogMetricsCollected{ - AppSignals: &adapters.AppSignals{ + ApplicationSignals: &adapters.AppSignals{ TLS: &adapters.TLS{ CertFile: "some-cert", KeyFile: "some-key", @@ -197,6 +197,170 @@ func Test_getDefaultInstrumentation(t *testing.T) { want: httpsInst, wantErr: false, }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := getDefaultInstrumentation(tt.args.agentConfig, false) + if (err != nil) != tt.wantErr { + t.Errorf("getDefaultInstrumentation() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("getDefaultInstrumentation() got = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_getDefaultInstrumentationWindows(t *testing.T) { + os.Setenv("AUTO_INSTRUMENTATION_JAVA", defaultJavaInstrumentationImage) + os.Setenv("AUTO_INSTRUMENTATION_PYTHON", defaultPythonInstrumentationImage) + os.Setenv("AUTO_INSTRUMENTATION_DOTNET", defaultDotNetInstrumentationImage) + + httpInst := &v1alpha1.Instrumentation{ + Status: v1alpha1.InstrumentationStatus{}, + TypeMeta: metav1.TypeMeta{ + APIVersion: defaultAPIVersion, + Kind: defaultKind, + }, + ObjectMeta: metav1.ObjectMeta{ + Name: defaultInstrumenation, + Namespace: defaultNamespace, + }, + Spec: v1alpha1.InstrumentationSpec{ + Propagators: []v1alpha1.Propagator{ + v1alpha1.TraceContext, + v1alpha1.Baggage, + v1alpha1.B3, + v1alpha1.XRay, + }, + Java: v1alpha1.Java{ + Image: defaultJavaInstrumentationImage, + Env: []corev1.EnvVar{ + {Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, //TODO: remove in favor of new name once safe + {Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"}, + {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:2000"}, + {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, + {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, + {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/traces"}, + {Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/metrics"}, //TODO: remove in favor of new name once safe + {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/metrics"}, + {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, + {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, + }, + }, + Python: v1alpha1.Python{ + Image: defaultPythonInstrumentationImage, + Env: []corev1.EnvVar{ + {Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, //TODO: remove in favor of new name once safe + {Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"}, + {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:2000"}, + {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, + {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, + {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/traces"}, + {Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/metrics"}, //TODO: remove in favor of new name once safe + {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/metrics"}, + {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, + {Name: "OTEL_PYTHON_DISTRO", Value: "aws_distro"}, + {Name: "OTEL_PYTHON_CONFIGURATOR", Value: "aws_configurator"}, + {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, + }, + }, + DotNet: v1alpha1.DotNet{ + Image: defaultDotNetInstrumentationImage, + Env: []corev1.EnvVar{ + {Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"}, + {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:2000"}, + {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, + {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, + {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/traces"}, + {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/metrics"}, + {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, + {Name: "OTEL_DOTNET_DISTRO", Value: "aws_distro"}, + {Name: "OTEL_DOTNET_CONFIGURATOR", Value: "aws_configurator"}, + {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, + {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.OpenTelemetry.AutoInstrumentation.Plugin, AWS.OpenTelemetry.AutoInstrumentation"}, + }, + }, + }, + } + httpsInst := &v1alpha1.Instrumentation{ + Status: v1alpha1.InstrumentationStatus{}, + TypeMeta: metav1.TypeMeta{ + APIVersion: defaultAPIVersion, + Kind: defaultKind, + }, + ObjectMeta: metav1.ObjectMeta{ + Name: defaultInstrumenation, + Namespace: defaultNamespace, + }, + Spec: v1alpha1.InstrumentationSpec{ + Propagators: []v1alpha1.Propagator{ + v1alpha1.TraceContext, + v1alpha1.Baggage, + v1alpha1.B3, + v1alpha1.XRay, + }, + Java: v1alpha1.Java{ + Image: defaultJavaInstrumentationImage, + Env: []corev1.EnvVar{ + {Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, //TODO: remove in favor of new name once safe + {Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"}, + {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:2000"}, + {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, + {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, + {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "https://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/traces"}, + {Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: "https://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/metrics"}, //TODO: remove in favor of new name once safe + {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "https://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/metrics"}, + {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, + {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, + }, + }, + Python: v1alpha1.Python{ + Image: defaultPythonInstrumentationImage, + Env: []corev1.EnvVar{ + {Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, //TODO: remove in favor of new name once safe + {Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"}, + {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:2000"}, + {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, + {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, + {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "https://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/traces"}, + {Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: "https://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/metrics"}, //TODO: remove in favor of new name once safe + {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "https://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/metrics"}, + {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, + {Name: "OTEL_PYTHON_DISTRO", Value: "aws_distro"}, + {Name: "OTEL_PYTHON_CONFIGURATOR", Value: "aws_configurator"}, + {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, + }, + }, + DotNet: v1alpha1.DotNet{ + Image: defaultDotNetInstrumentationImage, + Env: []corev1.EnvVar{ + {Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"}, + {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:2000"}, + {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, + {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, + {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "https://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/traces"}, + {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "https://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/metrics"}, + {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, + {Name: "OTEL_DOTNET_DISTRO", Value: "aws_distro"}, + {Name: "OTEL_DOTNET_CONFIGURATOR", Value: "aws_configurator"}, + {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, + {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.OpenTelemetry.AutoInstrumentation.Plugin, AWS.OpenTelemetry.AutoInstrumentation"}, + }, + }, + }, + } + + type args struct { + agentConfig *adapters.CwaConfig + } + tests := []struct { + name string + args args + want *v1alpha1.Instrumentation + wantErr bool + }{ { name: "application-signals-http", args: args{ @@ -233,7 +397,7 @@ func Test_getDefaultInstrumentation(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := getDefaultInstrumentation(tt.args.agentConfig) + got, err := getDefaultInstrumentation(tt.args.agentConfig, true) if (err != nil) != tt.wantErr { t.Errorf("getDefaultInstrumentation() error = %v, wantErr %v", err, tt.wantErr) return diff --git a/pkg/instrumentation/dotnet.go b/pkg/instrumentation/dotnet.go index eb608bb22..a396310c3 100644 --- a/pkg/instrumentation/dotnet.go +++ b/pkg/instrumentation/dotnet.go @@ -20,7 +20,6 @@ const ( envDotNetSharedStore = "DOTNET_SHARED_STORE" envDotNetStartupHook = "DOTNET_STARTUP_HOOKS" envDotNetOTelAutoHome = "OTEL_DOTNET_AUTO_HOME" - envDotNetAutoPlugins = "OTEL_DOTNET_AUTO_PLUGINS" dotNetCoreClrEnableProfilingEnabled = "1" dotNetCoreClrProfilerID = "{918728DD-259F-4A6A-AC2B-B85E1B658318}" dotNetCoreClrProfilerGlibcPath = "/otel-auto-instrumentation-dotnet/linux-x64/OpenTelemetry.AutoInstrumentation.Native.so" @@ -100,7 +99,6 @@ func injectDotNetSDK(dotNetSpec v1alpha1.DotNet, pod corev1.Pod, index int, runt concatEnvValues = true ) - setDotNetEnvVar(container, envDotNetAutoPlugins, dotNetAutoPlugins, doNotConcatEnvValues) setDotNetEnvVar(container, envDotNetCoreClrEnableProfiling, dotNetCoreClrEnableProfilingEnabled, doNotConcatEnvValues) setDotNetEnvVar(container, envDotNetCoreClrProfiler, dotNetCoreClrProfilerID, doNotConcatEnvValues) if isWindowsPod(pod) { diff --git a/pkg/instrumentation/podmutator_test.go b/pkg/instrumentation/podmutator_test.go index 9f2633c87..f00c78540 100644 --- a/pkg/instrumentation/podmutator_test.go +++ b/pkg/instrumentation/podmutator_test.go @@ -19,6 +19,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/fake" "github.com/aws/amazon-cloudwatch-agent-operator/apis/v1alpha1" + "github.com/aws/amazon-cloudwatch-agent-operator/internal/manifests/collector/adapters" "github.com/aws/amazon-cloudwatch-agent-operator/pkg/featuregate" ) @@ -29,77 +30,8 @@ const ( ) func TestGetInstrumentationInstanceFromNameSpaceDefault(t *testing.T) { - os.Setenv("AUTO_INSTRUMENTATION_JAVA", defaultJavaInstrumentationImage) - os.Setenv("AUTO_INSTRUMENTATION_PYTHON", defaultPythonInstrumentationImage) - os.Setenv("AUTO_INSTRUMENTATION_DOTNET", defaultDotNetInstrumentationImage) + defaultInst, _ := getDefaultInstrumentation(&adapters.CwaConfig{}, false) - defaultInst := &v1alpha1.Instrumentation{ - Status: v1alpha1.InstrumentationStatus{}, - TypeMeta: metav1.TypeMeta{ - APIVersion: defaultAPIVersion, - Kind: defaultKind, - }, - ObjectMeta: metav1.ObjectMeta{ - Name: defaultInstrumenation, - Namespace: defaultNamespace, - }, - Spec: v1alpha1.InstrumentationSpec{ - Propagators: []v1alpha1.Propagator{ - v1alpha1.TraceContext, - v1alpha1.Baggage, - v1alpha1.B3, - v1alpha1.XRay, - }, - Java: v1alpha1.Java{ - Image: defaultJavaInstrumentationImage, - Env: []corev1.EnvVar{ - {Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, //TODO: remove in favor of new name once safe - {Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"}, - {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent.amazon-cloudwatch:2000"}, - {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, - {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, - {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/traces"}, - {Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, //TODO: remove in favor of new name once safe - {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, - {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, - {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, - }, - }, - Python: v1alpha1.Python{ - Image: defaultPythonInstrumentationImage, - Env: []corev1.EnvVar{ - {Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, //TODO: remove in favor of new name once safe - {Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"}, - {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent.amazon-cloudwatch:2000"}, - {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, - {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, - {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/traces"}, - {Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, //TODO: remove in favor of new name once safe - {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, - {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, - {Name: "OTEL_PYTHON_DISTRO", Value: "aws_distro"}, - {Name: "OTEL_PYTHON_CONFIGURATOR", Value: "aws_configurator"}, - {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, - }, - }, - // temporary environment variables. Need to be updated with the latest values - DotNet: v1alpha1.DotNet{ - Image: defaultDotNetInstrumentationImage, - Env: []corev1.EnvVar{ - {Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, - {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent.amazon-cloudwatch:2000"}, - {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, - {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, - {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/traces"}, - {Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, - {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, - {Name: "OTEL_DOTNET_DISTRO", Value: "aws_distro"}, - {Name: "OTEL_DOTNET_CONFIGURATOR", Value: "aws_configurator"}, - {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, - }, - }, - }, - } namespace := corev1.Namespace{ ObjectMeta: metav1.ObjectMeta{ Name: "default-namespace", @@ -113,7 +45,7 @@ func TestGetInstrumentationInstanceFromNameSpaceDefault(t *testing.T) { Client: fake.NewClientBuilder().Build(), Logger: logr.Logger{}, } - instrumentation, err := podMutator.selectInstrumentationInstanceFromNamespace(context.Background(), namespace) + instrumentation, err := podMutator.selectInstrumentationInstanceFromNamespace(context.Background(), namespace, false) assert.Nil(t, err) assert.Equal(t, defaultInst, instrumentation) From cdf5ae388a9fc91cae3762d24a1bfabad3a9968a Mon Sep 17 00:00:00 2001 From: lisguo Date: Fri, 12 Jul 2024 13:25:43 -0400 Subject: [PATCH 12/14] Add OTEL_EXPORTER_OTLP_ENDPOINT env variable for .NET --- pkg/instrumentation/defaultinstrumentation.go | 3 ++- pkg/instrumentation/defaultinstrumentation_test.go | 12 ++++++++---- pkg/instrumentation/dotnet.go | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/instrumentation/defaultinstrumentation.go b/pkg/instrumentation/defaultinstrumentation.go index f2015106d..4fa93e0a7 100644 --- a/pkg/instrumentation/defaultinstrumentation.go +++ b/pkg/instrumentation/defaultinstrumentation.go @@ -109,13 +109,14 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=%s://%s:2000", http, cloudwatchAgentServiceEndpoint)}, {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, + {Name: "OTEL_EXPORTER_OTLP_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316", exporterPrefix, cloudwatchAgentServiceEndpoint)}, {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/traces", exporterPrefix, cloudwatchAgentServiceEndpoint)}, {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/metrics", exporterPrefix, cloudwatchAgentServiceEndpoint)}, {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, {Name: "OTEL_DOTNET_DISTRO", Value: "aws_distro"}, {Name: "OTEL_DOTNET_CONFIGURATOR", Value: "aws_configurator"}, {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, - {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.OpenTelemetry.AutoInstrumentation.Plugin, AWS.OpenTelemetry.AutoInstrumentation"}, + {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation"}, }, }, }, diff --git a/pkg/instrumentation/defaultinstrumentation_test.go b/pkg/instrumentation/defaultinstrumentation_test.go index f86df36fd..c553f9fac 100644 --- a/pkg/instrumentation/defaultinstrumentation_test.go +++ b/pkg/instrumentation/defaultinstrumentation_test.go @@ -76,13 +76,14 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) { {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent.amazon-cloudwatch:2000"}, {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, + {Name: "OTEL_EXPORTER_OTLP_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316"}, {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/traces"}, {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, {Name: "OTEL_DOTNET_DISTRO", Value: "aws_distro"}, {Name: "OTEL_DOTNET_CONFIGURATOR", Value: "aws_configurator"}, {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, - {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.OpenTelemetry.AutoInstrumentation.Plugin, AWS.OpenTelemetry.AutoInstrumentation"}, + {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation"}, }, }, }, @@ -143,13 +144,14 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) { {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent.amazon-cloudwatch:2000"}, {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, + {Name: "OTEL_EXPORTER_OTLP_ENDPOINT", Value: "https://cloudwatch-agent.amazon-cloudwatch:4316"}, {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "https://cloudwatch-agent.amazon-cloudwatch:4316/v1/traces"}, {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "https://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, {Name: "OTEL_DOTNET_DISTRO", Value: "aws_distro"}, {Name: "OTEL_DOTNET_CONFIGURATOR", Value: "aws_configurator"}, {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, - {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.OpenTelemetry.AutoInstrumentation.Plugin, AWS.OpenTelemetry.AutoInstrumentation"}, + {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation"}, }, }, }, @@ -273,13 +275,14 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) { {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:2000"}, {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, + {Name: "OTEL_EXPORTER_OTLP_ENDPOINT", Value: "http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316"}, {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/traces"}, {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/metrics"}, {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, {Name: "OTEL_DOTNET_DISTRO", Value: "aws_distro"}, {Name: "OTEL_DOTNET_CONFIGURATOR", Value: "aws_configurator"}, {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, - {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.OpenTelemetry.AutoInstrumentation.Plugin, AWS.OpenTelemetry.AutoInstrumentation"}, + {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation"}, }, }, }, @@ -340,13 +343,14 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) { {Name: "OTEL_TRACES_SAMPLER_ARG", Value: "endpoint=http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:2000"}, {Name: "OTEL_TRACES_SAMPLER", Value: "xray"}, {Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"}, + {Name: "OTEL_EXPORTER_OTLP_ENDPOINT", Value: "https://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316"}, {Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "https://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/traces"}, {Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "https://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/metrics"}, {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, {Name: "OTEL_DOTNET_DISTRO", Value: "aws_distro"}, {Name: "OTEL_DOTNET_CONFIGURATOR", Value: "aws_configurator"}, {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, - {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.OpenTelemetry.AutoInstrumentation.Plugin, AWS.OpenTelemetry.AutoInstrumentation"}, + {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation"}, }, }, }, diff --git a/pkg/instrumentation/dotnet.go b/pkg/instrumentation/dotnet.go index a396310c3..6f5f4aadc 100644 --- a/pkg/instrumentation/dotnet.go +++ b/pkg/instrumentation/dotnet.go @@ -28,7 +28,7 @@ const ( dotNetOTelAutoHomePath = "/otel-auto-instrumentation-dotnet" dotNetSharedStorePath = "/otel-auto-instrumentation-dotnet/store" dotNetStartupHookPath = "/otel-auto-instrumentation-dotnet/net/OpenTelemetry.AutoInstrumentation.StartupHook.dll" - dotNetAutoPlugins = "AWS.OpenTelemetry.AutoInstrumentation.Plugin, AWS.OpenTelemetry.AutoInstrumentation" + dotNetAutoPlugins = "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation" dotnetVolumeName = volumeName + "-dotnet" dotnetInitContainerName = initContainerName + "-dotnet" dotnetInstrMountPath = "/otel-auto-instrumentation-dotnet" From c934633d5f7d2da9354fb2390badb7e42fa9cc6a Mon Sep 17 00:00:00 2001 From: lisguo Date: Tue, 16 Jul 2024 10:41:52 -0400 Subject: [PATCH 13/14] Add DotNet to annotation mutator --- main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/main.go b/main.go index 1c3d2e215..4ec1d6a76 100644 --- a/main.go +++ b/main.go @@ -244,6 +244,7 @@ func main() { instrumentation.NewTypeSet( instrumentation.TypeJava, instrumentation.TypePython, + instrumentation.TypeDotNet, ), ) mgr.GetWebhookServer().Register("/mutate-v1-workload", &webhook.Admission{ From 92bc7faf9662e1d5afb0ae301bff8d283121e0ac Mon Sep 17 00:00:00 2001 From: lisguo Date: Tue, 16 Jul 2024 12:16:29 -0400 Subject: [PATCH 14/14] Add comment on windows headless service endpoint. Update README with language support --- README.md | 5 +++++ pkg/instrumentation/defaultinstrumentation.go | 2 ++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index af1294f97..c7b30c028 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ # Amazon CloudWatch Agent Operator The Amazon CloudWatch Agent Operator is software developed to manage the [CloudWatch Agent](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Install-CloudWatch-Agent.html) on kubernetes. +Supported Languages: +- Java +- Python +- .NET + This repo is based off of the [OpenTelemetry Operator](https://github.com/open-telemetry/opentelemetry-operator) ## Build and Deployment diff --git a/pkg/instrumentation/defaultinstrumentation.go b/pkg/instrumentation/defaultinstrumentation.go index 4fa93e0a7..b0f446c1d 100644 --- a/pkg/instrumentation/defaultinstrumentation.go +++ b/pkg/instrumentation/defaultinstrumentation.go @@ -41,6 +41,8 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo cloudwatchAgentServiceEndpoint := "cloudwatch-agent.amazon-cloudwatch" if isWindowsPod { + // Windows pods use the headless service endpoint due to limitations with the agent on host network mode + // https://kubernetes.io/docs/concepts/services-networking/windows-networking/#limitations cloudwatchAgentServiceEndpoint = "cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local" }