Skip to content

Commit

Permalink
support cross-namespace instrumentation reference
Browse files Browse the repository at this point in the history
  • Loading branch information
tKe committed May 24, 2022
1 parent 4ffcef4 commit 21db1d5
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/instrumentation/podmutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,15 @@ func (pm *instPodMutator) getInstrumentationInstance(ctx context.Context, ns cor
return pm.selectInstrumentationInstanceFromNamespace(ctx, ns)
}

var instNamespacedName types.NamespacedName
if instNamespace, instName, namespaced := strings.Cut(instValue, "/"); namespaced {
instNamespacedName = types.NamespacedName{Name: instName, Namespace: instNamespace}
} else {
instNamespacedName = types.NamespacedName{Name: instValue, Namespace: ns.Name}
}

otelInst := &v1alpha1.Instrumentation{}
err := pm.Client.Get(ctx, types.NamespacedName{Name: instValue, Namespace: ns.Name}, otelInst)
err := pm.Client.Get(ctx, instNamespacedName, otelInst)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
delete:
- apiVersion: v1
kind: Namespace
name: my-other-ns
23 changes: 23 additions & 0 deletions tests/e2e/instrumentation-java-other-ns/00-install-collector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
name: sidecar
spec:
mode: sidecar
config: |
receivers:
otlp:
protocols:
grpc:
http:
processors:
exporters:
logging:
service:
pipelines:
traces:
receivers: [otlp]
processors: []
exporters: [logging]
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: my-other-ns
---
apiVersion: opentelemetry.io/v1alpha1
kind: Instrumentation
metadata:
name: java
namespace: my-other-ns
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"
- 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"
48 changes: 48 additions & 0 deletions tests/e2e/instrumentation-java-other-ns/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: v1
kind: Pod
metadata:
annotations:
sidecar.opentelemetry.io/inject: "true"
instrumentation.opentelemetry.io/inject-java: "my-other-ns/java"
labels:
app: my-pod-with-sidecar
spec:
containers:
- name: myapp
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/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-deployment-with-sidecar
- name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME
- name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME
- name: OTEL_PROPAGATORS
value: jaeger,b3
- name: OTEL_RESOURCE_ATTRIBUTES
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
- mountPath: /otel-auto-instrumentation
name: opentelemetry-auto-instrumentation
- name: otc-container
initContainers:
- name: opentelemetry-auto-instrumentation
status:
phase: Running
24 changes: 24 additions & 0 deletions tests/e2e/instrumentation-java-other-ns/01-install-app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment-with-sidecar
spec:
selector:
matchLabels:
app: my-pod-with-sidecar
replicas: 1
template:
metadata:
labels:
app: my-pod-with-sidecar
annotations:
sidecar.opentelemetry.io/inject: "true"
instrumentation.opentelemetry.io/inject-java: "my-other-ns/java"
spec:
securityContext:
runAsUser: 1000
runAsGroup: 3000
fsGroup: 2000
containers:
- name: myapp
image: ghcr.io/pavolloffay/spring-petclinic:latest

0 comments on commit 21db1d5

Please sign in to comment.