Skip to content

Commit

Permalink
Test OpenTelemetry must-gather script
Browse files Browse the repository at this point in the history
  • Loading branch information
IshwarKanse committed Oct 28, 2024
1 parent 2b36f0d commit 2264638
Show file tree
Hide file tree
Showing 15 changed files with 525 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ metadata:
categories: Logging & Tracing,Monitoring
certified: "false"
containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
createdAt: "2024-10-16T10:10:50Z"
createdAt: "2024-10-28T04:16:30Z"
description: Provides the OpenTelemetry components, including the Collector
operators.operatorframework.io/builder: operator-sdk-v1.29.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
Expand Down Expand Up @@ -481,7 +481,7 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.serviceAccountName
image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.111.0
image: quay.io/rhn_support_ikanse/opentelemetry-operator:latest
livenessProbe:
httpGet:
path: /healthz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ metadata:
categories: Logging & Tracing,Monitoring
certified: "false"
containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
createdAt: "2024-10-16T10:10:50Z"
createdAt: "2024-10-28T04:16:35Z"
description: Provides the OpenTelemetry components, including the Collector
operators.operatorframework.io/builder: operator-sdk-v1.29.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
Expand Down Expand Up @@ -485,7 +485,7 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.serviceAccountName
image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.111.0
image: quay.io/rhn_support_ikanse/opentelemetry-operator:latest
livenessProbe:
httpGet:
path: /healthz
Expand Down
6 changes: 6 additions & 0 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
resources:
- manager.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: quay.io/rhn_support_ikanse/opentelemetry-operator
newTag: latest
77 changes: 77 additions & 0 deletions tests/e2e-openshift/must-gather/assert-install-app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apiVersion: v1
kind: Pod
metadata:
annotations:
instrumentation.opentelemetry.io/inject-nodejs: "true"
sidecar.opentelemetry.io/inject: "true"
labels:
app: my-nodejs
spec:
containers:
- env:
- name: OTEL_NODE_IP
valueFrom:
fieldRef:
fieldPath: status.hostIP
- name: OTEL_POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: NODE_PATH
value: /usr/local/lib/node_modules
- name: OTEL_NODEJS_DEBUG
value: "true"
- name: NODE_OPTIONS
value: ' --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js'
- 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_METRICS_EXPORTER
value: prometheus
- name: OTEL_SERVICE_NAME
value: my-nodejs
- 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: myapp
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
readOnly: true
- mountPath: /otel-auto-instrumentation-nodejs
name: opentelemetry-auto-instrumentation-nodejs
- args:
- --config=env:OTEL_CONFIG
name: otc-container
initContainers:
- name: opentelemetry-auto-instrumentation-nodejs
status:
containerStatuses:
- name: myapp
ready: true
started: true
- name: otc-container
ready: true
started: true
initContainerStatuses:
- name: opentelemetry-auto-instrumentation-nodejs
ready: true
phase: Running
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: stateful-collector
status:
readyReplicas: 1
replicas: 1
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: stateful-targetallocator
status:
observedGeneration: 1
readyReplicas: 1
replicas: 1
---
apiVersion: v1
data:
collector.yaml: |
exporters:
debug: {}
processors: {}
receivers:
jaeger:
protocols:
grpc:
endpoint: 0.0.0.0:14250
prometheus:
config:
global:
scrape_interval: 30s
scrape_protocols:
- PrometheusProto
- OpenMetricsText1.0.0
- OpenMetricsText0.0.1
- PrometheusText0.0.4
target_allocator:
collector_id: ${POD_NAME}
endpoint: http://stateful-targetallocator:80
interval: 30s
service:
pipelines:
traces:
exporters:
- debug
receivers:
- jaeger
telemetry:
metrics:
address: 0.0.0.0:8888
kind: ConfigMap
metadata:
labels:
app.kubernetes.io/component: opentelemetry-collector
app.kubernetes.io/instance: chainsaw-must-gather.stateful
app.kubernetes.io/managed-by: opentelemetry-operator
app.kubernetes.io/name: stateful-collector
app.kubernetes.io/part-of: opentelemetry
name: stateful-collector-2729987d
namespace: chainsaw-must-gather
---
apiVersion: v1
kind: ConfigMap
metadata:
name: stateful-targetallocator
namespace: ($namespace)
data:
targetallocator.yaml:
(parse_yaml(@)):
allocation_strategy: consistent-hashing
collector_selector:
matchlabels:
app.kubernetes.io/component: opentelemetry-collector
app.kubernetes.io/instance: (join('.', [$namespace, 'stateful']))
app.kubernetes.io/managed-by: opentelemetry-operator
app.kubernetes.io/part-of: opentelemetry
matchexpressions: [ ]
config:
global:
scrape_interval: 30s
scrape_protocols:
- PrometheusProto
- OpenMetricsText1.0.0
- OpenMetricsText0.0.1
- PrometheusText0.0.4
scrape_configs:
- job_name: otel-collector
scrape_interval: 10s
static_configs:
- targets:
- 0.0.0.0:8888
filter_strategy: relabel-config
70 changes: 70 additions & 0 deletions tests/e2e-openshift/must-gather/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: must-gather
spec:
namespace: chainsaw-must-gather
steps:
- name: Install Target Allocator
try:
- apply:
template: true
file: install-target-allocator.yaml
- assert:
file: assert-install-target-allocator.yaml
catch:
- podLogs:
selector: app.kubernetes.io/component=opentelemetry-targetallocator
- name: Create instrumentation CR and sidecar collector instance
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=1000/1000
- --overwrite
- command:
entrypoint: kubectl
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.supplemental-groups=3000/3000
- --overwrite
- apply:
file: install-collector-sidecar.yaml
- apply:
file: install-instrumentation.yaml
- name: Install app
try:
- apply:
file: install-app.yaml
- assert:
file: assert-install-app.yaml
catch:
- podLogs:
selector: app=my-nodejs
- name: Run the must-gather and verify the contents
try:
- command:
entrypoint: oc
args:
- get
- pods
- -A
- -l control-plane=controller-manager
- -l app.kubernetes.io/name=opentelemetry-operator
- -o
- jsonpath={.items[0].metadata.namespace}
outputs:
- name: OTEL_NAMESPACE
value: ($stdout)
- script:
env:
- name: otelnamespace
value: ($OTEL_NAMESPACE)
timeout: 5m
content: ./check_must_gather.sh
51 changes: 51 additions & 0 deletions tests/e2e-openshift/must-gather/check_must_gather.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

# Create a temporary directory to store must-gather
MUST_GATHER_DIR=$(mktemp -d)

# Run the must-gather script
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

# Define required files and directories
REQUIRED_ITEMS=(
event-filter.html
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/*opentelemetry-operato*.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/clusterserviceversion-opentelemetry-operator-v*.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/installplan-install-*.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/subscription-opentelemetry-operator-v*-sub.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-collector-headless.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-collector.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/deployment-stateful-targetallocator.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-collector-monitoring.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/poddisruptionbudget-stateful-targetallocator.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/poddisruptionbudget-stateful-collector.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-targetallocator.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/configmap-stateful-collector-2729987d.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/configmap-stateful-targetallocator.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/statefulset-stateful-collector.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/opentelemetrycollector-stateful.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/serviceaccount-stateful-collector.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/service-sidecar-collector.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/opentelemetrycollector-sidecar.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/service-sidecar-collector-monitoring.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/configmap-sidecar-collector-3826c0e7.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/serviceaccount-sidecar-collector.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/service-sidecar-collector-headless.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/chainsaw-must-gather/instrumentation-nodejs.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/opentelemetry-operator-controller-manager-*
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/deployment-opentelemetry-operator-controller-manager.yaml
timestamp
)

# Verify each required item
for item in "${REQUIRED_ITEMS[@]}"; do
if ! find "$MUST_GATHER_DIR" -path "$MUST_GATHER_DIR/$item" -print -quit | grep -q .; then
echo "Missing: $item"
exit 1
else
echo "Found: $item"
fi
done

# Cleanup the must-gather directory
rm -rf $MUST_GATHER_DIR
31 changes: 31 additions & 0 deletions tests/e2e-openshift/must-gather/install-app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nodejs
spec:
selector:
matchLabels:
app: my-nodejs
replicas: 1
template:
metadata:
labels:
app: my-nodejs
annotations:
sidecar.opentelemetry.io/inject: "true"
instrumentation.opentelemetry.io/inject-nodejs: "true"
spec:
securityContext:
runAsUser: 1000
runAsGroup: 3000
fsGroup: 3000
containers:
- name: myapp
image: ghcr.io/open-telemetry/opentelemetry-operator/e2e-test-app-nodejs:main
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
env:
- name: NODE_PATH
value: /usr/local/lib/node_modules
22 changes: 22 additions & 0 deletions tests/e2e-openshift/must-gather/install-collector-sidecar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
name: sidecar
spec:
config:
receivers:
otlp:
protocols:
grpc: {}
http: {}
processors: {}

exporters:
debug:

service:
pipelines:
traces:
receivers: [otlp]
exporters: [debug]
mode: sidecar
Loading

0 comments on commit 2264638

Please sign in to comment.