Skip to content

Commit

Permalink
Merge pull request openshift#48 from IshwarKanse/transform
Browse files Browse the repository at this point in the history
Add test case for Transform processor
  • Loading branch information
IshwarKanse authored Jul 15, 2024
2 parents 0df0c41 + 438962b commit f8b9603
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/e2e-otel/transformprocessor/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: transformprocessor
spec:
namespace: chainsaw-tprocssr
steps:
- name: Create Tempo monolithic instances
try:
- apply:
file: install-tempo.yaml
- assert:
file: install-tempo-assert.yaml
- name: Create OTEL collector instance
try:
- apply:
file: otel-collector.yaml
- assert:
file: otel-collector-assert.yaml
- name: Generate and send traces to the OTEL collector
try:
- apply:
file: generate-traces.yaml
- assert:
file: generate-traces-assert.yaml
- name: Verify traces in the Tempo instances
try:
- apply:
file: verify-traces.yaml
- assert:
file: verify-traces-assert.yaml
7 changes: 7 additions & 0 deletions tests/e2e-otel/transformprocessor/generate-traces-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: batch/v1
kind: Job
metadata:
name: generate-traces-green
namespace: chainsaw-tprocssr
status:
succeeded: 1
20 changes: 20 additions & 0 deletions tests/e2e-otel/transformprocessor/generate-traces.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: batch/v1
kind: Job
metadata:
name: generate-traces-green
spec:
template:
spec:
containers:
- name: telemetrygen
image: ghcr.io/open-telemetry/opentelemetry-collector-contrib/telemetrygen:v0.92.0
args:
- traces
- --otlp-endpoint=tprocssr-collector.chainsaw-tprocssr.svc:4317
- --otlp-insecure=true
- --traces=1
- --service=green
- --otlp-attributes=X-Tenant="green"
- --otlp-attributes=generator="green-1"
restartPolicy: Never
backoffLimit: 4
52 changes: 52 additions & 0 deletions tests/e2e-otel/transformprocessor/install-tempo-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: tempo-tprocssr
namespace: chainsaw-tprocssr
status:
availableReplicas: 1
readyReplicas: 1
replicas: 1

---
apiVersion: v1
kind: Pod
metadata:
name: tempo-tprocssr-0
namespace: chainsaw-tprocssr
status:
containerStatuses:
- name: tempo
ready: true
started: true
- name: tempo-query
ready: true
started: true
phase: Running

---
apiVersion: v1
kind: Service
metadata:
name: tempo-tprocssr-jaegerui
namespace: chainsaw-tprocssr
spec:
ports:
- name: jaeger-grpc
port: 16685
protocol: TCP
targetPort: jaeger-grpc
- name: jaeger-ui
port: 16686
protocol: TCP
targetPort: jaeger-ui
- name: jaeger-metrics
port: 16687
protocol: TCP
targetPort: jaeger-metrics
selector:
app.kubernetes.io/component: tempo
app.kubernetes.io/instance: tprocssr
app.kubernetes.io/managed-by: tempo-operator
app.kubernetes.io/name: tempo-monolithic

9 changes: 9 additions & 0 deletions tests/e2e-otel/transformprocessor/install-tempo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: tempo.grafana.com/v1alpha1
kind: TempoMonolithic
metadata:
name: tprocssr
spec:
jaegerui:
enabled: true
route:
enabled: true
28 changes: 28 additions & 0 deletions tests/e2e-otel/transformprocessor/otel-collector-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: tprocssr-collector
namespace: chainsaw-tprocssr
status:
availableReplicas: 1
readyReplicas: 1
replicas: 1

---
apiVersion: v1
kind: Service
metadata:
name: tprocssr-collector
namespace: chainsaw-tprocssr
spec:
ports:
- appProtocol: grpc
name: otlp-grpc
port: 4317
protocol: TCP
targetPort: 4317
selector:
app.kubernetes.io/component: opentelemetry-collector
app.kubernetes.io/instance: chainsaw-tprocssr.tprocssr
app.kubernetes.io/managed-by: opentelemetry-operator
app.kubernetes.io/part-of: opentelemetry
43 changes: 43 additions & 0 deletions tests/e2e-otel/transformprocessor/otel-collector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
name: tprocssr
spec:
image: ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector-contrib:0.103.1
config:
receivers:
otlp:
protocols:
grpc: {}

exporters:
otlp:
endpoint: tempo-tprocssr.chainsaw-tprocssr.svc:4317
tls:
insecure: true

processors:
transform:
error_mode: ignore
trace_statements:
- context: resource
statements:
- keep_keys(attributes, ["service.name", "X-Tenant", "otel.library.name"])
- set(attributes["X-Tenant"], "blue") where attributes["X-Tenant"] == "green"
- limit(attributes, 100, [])
- truncate_all(attributes, 4096)
- context: span
statements:
- set(attributes["net.peer.ip"], "5.6.7.8") where attributes["net.peer.ip"] == "1.2.3.4"
- set(attributes["peer.service"], "modified-server") where attributes["peer.service"] == "telemetrygen-server"
- set(attributes["peer.service"], "modified-client") where attributes["peer.service"] == "telemetrygen-client"
- set(name, "modified-operation") where name == "okey-dokey"
- limit(attributes, 100, [])
- truncate_all(attributes, 4096)

service:
pipelines:
traces:
receivers: [otlp]
processors: [transform]
exporters: [otlp]
7 changes: 7 additions & 0 deletions tests/e2e-otel/transformprocessor/verify-traces-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: batch/v1
kind: Job
metadata:
name: verify-traces
namespace: chainsaw-tprocssr
status:
succeeded: 1
42 changes: 42 additions & 0 deletions tests/e2e-otel/transformprocessor/verify-traces.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: batch/v1
kind: Job
metadata:
name: verify-traces
spec:
template:
spec:
containers:
- name: verify-traces-green
image: ghcr.io/grafana/tempo-operator/test-utils:main
command:
- /bin/bash
- -eux
- -c
args:
- |
TRACE_JSON=$(curl -s -G http://tempo-tprocssr-jaegerui.chainsaw-tprocssr.svc:16686/api/traces --data-urlencode "service=green")
VALIDATE=$(echo $TRACE_JSON | jq '
.data[] |
select(
.spans[] |
(
(.operationName == "modified-operation") and
(.tags[] | select(.key == "net.peer.ip" and .value == "5.6.7.8")) and
(.tags[] | select(.key == "peer.service" and .value == "modified-client"))
)
) and
(
.processes[] |
(
(.tags[] | select(.key == "X-Tenant" and .value == "blue")) and
(.tags[] | select(.key == "otel.library.name" and .value == "telemetrygen"))
)
)
')
if [ -n "$VALIDATE" ]; then
echo "Validation passed: The trace values match the transform processor settings."
else
echo "Validation failed: The trace values do not match the transform processor settings."
exit 1
fi
restartPolicy: Never

0 comments on commit f8b9603

Please sign in to comment.