Skip to content

Commit

Permalink
Test multi-container multi-instrumentation for ApacheHTTPD, Golang, S…
Browse files Browse the repository at this point in the history
…DK (#3316)
  • Loading branch information
IshwarKanse authored Oct 3, 2024
1 parent 05c901f commit 91759b0
Show file tree
Hide file tree
Showing 14 changed files with 735 additions and 240 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
name: sidecar
spec:
mode: sidecar
config: |
receivers:
otlp:
protocols:
grpc:
http:
processors:
exporters:
debug:
service:
pipelines:
traces:
receivers: [otlp]
exporters: [debug]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: opentelemetry.io/v1alpha1
kind: Instrumentation
metadata:
name: go
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"
python:
env:
- name: OTEL_SERVICE_NAME
value: "pythonapp"
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: http://localhost:4318
go:
env:
- name: OTEL_SERVICE_NAME
value: "goapp"

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: otel-instrumentation-go
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
apiVersion: v1
kind: Pod
metadata:
annotations:
instrumentation.opentelemetry.io/go-container-names: goapp
instrumentation.opentelemetry.io/inject-go: "true"
instrumentation.opentelemetry.io/inject-python: "true"
instrumentation.opentelemetry.io/otel-go-auto-target-exe: /usr/src/app/productcatalogservice
instrumentation.opentelemetry.io/python-container-names: pythonapp
labels:
app: my-golang-multiinst
spec:
containers:
- name: goapp
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
readOnly: true
- command:
- flask
- run
- -p
- "8087"
env:
- name: OTEL_NODE_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.hostIP
- name: OTEL_POD_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
- name: OTEL_SERVICE_NAME
value: pythonapp
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: http://localhost:4318
- name: PYTHONPATH
value: /otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation:/otel-auto-instrumentation-python
- name: OTEL_EXPORTER_OTLP_PROTOCOL
value: http/protobuf
- name: OTEL_TRACES_EXPORTER
value: otlp
- name: OTEL_METRICS_EXPORTER
value: otlp
- 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_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: pythonapp
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
readOnly: true
- mountPath: /otel-auto-instrumentation-python
name: opentelemetry-auto-instrumentation-python
- args:
- --feature-gates=-component.UseLocalHostAsDefaultHost
- --config=env:OTEL_CONFIG
env:
- name: POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: OTEL_CONFIG
value: |
receivers:
otlp:
protocols:
grpc: null
http: null
exporters:
debug: null
service:
pipelines:
traces:
exporters:
- debug
receivers:
- otlp
- name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: OTEL_RESOURCE_ATTRIBUTES_POD_UID
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.uid
- name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
- name: OTEL_RESOURCE_ATTRIBUTES
name: otc-container
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
readOnly: true
- env:
- name: OTEL_NODE_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.hostIP
- name: OTEL_POD_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
- name: OTEL_GO_AUTO_TARGET_EXE
value: /usr/src/app/productcatalogservice
- name: OTEL_SERVICE_NAME
value: goapp
- 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_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: opentelemetry-auto-instrumentation
volumeMounts:
- mountPath: /sys/kernel/debug
name: kernel-debug
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
readOnly: true
initContainers:
- command:
- cp
- -r
- /autoinstrumentation/.
- /otel-auto-instrumentation-python
name: opentelemetry-auto-instrumentation-python
volumeMounts:
- mountPath: /otel-auto-instrumentation-python
name: opentelemetry-auto-instrumentation-python
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
readOnly: true
status:
containerStatuses:
- name: goapp
ready: true
started: true
- name: opentelemetry-auto-instrumentation
ready: true
started: true
- name: otc-container
ready: true
started: true
- name: pythonapp
ready: true
started: true
initContainerStatuses:
- name: opentelemetry-auto-instrumentation-python
ready: true
state:
terminated:
reason: Completed
phase: Running
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-golang-multiinst
spec:
selector:
matchLabels:
app: my-golang-multiinst
replicas: 1
template:
metadata:
labels:
app: my-golang-multiinst
annotations:
sidecar.opentelemetry.io/inject: "true"
instrumentation.opentelemetry.io/inject-go: "true"
instrumentation.opentelemetry.io/otel-go-auto-target-exe: /usr/src/app/productcatalogservice
instrumentation.opentelemetry.io/inject-python: "true"
instrumentation.opentelemetry.io/python-container-names: "pythonapp"
instrumentation.opentelemetry.io/go-container-names: "goapp"
spec:
serviceAccountName: otel-instrumentation-go
securityContext:
runAsUser: 0
runAsGroup: 3000
fsGroup: 3000
containers:
- name: goapp
image: ghcr.io/open-telemetry/opentelemetry-operator/e2e-test-app-golang:main
- name: pythonapp
image: ghcr.io/open-telemetry/opentelemetry-operator/e2e-test-app-python:main
command: ["flask", "run", "-p", "8087"]
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
seccompProfile:
type: RuntimeDefault

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

if [[ "$(kubectl api-resources --api-group=operator.openshift.io -o name)" ]]; then
kubectl apply -f scc.yaml
oc adm policy add-scc-to-user otel-go-instrumentation -z otel-instrumentation-go -n $NAMESPACE
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
creationTimestamp: null
name: instrumentation-multi-multicontainer-go
spec:
steps:
- name: step-00
try:
# In OpenShift, when a namespace is created, all necessary SCC annotations are automatically added. However, if a namespace is created using a resource file with only selected SCCs, the other auto-added SCCs are not included. Therefore, the UID-range and supplemental groups SCC annotations must be set after the namespace is created.
- command:
entrypoint: kubectl
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.uid-range=0/0
- --overwrite
- command:
entrypoint: kubectl
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.supplemental-groups=3000/3000
- --overwrite
- apply:
file: 00-install-collector.yaml
- apply:
file: 00-install-instrumentation.yaml
- name: step-01
try:
- script:
content: ./add-scc.sh
- apply:
file: 01-add-scc.yaml
- name: step-02
try:
- apply:
file: 02-install-app.yaml
- assert:
file: 02-assert.yaml
catch:
- podLogs:
selector: app=my-golang
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: security.openshift.io/v1
kind: SecurityContextConstraints
metadata:
name: otel-go-instrumentation
allowHostDirVolumePlugin: true
allowPrivilegeEscalation: true
allowPrivilegedContainer: true
fsGroup:
type: RunAsAny
runAsUser:
type: RunAsAny
seLinuxContext:
type: RunAsAny
seccompProfiles:
- '*'
supplementalGroups:
type: RunAsAny
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,18 @@ spec:
env:
- name: OTEL_SERVICE_NAME
value: "goapp"
nginx:
configFile: /etc/nginx/conf.d/default.conf
env:
- name: OTEL_SERVICE_NAME
value: "nginxapp"
attrs:
- name: NginxModuleOtelMaxQueueSize
value: "4096"
apacheHttpd:
env:
- name: OTEL_SERVICE_NAME
value: "apache-httpd-app"
attrs:
- name: ApacheModuleOtelMaxQueueSize
value: "4096"
Loading

0 comments on commit 91759b0

Please sign in to comment.