Skip to content

Commit 409ad4a

Browse files
committed
Test OpenTelemetry must-gather script
1 parent 2b36f0d commit 409ad4a

12 files changed

+515
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
annotations:
5+
instrumentation.opentelemetry.io/inject-nodejs: "true"
6+
sidecar.opentelemetry.io/inject: "true"
7+
labels:
8+
app: my-nodejs
9+
spec:
10+
containers:
11+
- env:
12+
- name: OTEL_NODE_IP
13+
valueFrom:
14+
fieldRef:
15+
fieldPath: status.hostIP
16+
- name: OTEL_POD_IP
17+
valueFrom:
18+
fieldRef:
19+
fieldPath: status.podIP
20+
- name: NODE_PATH
21+
value: /usr/local/lib/node_modules
22+
- name: OTEL_NODEJS_DEBUG
23+
value: "true"
24+
- name: NODE_OPTIONS
25+
value: ' --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js'
26+
- name: OTEL_TRACES_EXPORTER
27+
value: otlp
28+
- name: OTEL_EXPORTER_OTLP_ENDPOINT
29+
value: http://localhost:4317
30+
- name: OTEL_EXPORTER_OTLP_TIMEOUT
31+
value: "20"
32+
- name: OTEL_TRACES_SAMPLER
33+
value: parentbased_traceidratio
34+
- name: OTEL_TRACES_SAMPLER_ARG
35+
value: "0.85"
36+
- name: SPLUNK_TRACE_RESPONSE_HEADER_ENABLED
37+
value: "true"
38+
- name: OTEL_METRICS_EXPORTER
39+
value: prometheus
40+
- name: OTEL_SERVICE_NAME
41+
value: my-nodejs
42+
- name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME
43+
valueFrom:
44+
fieldRef:
45+
apiVersion: v1
46+
fieldPath: metadata.name
47+
- name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME
48+
valueFrom:
49+
fieldRef:
50+
apiVersion: v1
51+
fieldPath: spec.nodeName
52+
- name: OTEL_PROPAGATORS
53+
value: jaeger,b3
54+
- name: OTEL_RESOURCE_ATTRIBUTES
55+
name: myapp
56+
volumeMounts:
57+
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
58+
readOnly: true
59+
- mountPath: /otel-auto-instrumentation-nodejs
60+
name: opentelemetry-auto-instrumentation-nodejs
61+
- args:
62+
- --config=env:OTEL_CONFIG
63+
name: otc-container
64+
initContainers:
65+
- name: opentelemetry-auto-instrumentation-nodejs
66+
status:
67+
containerStatuses:
68+
- name: myapp
69+
ready: true
70+
started: true
71+
- name: otc-container
72+
ready: true
73+
started: true
74+
initContainerStatuses:
75+
- name: opentelemetry-auto-instrumentation-nodejs
76+
ready: true
77+
phase: Running
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
apiVersion: apps/v1
2+
kind: StatefulSet
3+
metadata:
4+
name: stateful-collector
5+
status:
6+
readyReplicas: 1
7+
replicas: 1
8+
---
9+
apiVersion: apps/v1
10+
kind: Deployment
11+
metadata:
12+
name: stateful-targetallocator
13+
status:
14+
observedGeneration: 1
15+
readyReplicas: 1
16+
replicas: 1
17+
---
18+
apiVersion: v1
19+
data:
20+
collector.yaml: |
21+
exporters:
22+
debug: {}
23+
processors: {}
24+
receivers:
25+
jaeger:
26+
protocols:
27+
grpc:
28+
endpoint: 0.0.0.0:14250
29+
prometheus:
30+
config:
31+
global:
32+
scrape_interval: 30s
33+
scrape_protocols:
34+
- PrometheusProto
35+
- OpenMetricsText1.0.0
36+
- OpenMetricsText0.0.1
37+
- PrometheusText0.0.4
38+
target_allocator:
39+
collector_id: ${POD_NAME}
40+
endpoint: http://stateful-targetallocator:80
41+
interval: 30s
42+
service:
43+
pipelines:
44+
traces:
45+
exporters:
46+
- debug
47+
receivers:
48+
- jaeger
49+
telemetry:
50+
metrics:
51+
address: 0.0.0.0:8888
52+
kind: ConfigMap
53+
metadata:
54+
labels:
55+
app.kubernetes.io/component: opentelemetry-collector
56+
app.kubernetes.io/instance: chainsaw-must-gather.stateful
57+
app.kubernetes.io/managed-by: opentelemetry-operator
58+
app.kubernetes.io/name: stateful-collector
59+
app.kubernetes.io/part-of: opentelemetry
60+
name: stateful-collector-2729987d
61+
namespace: chainsaw-must-gather
62+
---
63+
apiVersion: v1
64+
kind: ConfigMap
65+
metadata:
66+
name: stateful-targetallocator
67+
namespace: ($namespace)
68+
data:
69+
targetallocator.yaml:
70+
(parse_yaml(@)):
71+
allocation_strategy: consistent-hashing
72+
collector_selector:
73+
matchlabels:
74+
app.kubernetes.io/component: opentelemetry-collector
75+
app.kubernetes.io/instance: (join('.', [$namespace, 'stateful']))
76+
app.kubernetes.io/managed-by: opentelemetry-operator
77+
app.kubernetes.io/part-of: opentelemetry
78+
matchexpressions: [ ]
79+
config:
80+
global:
81+
scrape_interval: 30s
82+
scrape_protocols:
83+
- PrometheusProto
84+
- OpenMetricsText1.0.0
85+
- OpenMetricsText0.0.1
86+
- PrometheusText0.0.4
87+
scrape_configs:
88+
- job_name: otel-collector
89+
scrape_interval: 10s
90+
static_configs:
91+
- targets:
92+
- 0.0.0.0:8888
93+
filter_strategy: relabel-config
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
apiVersion: chainsaw.kyverno.io/v1alpha1
2+
kind: Test
3+
metadata:
4+
name: must-gather
5+
spec:
6+
namespace: chainsaw-must-gather
7+
steps:
8+
- name: Install Target Allocator
9+
try:
10+
- apply:
11+
template: true
12+
file: install-target-allocator.yaml
13+
- assert:
14+
file: assert-install-target-allocator.yaml
15+
catch:
16+
- podLogs:
17+
selector: app.kubernetes.io/component=opentelemetry-targetallocator
18+
- name: Create instrumentation CR and sidecar collector instance
19+
try:
20+
# 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.
21+
- command:
22+
entrypoint: kubectl
23+
args:
24+
- annotate
25+
- namespace
26+
- ${NAMESPACE}
27+
- openshift.io/sa.scc.uid-range=1000/1000
28+
- --overwrite
29+
- command:
30+
entrypoint: kubectl
31+
args:
32+
- annotate
33+
- namespace
34+
- ${NAMESPACE}
35+
- openshift.io/sa.scc.supplemental-groups=3000/3000
36+
- --overwrite
37+
- apply:
38+
file: install-collector-sidecar.yaml
39+
- apply:
40+
file: install-instrumentation.yaml
41+
- name: Install app
42+
try:
43+
- apply:
44+
file: install-app.yaml
45+
- assert:
46+
file: assert-install-app.yaml
47+
catch:
48+
- podLogs:
49+
selector: app=my-nodejs
50+
- name: Run the must-gather and verify the contents
51+
try:
52+
- command:
53+
entrypoint: oc
54+
args:
55+
- get
56+
- pods
57+
- -A
58+
- -l control-plane=controller-manager
59+
- -l app.kubernetes.io/name=opentelemetry-operator
60+
- -o
61+
- jsonpath={.items[0].metadata.namespace}
62+
outputs:
63+
- name: OTEL_NAMESPACE
64+
value: ($stdout)
65+
- script:
66+
env:
67+
- name: otelnamespace
68+
value: ($OTEL_NAMESPACE)
69+
timeout: 5m
70+
content: ./check_must_gather.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
# Create a temporary directory to store must-gather
4+
MUST_GATHER_DIR=$(mktemp -d)
5+
6+
# Run the must-gather script
7+
oc adm must-gather --dest-dir=$MUST_GATHER_DIR --image=ghcr.io/open-telemetry/opentelemetry-operator/must-gather:latest -- /usr/bin/must-gather --operator-namespace $otelnamespace
8+
9+
# Define required files and directories
10+
REQUIRED_ITEMS=(
11+
event-filter.html
12+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/*opentelemetry-operato*.yaml
13+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/clusterserviceversion-opentelemetry-operator-v*.yaml
14+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/installplan-install-*.yaml
15+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/subscription-opentelemetry-operator-v*-sub.yaml
16+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-collector-headless.yaml
17+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-collector.yaml
18+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/deployment-stateful-targetallocator.yaml
19+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-collector-monitoring.yaml
20+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/poddisruptionbudget-stateful-targetallocator.yaml
21+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/poddisruptionbudget-stateful-collector.yaml
22+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-targetallocator.yaml
23+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/configmap-stateful-collector-2729987d.yaml
24+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/configmap-stateful-targetallocator.yaml
25+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/statefulset-stateful-collector.yaml
26+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/opentelemetrycollector-stateful.yaml
27+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/serviceaccount-stateful-collector.yaml
28+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/service-sidecar-collector.yaml
29+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/opentelemetrycollector-sidecar.yaml
30+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/service-sidecar-collector-monitoring.yaml
31+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/configmap-sidecar-collector-3826c0e7.yaml
32+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/serviceaccount-sidecar-collector.yaml
33+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/service-sidecar-collector-headless.yaml
34+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/chainsaw-must-gather/instrumentation-nodejs.yaml
35+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/opentelemetry-operator-controller-manager-*
36+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/deployment-opentelemetry-operator-controller-manager.yaml
37+
timestamp
38+
)
39+
40+
# Verify each required item
41+
for item in "${REQUIRED_ITEMS[@]}"; do
42+
if ! find "$MUST_GATHER_DIR" -path "$MUST_GATHER_DIR/$item" -print -quit | grep -q .; then
43+
echo "Missing: $item"
44+
exit 1
45+
else
46+
echo "Found: $item"
47+
fi
48+
done
49+
50+
# Cleanup the must-gather directory
51+
rm -rf $MUST_GATHER_DIR
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: my-nodejs
5+
spec:
6+
selector:
7+
matchLabels:
8+
app: my-nodejs
9+
replicas: 1
10+
template:
11+
metadata:
12+
labels:
13+
app: my-nodejs
14+
annotations:
15+
sidecar.opentelemetry.io/inject: "true"
16+
instrumentation.opentelemetry.io/inject-nodejs: "true"
17+
spec:
18+
securityContext:
19+
runAsUser: 1000
20+
runAsGroup: 3000
21+
fsGroup: 3000
22+
containers:
23+
- name: myapp
24+
image: ghcr.io/open-telemetry/opentelemetry-operator/e2e-test-app-nodejs:main
25+
securityContext:
26+
allowPrivilegeEscalation: false
27+
capabilities:
28+
drop: ["ALL"]
29+
env:
30+
- name: NODE_PATH
31+
value: /usr/local/lib/node_modules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: opentelemetry.io/v1beta1
2+
kind: OpenTelemetryCollector
3+
metadata:
4+
name: sidecar
5+
spec:
6+
config:
7+
receivers:
8+
otlp:
9+
protocols:
10+
grpc: {}
11+
http: {}
12+
processors: {}
13+
14+
exporters:
15+
debug:
16+
17+
service:
18+
pipelines:
19+
traces:
20+
receivers: [otlp]
21+
exporters: [debug]
22+
mode: sidecar
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apiVersion: opentelemetry.io/v1alpha1
2+
kind: Instrumentation
3+
metadata:
4+
name: nodejs
5+
spec:
6+
env:
7+
- name: OTEL_TRACES_EXPORTER
8+
value: otlp
9+
- name: OTEL_EXPORTER_OTLP_ENDPOINT
10+
value: http://localhost:4317
11+
- name: OTEL_EXPORTER_OTLP_TIMEOUT
12+
value: "20"
13+
- name: OTEL_TRACES_SAMPLER
14+
value: parentbased_traceidratio
15+
- name: OTEL_TRACES_SAMPLER_ARG
16+
value: "0.85"
17+
- name: SPLUNK_TRACE_RESPONSE_HEADER_ENABLED
18+
value: "true"
19+
- name: OTEL_METRICS_EXPORTER
20+
value: prometheus
21+
exporter:
22+
endpoint: http://localhost:4317
23+
propagators:
24+
- jaeger
25+
- b3
26+
sampler:
27+
type: parentbased_traceidratio
28+
argument: "0.25"
29+
nodejs:
30+
env:
31+
- name: OTEL_NODEJS_DEBUG
32+
value: "true"
33+

0 commit comments

Comments
 (0)