Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Duncan-tree-zhou committed Jan 28, 2022
1 parent 29cbdb1 commit a8a4d80
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 46 deletions.
1 change: 1 addition & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 20 additions & 4 deletions bundle/manifests/opentelemetry.io_instrumentations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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 @@ -158,7 +162,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 @@ -276,7 +284,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 @@ -409,7 +421,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
201 changes: 175 additions & 26 deletions pkg/instrumentation/podmutator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,40 @@ func TestMutatePod(t *testing.T) {
Namespace: "javaagent",
},
Spec: v1alpha1.InstrumentationSpec{
Java: v1alpha1.Java{},
Java: v1alpha1.Java{
Env: []corev1.EnvVar{
{
Name: "OTEL_JAVAAGENT_DEBUG",
Value: "true",
},
{
Name: "OTEL_INSTRUMENTATION_JDBC_ENABLED",
Value: "false",
},
},
},
Env: []corev1.EnvVar{
{
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: v1alpha1.Exporter{
Endpoint: "http://collector:12345",
},
Expand Down Expand Up @@ -103,12 +136,40 @@ func TestMutatePod(t *testing.T) {
Name: "app",
Env: []corev1.EnvVar{
{
Name: "OTEL_SERVICE_NAME",
Value: "app",
Name: "OTEL_JAVAAGENT_DEBUG",
Value: "true",
},
{
Name: "OTEL_INSTRUMENTATION_JDBC_ENABLED",
Value: "false",
},
{
Name: "JAVA_TOOL_OPTIONS",
Value: javaJVMArgument,
},
{
Name: "OTEL_TRACES_EXPORTER",
Value: "otlp",
},
{
Name: "OTEL_EXPORTER_OTLP_ENDPOINT",
Value: "http://collector:12345",
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: "app",
},
{
Name: "OTEL_RESOURCE_ATTRIBUTES_POD_NAME",
Expand All @@ -130,10 +191,6 @@ func TestMutatePod(t *testing.T) {
Name: "OTEL_RESOURCE_ATTRIBUTES",
Value: "k8s.container.name=app,k8s.namespace.name=javaagent,k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)",
},
{
Name: "JAVA_TOOL_OPTIONS",
Value: javaJVMArgument,
},
},
VolumeMounts: []corev1.VolumeMount{
{
Expand Down Expand Up @@ -161,6 +218,34 @@ func TestMutatePod(t *testing.T) {
Spec: v1alpha1.InstrumentationSpec{
NodeJS: v1alpha1.NodeJS{
Image: "otel/nodejs:1",
Env: []corev1.EnvVar{
{
Name: "OTEL_NODEJS_DEBUG",
Value: "true",
},
},
},
Env: []corev1.EnvVar{
{
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: v1alpha1.Exporter{
Endpoint: "http://collector:12345",
Expand Down Expand Up @@ -212,12 +297,36 @@ func TestMutatePod(t *testing.T) {
Name: "app",
Env: []corev1.EnvVar{
{
Name: "OTEL_SERVICE_NAME",
Value: "app",
Name: "OTEL_NODEJS_DEBUG",
Value: "true",
},
{
Name: "NODE_OPTIONS",
Value: nodeRequireArgument,
},
{
Name: "OTEL_TRACES_EXPORTER",
Value: "otlp",
},
{
Name: "OTEL_EXPORTER_OTLP_ENDPOINT",
Value: "http://collector:12345",
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: "app",
},
{
Name: "OTEL_RESOURCE_ATTRIBUTES_POD_NAME",
Expand All @@ -239,10 +348,6 @@ func TestMutatePod(t *testing.T) {
Name: "OTEL_RESOURCE_ATTRIBUTES",
Value: "k8s.container.name=app,k8s.namespace.name=nodejs,k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)",
},
{
Name: "NODE_OPTIONS",
Value: nodeRequireArgument,
},
},
VolumeMounts: []corev1.VolumeMount{
{
Expand Down Expand Up @@ -270,10 +375,38 @@ func TestMutatePod(t *testing.T) {
Spec: v1alpha1.InstrumentationSpec{
Python: v1alpha1.Python{
Image: "otel/python:1",
Env: []corev1.EnvVar{
{
Name: "OTEL_LOG_LEVEL",
Value: "debug",
},
{
Name: "OTEL_TRACES_EXPORTER",
Value: "otlp_proto_http",
},
{
Name: "OTEL_EXPORTER_OTLP_ENDPOINT",
Value: "http://localhost:4317",
},
},
},
Exporter: v1alpha1.Exporter{
Endpoint: "http://collector:12345",
},
Env: []corev1.EnvVar{
{
Name: "OTEL_EXPORTER_OTLP_TIMEOUT",
Value: "20",
},
{
Name: "OTEL_TRACES_SAMPLER",
Value: "parentbased_traceidratio",
},
{
Name: "OTEL_TRACES_SAMPLER_ARG",
Value: "0.85",
},
},
},
},
pod: corev1.Pod{
Expand Down Expand Up @@ -321,12 +454,36 @@ func TestMutatePod(t *testing.T) {
Name: "app",
Env: []corev1.EnvVar{
{
Name: "OTEL_SERVICE_NAME",
Value: "app",
Name: "OTEL_LOG_LEVEL",
Value: "debug",
},
{
Name: "OTEL_TRACES_EXPORTER",
Value: "otlp_proto_http",
},
{
Name: "OTEL_EXPORTER_OTLP_ENDPOINT",
Value: "http://collector:12345",
Value: "http://localhost:4317",
},
{
Name: "PYTHONPATH",
Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix),
},
{
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: "app",
},
{
Name: "OTEL_RESOURCE_ATTRIBUTES_POD_NAME",
Expand All @@ -348,14 +505,6 @@ func TestMutatePod(t *testing.T) {
Name: "OTEL_RESOURCE_ATTRIBUTES",
Value: "k8s.container.name=app,k8s.namespace.name=python,k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)",
},
{
Name: "PYTHONPATH",
Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix),
},
{
Name: "OTEL_TRACES_EXPORTER",
Value: "otlp_proto_http",
},
},
VolumeMounts: []corev1.VolumeMount{
{
Expand Down
Loading

0 comments on commit a8a4d80

Please sign in to comment.