Skip to content

Commit 57eeb5a

Browse files
committed
Test OpenTelemetry must-gather script
1 parent 70dff69 commit 57eeb5a

11 files changed

+511
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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: install-target-allocator-assert.yaml
15+
catch:
16+
- podLogs:
17+
selector: app.kubernetes.io/component=opentelemetry-targetallocator
18+
- name: assert-data-propagates
19+
try:
20+
- assert:
21+
resource:
22+
apiVersion: v1
23+
kind: ConfigMap
24+
metadata:
25+
name: stateful-targetallocator
26+
namespace: ($namespace)
27+
data:
28+
targetallocator.yaml:
29+
(parse_yaml(@)):
30+
allocation_strategy: consistent-hashing
31+
collector_selector:
32+
matchlabels:
33+
app.kubernetes.io/component: opentelemetry-collector
34+
app.kubernetes.io/instance: (join('.', [$namespace, 'stateful']))
35+
app.kubernetes.io/managed-by: opentelemetry-operator
36+
app.kubernetes.io/part-of: opentelemetry
37+
matchexpressions: [ ]
38+
config:
39+
global:
40+
scrape_interval: 30s
41+
scrape_protocols:
42+
- PrometheusProto
43+
- OpenMetricsText1.0.0
44+
- OpenMetricsText0.0.1
45+
- PrometheusText0.0.4
46+
scrape_configs:
47+
- job_name: otel-collector
48+
scrape_interval: 10s
49+
static_configs:
50+
- targets:
51+
- 0.0.0.0:8888
52+
filter_strategy: relabel-config
53+
- name: Create instrumentation CR and sidecar collector instance
54+
try:
55+
# 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.
56+
- command:
57+
entrypoint: kubectl
58+
args:
59+
- annotate
60+
- namespace
61+
- ${NAMESPACE}
62+
- openshift.io/sa.scc.uid-range=1000/1000
63+
- --overwrite
64+
- command:
65+
entrypoint: kubectl
66+
args:
67+
- annotate
68+
- namespace
69+
- ${NAMESPACE}
70+
- openshift.io/sa.scc.supplemental-groups=3000/3000
71+
- --overwrite
72+
- apply:
73+
file: install-collector-sidecar.yaml
74+
- apply:
75+
file: install-instrumentation.yaml
76+
- name: Install app
77+
try:
78+
- apply:
79+
file: install-app.yaml
80+
- assert:
81+
file: install-app-assert.yaml
82+
catch:
83+
- podLogs:
84+
selector: app=my-nodejs
85+
- name: Run the must-gather and verify the contents
86+
try:
87+
- command:
88+
entrypoint: oc
89+
args:
90+
- get
91+
- pods
92+
- -A
93+
- -l control-plane=controller-manager
94+
- -l app.kubernetes.io/name=opentelemetry-operator
95+
- -o
96+
- jsonpath={.items[0].metadata.namespace}
97+
outputs:
98+
- name: OTEL_NAMESPACE
99+
value: ($stdout)
100+
- script:
101+
env:
102+
- name: otelnamespace
103+
value: ($OTEL_NAMESPACE)
104+
timeout: 5m
105+
content: ./check_must_gather.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
# Create the directory to store must-gather
4+
MUST_GATHER_DIR=/tmp/must-gather
5+
mkdir -p $MUST_GATHER_DIR
6+
7+
# Run the must-gather script
8+
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
9+
10+
# Define required files and directories
11+
REQUIRED_ITEMS=(
12+
event-filter.html
13+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/*opentelemetry-operato*.yaml
14+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/clusterserviceversion-opentelemetry-operator-v*.yaml
15+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/installplan-install-*.yaml
16+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/subscription-opentelemetry-operator-v*-sub.yaml
17+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-collector-headless.yaml
18+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-collector.yaml
19+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/deployment-stateful-targetallocator.yaml
20+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-collector-monitoring.yaml
21+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/poddisruptionbudget-stateful-targetallocator.yaml
22+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/poddisruptionbudget-stateful-collector.yaml
23+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-targetallocator.yaml
24+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/configmap-stateful-collector-7a42612e.yaml
25+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/configmap-stateful-targetallocator.yaml
26+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/statefulset-stateful-collector.yaml
27+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/opentelemetrycollector-stateful.yaml
28+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/serviceaccount-stateful-collector.yaml
29+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/service-sidecar-collector.yaml
30+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/opentelemetrycollector-sidecar.yaml
31+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/service-sidecar-collector-monitoring.yaml
32+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/configmap-sidecar-collector-aec5aa11.yaml
33+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/serviceaccount-sidecar-collector.yaml
34+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/service-sidecar-collector-headless.yaml
35+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/chainsaw-must-gather/instrumentation-nodejs.yaml
36+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/opentelemetry-operator-controller-manager-*
37+
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/deployment-opentelemetry-operator-controller-manager.yaml
38+
timestamp
39+
)
40+
41+
# Verify each required item
42+
for item in "${REQUIRED_ITEMS[@]}"; do
43+
if ! find "$MUST_GATHER_DIR" -path "$MUST_GATHER_DIR/$item" -print -quit | grep -q .; then
44+
echo "Missing: $item"
45+
exit 1
46+
else
47+
echo "Found: $item"
48+
fi
49+
done
50+
51+
# Cleanup the must-gather directory
52+
rm -rf $MUST_GATHER_DIR
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,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/v1alpha1
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+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
kind: ConfigMap
20+
metadata:
21+
name: stateful-targetallocator
22+
---
23+
apiVersion: v1
24+
data:
25+
collector.yaml: |
26+
exporters:
27+
debug: null
28+
receivers:
29+
jaeger:
30+
protocols:
31+
grpc:
32+
endpoint: 0.0.0.0:14250
33+
prometheus:
34+
config:
35+
global:
36+
scrape_interval: 30s
37+
scrape_protocols:
38+
- PrometheusProto
39+
- OpenMetricsText1.0.0
40+
- OpenMetricsText0.0.1
41+
- PrometheusText0.0.4
42+
target_allocator:
43+
collector_id: ${POD_NAME}
44+
endpoint: http://stateful-targetallocator:80
45+
interval: 30s
46+
service:
47+
pipelines:
48+
traces:
49+
exporters:
50+
- debug
51+
receivers:
52+
- jaeger
53+
telemetry:
54+
metrics:
55+
address: 0.0.0.0:8888
56+
kind: ConfigMap
57+
metadata:
58+
name: stateful-collector-7a42612e

0 commit comments

Comments
 (0)