From 4f0912138c9a1fc68bf5985c632c998534a02dd2 Mon Sep 17 00:00:00 2001 From: Duncan-tree-zhou Date: Wed, 26 Jan 2022 00:50:51 +0800 Subject: [PATCH] update e2e testcases --- apis/v1alpha1/instrumentation_types.go | 16 +++++++++---- apis/v1alpha1/instrumentation_webhook.go | 10 ++++---- .../opentelemetry.io_instrumentations.yaml | 24 +++++++++++++++---- docs/api.md | 8 +++---- .../00-install-instrumentation.yaml | 17 +++++++++++++ tests/e2e/instrumentation-java/01-assert.yaml | 24 ++++++++++++------- .../00-install-instrumentation.yaml | 19 +++++++++++++++ .../e2e/instrumentation-nodejs/01-assert.yaml | 18 ++++++++++---- .../00-install-instrumentation.yaml | 20 +++++++++++++++- .../e2e/instrumentation-python/01-assert.yaml | 20 +++++++++++----- 10 files changed, 139 insertions(+), 37 deletions(-) diff --git a/apis/v1alpha1/instrumentation_types.go b/apis/v1alpha1/instrumentation_types.go index 37e2592546..2b5af16ad8 100644 --- a/apis/v1alpha1/instrumentation_types.go +++ b/apis/v1alpha1/instrumentation_types.go @@ -37,7 +37,9 @@ type InstrumentationSpec struct { // +optional Sampler `json:"sampler,omitempty"` - // Env defines env vars. + // Env defines common env vars. There are four layers for env vars' definitions and + // the precedence order is: `original container env vars` > `language specific env vars` > `common env vars` > `instrument spec configs' vars` + // If the former var had been defined, then the other vars would be ignored. // +optional Env []corev1.EnvVar `json:"env,omitempty"` @@ -94,7 +96,9 @@ type Java struct { // +optional Image string `json:"image,omitempty"` - // Env defines env vars. + // Env defines java specific env vars. There are four layers for env vars' definitions and + // the precedence order is: `original container env vars` > `language specific env vars` > `common env vars` > `instrument spec configs' vars` + // If the former var had been defined, then the other vars would be ignored. // +optional Env []corev1.EnvVar `json:"env,omitempty"` } @@ -105,7 +109,9 @@ type NodeJS struct { // +optional Image string `json:"image,omitempty"` - // Env defines env vars. + // Env defines nodejs specific env vars. There are four layers for env vars' definitions and + // the precedence order is: `original container env vars` > `language specific env vars` > `common env vars` > `instrument spec configs' vars` + // If the former var had been defined, then the other vars would be ignored. // +optional Env []corev1.EnvVar `json:"env,omitempty"` } @@ -116,7 +122,9 @@ type Python struct { // +optional Image string `json:"image,omitempty"` - // Env defines env vars. + // Env defines python specific env vars. There are four layers for env vars' definitions and + // the precedence order is: `original container env vars` > `language specific env vars` > `common env vars` > `instrument spec configs' vars` + // If the former var had been defined, then the other vars would be ignored. // +optional Env []corev1.EnvVar `json:"env,omitempty"` } diff --git a/apis/v1alpha1/instrumentation_webhook.go b/apis/v1alpha1/instrumentation_webhook.go index 800e8d1781..1a977ee192 100644 --- a/apis/v1alpha1/instrumentation_webhook.go +++ b/apis/v1alpha1/instrumentation_webhook.go @@ -16,10 +16,10 @@ package v1alpha1 import ( "fmt" - corev1 "k8s.io/api/core/v1" "strconv" "strings" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" logf "sigs.k8s.io/controller-runtime/pkg/log" @@ -129,11 +129,9 @@ func (in *Instrumentation) validate() error { } func (in *Instrumentation) validateEnv(envs []corev1.EnvVar) error { - if len(envs) > 0 { - for _, env := range envs { - if !strings.HasPrefix(env.Name, envPrefix) { - return fmt.Errorf("env name should start with \"OTEL_\": %s", env.Name) - } + for _, env := range envs { + if !strings.HasPrefix(env.Name, envPrefix) { + return fmt.Errorf("env name should start with \"OTEL_\": %s", env.Name) } } return nil diff --git a/config/crd/bases/opentelemetry.io_instrumentations.yaml b/config/crd/bases/opentelemetry.io_instrumentations.yaml index 2a5789397e..0fcc3cc159 100644 --- a/config/crd/bases/opentelemetry.io_instrumentations.yaml +++ b/config/crd/bases/opentelemetry.io_instrumentations.yaml @@ -45,7 +45,11 @@ spec: SDK and instrumentation. properties: env: - description: Env defines env vars. + description: 'Env defines common env vars. There are four layers for + env vars'' definitions and precedence order is: `original container + env vars` > `language specific env vars` > `common env vars` > `instrument + spec configs'' vars` If the former var had been defined, then the + other vars would be ignored.' items: description: EnvVar represents an environment variable present in a Container. @@ -160,7 +164,11 @@ spec: description: Java defines configuration for java auto-instrumentation. properties: env: - description: Env defines env vars. + description: 'Env defines java specific env vars. There are four + layers for env vars'' definitions and precedence order is: `original + container env vars` > `language specific env vars` > `common + env vars` > `instrument spec configs'' vars` If the former var + had been defined, then the other vars would be ignored.' items: description: EnvVar represents an environment variable present in a Container. @@ -278,7 +286,11 @@ spec: description: NodeJS defines configuration for nodejs auto-instrumentation. properties: env: - description: Env defines env vars. + description: 'Env defines nodejs specific env vars. There are + four layers for env vars'' definitions and precedence order + is: `original container env vars` > `language specific env vars` + > `common env vars` > `instrument spec configs'' vars` If the + former var had been defined, then the other vars would be ignored.' items: description: EnvVar represents an environment variable present in a Container. @@ -411,7 +423,11 @@ spec: description: Python defines configuration for python auto-instrumentation. properties: env: - description: Env defines env vars. + description: 'Env defines python specific env vars. There are + four layers for env vars'' definitions and precedence order + is: `original container env vars` > `language specific env vars` + > `common env vars` > `instrument spec configs'' vars` If the + former var had been defined, then the other vars would be ignored.' items: description: EnvVar represents an environment variable present in a Container. diff --git a/docs/api.md b/docs/api.md index 9d35c0bce8..86ad531765 100644 --- a/docs/api.md +++ b/docs/api.md @@ -89,7 +89,7 @@ InstrumentationSpec defines the desired state of OpenTelemetry SDK and instrumen env []object - Env defines env vars.
+ Env defines common env vars. There are four layers for env vars' definitions and precedence order is: `original container env vars` > `language specific env vars` > `common env vars` > `instrument spec configs' vars` If the former var had been defined, then the other vars would be ignored.
false @@ -438,7 +438,7 @@ Java defines configuration for java auto-instrumentation. env []object - Env defines env vars.
+ Env defines java specific env vars. There are four layers for env vars' definitions and precedence order is: `original container env vars` > `language specific env vars` > `common env vars` > `instrument spec configs' vars` If the former var had been defined, then the other vars would be ignored.
false @@ -718,7 +718,7 @@ NodeJS defines configuration for nodejs auto-instrumentation. env []object - Env defines env vars.
+ Env defines nodejs specific env vars. There are four layers for env vars' definitions and precedence order is: `original container env vars` > `language specific env vars` > `common env vars` > `instrument spec configs' vars` If the former var had been defined, then the other vars would be ignored.
false @@ -998,7 +998,7 @@ Python defines configuration for python auto-instrumentation. env []object - Env defines env vars.
+ Env defines python specific env vars. There are four layers for env vars' definitions and precedence order is: `original container env vars` > `language specific env vars` > `common env vars` > `instrument spec configs' vars` If the former var had been defined, then the other vars would be ignored.
false diff --git a/tests/e2e/instrumentation-java/00-install-instrumentation.yaml b/tests/e2e/instrumentation-java/00-install-instrumentation.yaml index 6c1347b139..793f5a87f7 100644 --- a/tests/e2e/instrumentation-java/00-install-instrumentation.yaml +++ b/tests/e2e/instrumentation-java/00-install-instrumentation.yaml @@ -3,6 +3,17 @@ kind: Instrumentation metadata: name: java spec: + 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" exporter: endpoint: http://localhost:4317 propagators: @@ -11,3 +22,9 @@ spec: sampler: type: parentbased_traceidratio argument: "0.25" + java: + env: + - name: OTEL_JAVAAGENT_DEBUG + value: "true" + - name: OTEL_INSTRUMENTATION_JDBC_ENABLED + value: "false" diff --git a/tests/e2e/instrumentation-java/01-assert.yaml b/tests/e2e/instrumentation-java/01-assert.yaml index 63b4bd8330..cdc33dcc36 100644 --- a/tests/e2e/instrumentation-java/01-assert.yaml +++ b/tests/e2e/instrumentation-java/01-assert.yaml @@ -10,21 +10,29 @@ spec: containers: - name: myapp env: - - name: OTEL_SERVICE_NAME - value: my-deployment-with-sidecar + - name: OTEL_JAVAAGENT_DEBUG + value: "true" + - name: OTEL_INSTRUMENTATION_JDBC_ENABLED + value: "false" + - name: JAVA_TOOL_OPTIONS + value: " -javaagent:/otel-auto-instrumentation/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: OTEL_SERVICE_NAME + value: my-deployment-with-sidecar - name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME - name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME - name: OTEL_RESOURCE_ATTRIBUTES - name: OTEL_PROPAGATORS value: jaeger,b3 - - name: OTEL_TRACES_SAMPLER - value: parentbased_traceidratio - - name: OTEL_TRACES_SAMPLER_ARG - value: "0.25" - - name: JAVA_TOOL_OPTIONS - value: " -javaagent:/otel-auto-instrumentation/javaagent.jar" volumeMounts: - mountPath: /var/run/secrets/kubernetes.io/serviceaccount - mountPath: /otel-auto-instrumentation diff --git a/tests/e2e/instrumentation-nodejs/00-install-instrumentation.yaml b/tests/e2e/instrumentation-nodejs/00-install-instrumentation.yaml index 9ea4358b9b..40459f483a 100644 --- a/tests/e2e/instrumentation-nodejs/00-install-instrumentation.yaml +++ b/tests/e2e/instrumentation-nodejs/00-install-instrumentation.yaml @@ -3,8 +3,27 @@ kind: Instrumentation metadata: name: nodejs spec: + 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" exporter: endpoint: http://localhost:4317 propagators: - jaeger - b3 + sampler: + type: parentbased_traceidratio + argument: "0.25" + nodejs: + env: + - name: OTEL_NODEJS_DEBUG + value: "true" + diff --git a/tests/e2e/instrumentation-nodejs/01-assert.yaml b/tests/e2e/instrumentation-nodejs/01-assert.yaml index b796a5b8e5..d327e85962 100644 --- a/tests/e2e/instrumentation-nodejs/01-assert.yaml +++ b/tests/e2e/instrumentation-nodejs/01-assert.yaml @@ -10,17 +10,27 @@ spec: containers: - name: myapp env: - - name: OTEL_SERVICE_NAME - value: my-deployment-with-sidecar + - name: OTEL_NODEJS_DEBUG + value: "true" + - name: NODE_OPTIONS + value: " --require /otel-auto-instrumentation/autoinstrumentation.js" + - 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: OTEL_SERVICE_NAME + value: my-deployment-with-sidecar - name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME - name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME - name: OTEL_RESOURCE_ATTRIBUTES - name: OTEL_PROPAGATORS value: jaeger,b3 - - name: NODE_OPTIONS - value: " --require /otel-auto-instrumentation/autoinstrumentation.js" volumeMounts: - mountPath: /var/run/secrets/kubernetes.io/serviceaccount - mountPath: /otel-auto-instrumentation diff --git a/tests/e2e/instrumentation-python/00-install-instrumentation.yaml b/tests/e2e/instrumentation-python/00-install-instrumentation.yaml index d41827bf8f..fa1fff2353 100644 --- a/tests/e2e/instrumentation-python/00-install-instrumentation.yaml +++ b/tests/e2e/instrumentation-python/00-install-instrumentation.yaml @@ -3,8 +3,26 @@ kind: Instrumentation metadata: name: python spec: + env: + - name: OTEL_EXPORTER_OTLP_TIMEOUT + value: "20" + - name: OTEL_TRACES_SAMPLER + value: parentbased_traceidratio + - name: OTEL_TRACES_SAMPLER_ARG + value: "0.85" exporter: - endpoint: http://localhost:4318/v1/traces + endpoint: http://localhost:4317 propagators: - jaeger - b3 + sampler: + type: parentbased_traceidratio + argument: "0.25" + python: + env: + - name: OTEL_LOG_LEVEL + value: "debug" + - name: OTEL_TRACES_EXPORTER + value: otlp_proto_http + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://localhost:4317 \ No newline at end of file diff --git a/tests/e2e/instrumentation-python/01-assert.yaml b/tests/e2e/instrumentation-python/01-assert.yaml index 35ea2acb80..105cfd30cd 100644 --- a/tests/e2e/instrumentation-python/01-assert.yaml +++ b/tests/e2e/instrumentation-python/01-assert.yaml @@ -10,19 +10,27 @@ spec: containers: - name: myapp env: + - name: OTEL_LOG_LEVEL + value: "debug" + - name: OTEL_TRACES_EXPORTER + value: otlp_proto_http + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://localhost:4317 + - name: PYTHONPATH + value: "/otel-auto-instrumentation/opentelemetry/instrumentation/auto_instrumentation:/otel-auto-instrumentation" + - name: OTEL_EXPORTER_OTLP_TIMEOUT + value: "20" + - name: OTEL_TRACES_SAMPLER + value: parentbased_traceidratio + - name: OTEL_TRACES_SAMPLER_ARG + value: "0.85" - name: OTEL_SERVICE_NAME value: my-deployment-with-sidecar - - name: OTEL_EXPORTER_OTLP_ENDPOINT - value: http://localhost:4318/v1/traces - name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME - name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME - name: OTEL_RESOURCE_ATTRIBUTES - name: OTEL_PROPAGATORS value: jaeger,b3 - - name: PYTHONPATH - value: "/otel-auto-instrumentation/opentelemetry/instrumentation/auto_instrumentation:/otel-auto-instrumentation" - - name: OTEL_TRACES_EXPORTER - value: otlp_proto_http volumeMounts: - mountPath: /var/run/secrets/kubernetes.io/serviceaccount - mountPath: /otel-auto-instrumentation