Skip to content

Commit

Permalink
update e2e testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
Duncan-tree-zhou committed Jan 26, 2022
1 parent dadd4da commit 29cbdb1
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 37 deletions.
16 changes: 12 additions & 4 deletions apis/v1alpha1/instrumentation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down Expand Up @@ -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"`
}
Expand All @@ -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"`
}
Expand All @@ -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"`
}
Expand Down
10 changes: 4 additions & 6 deletions apis/v1alpha1/instrumentation_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
24 changes: 20 additions & 4 deletions config/crd/bases/opentelemetry.io_instrumentations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 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.'
items:
description: EnvVar represents an environment variable present in
a Container.
Expand Down Expand Up @@ -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 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.'
items:
description: EnvVar represents an environment variable present
in a Container.
Expand Down Expand Up @@ -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 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.'
items:
description: EnvVar represents an environment variable present
in a Container.
Expand Down Expand Up @@ -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 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.'
items:
description: EnvVar represents an environment variable present
in a Container.
Expand Down
8 changes: 4 additions & 4 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ InstrumentationSpec defines the desired state of OpenTelemetry SDK and instrumen
<td><b><a href="#instrumentationspecenvindex">env</a></b></td>
<td>[]object</td>
<td>
Env defines env vars.<br/>
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.<br/>
</td>
<td>false</td>
</tr><tr>
Expand Down Expand Up @@ -438,7 +438,7 @@ Java defines configuration for java auto-instrumentation.
<td><b><a href="#instrumentationspecjavaenvindex">env</a></b></td>
<td>[]object</td>
<td>
Env defines env vars.<br/>
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.<br/>
</td>
<td>false</td>
</tr><tr>
Expand Down Expand Up @@ -718,7 +718,7 @@ NodeJS defines configuration for nodejs auto-instrumentation.
<td><b><a href="#instrumentationspecnodejsenvindex">env</a></b></td>
<td>[]object</td>
<td>
Env defines env vars.<br/>
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.<br/>
</td>
<td>false</td>
</tr><tr>
Expand Down Expand Up @@ -998,7 +998,7 @@ Python defines configuration for python auto-instrumentation.
<td><b><a href="#instrumentationspecpythonenvindex">env</a></b></td>
<td>[]object</td>
<td>
Env defines env vars.<br/>
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.<br/>
</td>
<td>false</td>
</tr><tr>
Expand Down
17 changes: 17 additions & 0 deletions tests/e2e/instrumentation-java/00-install-instrumentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
24 changes: 16 additions & 8 deletions tests/e2e/instrumentation-java/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tests/e2e/instrumentation-nodejs/00-install-instrumentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

18 changes: 14 additions & 4 deletions tests/e2e/instrumentation-nodejs/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion tests/e2e/instrumentation-python/00-install-instrumentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 14 additions & 6 deletions tests/e2e/instrumentation-python/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 29cbdb1

Please sign in to comment.