From 60540f03a6d458afdc34b17b39e35c27a32d1e7a Mon Sep 17 00:00:00 2001 From: crossoverJie Date: Tue, 2 Apr 2024 23:59:14 +0800 Subject: [PATCH] fix wrong Inst when having multi Inst --- pkg/instrumentation/podmutator.go | 2 +- .../00-install-instrumentation-select.yaml | 38 ++++++++++ .../01-assert-select-multi.yaml | 69 +++++++++++++++++++ .../01-install-app-select.yaml | 29 ++++++++ 4 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 tests/e2e-instrumentation/instrumentation-select/01-assert-select-multi.yaml diff --git a/pkg/instrumentation/podmutator.go b/pkg/instrumentation/podmutator.go index bb1557b71c..e3c3b1d673 100644 --- a/pkg/instrumentation/podmutator.go +++ b/pkg/instrumentation/podmutator.go @@ -428,6 +428,6 @@ func (pm *instPodMutator) selectInstrumentationInstanceFromNamespace(ctx context case s > 1: return nil, errMultipleInstancesPossible default: - return &otelInsts.Items[0], nil + return &availableInstrument[0], nil } } diff --git a/tests/e2e-instrumentation/instrumentation-select/00-install-instrumentation-select.yaml b/tests/e2e-instrumentation/instrumentation-select/00-install-instrumentation-select.yaml index 84b213ab8a..74f5aa10f3 100644 --- a/tests/e2e-instrumentation/instrumentation-select/00-install-instrumentation-select.yaml +++ b/tests/e2e-instrumentation/instrumentation-select/00-install-instrumentation-select.yaml @@ -35,3 +35,41 @@ spec: value: "false" - name: SPLUNK_PROFILER_ENABLED value: "false" +--- +apiVersion: opentelemetry.io/v1alpha1 +kind: Instrumentation +metadata: + name: my-java-multi +spec: + selector: + matchLabels: + app: my-java-multi + env: + - name: OTEL_TRACES_EXPORTER + value: otlp + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://localhost:4317 + - name: OTEL_EXPORTER_OTLP_TIMEOUT + value: "20" + - name: OTEL_TRACES_SAMPLER + value: parentbased_traceidratio + - name: OTEL_TRACES_SAMPLER_ARG + value: "0.85" + - name: SPLUNK_TRACE_RESPONSE_HEADER_ENABLED + value: "true" + exporter: + endpoint: http://localhost:4317 + propagators: + - jaeger + - b3 + sampler: + type: parentbased_traceidratio + argument: "0.25" + java: + env: + - name: OTEL_JAVAAGENT_DEBUG + value: "true" + - name: OTEL_INSTRUMENTATION_JDBC_ENABLED + value: "false" + - name: SPLUNK_PROFILER_ENABLED + value: "false" diff --git a/tests/e2e-instrumentation/instrumentation-select/01-assert-select-multi.yaml b/tests/e2e-instrumentation/instrumentation-select/01-assert-select-multi.yaml new file mode 100644 index 0000000000..f8ce8b1ae5 --- /dev/null +++ b/tests/e2e-instrumentation/instrumentation-select/01-assert-select-multi.yaml @@ -0,0 +1,69 @@ +apiVersion: v1 +kind: Pod +metadata: + annotations: + instrumentation.opentelemetry.io/inject-java: "true" + sidecar.opentelemetry.io/inject: "true" + labels: + app: my-java-multi +spec: + containers: + - env: + - name: OTEL_JAVAAGENT_DEBUG + value: "true" + - name: OTEL_INSTRUMENTATION_JDBC_ENABLED + value: "false" + - name: SPLUNK_PROFILER_ENABLED + value: "false" + - name: JAVA_TOOL_OPTIONS + value: ' -javaagent:/otel-auto-instrumentation-java/javaagent.jar' + - name: OTEL_TRACES_EXPORTER + value: otlp + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://localhost:4317 + - name: OTEL_EXPORTER_OTLP_TIMEOUT + value: "20" + - name: OTEL_TRACES_SAMPLER + value: parentbased_traceidratio + - name: OTEL_TRACES_SAMPLER_ARG + value: "0.85" + - name: SPLUNK_TRACE_RESPONSE_HEADER_ENABLED + value: "true" + - name: OTEL_SERVICE_NAME + value: my-java-multi + - name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: spec.nodeName + - name: OTEL_PROPAGATORS + value: jaeger,b3 + - name: OTEL_RESOURCE_ATTRIBUTES + name: myapp + volumeMounts: + - mountPath: /var/run/secrets/kubernetes.io/serviceaccount + readOnly: true + - mountPath: /otel-auto-instrumentation-java + name: opentelemetry-auto-instrumentation-java + - args: + - --config=env:OTEL_CONFIG + name: otc-container + initContainers: + - name: opentelemetry-auto-instrumentation-java +status: + containerStatuses: + - name: myapp + ready: true + started: true + - name: otc-container + ready: true + started: true + initContainerStatuses: + - name: opentelemetry-auto-instrumentation-java + ready: true + phase: Running diff --git a/tests/e2e-instrumentation/instrumentation-select/01-install-app-select.yaml b/tests/e2e-instrumentation/instrumentation-select/01-install-app-select.yaml index 31f1667641..145bd6bed8 100644 --- a/tests/e2e-instrumentation/instrumentation-select/01-install-app-select.yaml +++ b/tests/e2e-instrumentation/instrumentation-select/01-install-app-select.yaml @@ -55,3 +55,32 @@ spec: allowPrivilegeEscalation: false capabilities: drop: ["ALL"] +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-java-multi +spec: + selector: + matchLabels: + app: my-java-multi + replicas: 1 + template: + metadata: + labels: + app: my-java-multi + annotations: + sidecar.opentelemetry.io/inject: "true" + instrumentation.opentelemetry.io/inject-java: "true" + spec: + securityContext: + runAsUser: 1000 + runAsGroup: 3000 + fsGroup: 3000 + containers: + - name: myapp + image: ghcr.io/open-telemetry/opentelemetry-operator/e2e-test-app-java:main + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: ["ALL"]