Skip to content

Commit

Permalink
[chore] use config sample in e2e tests (#389)
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Bacher <[email protected]>
Co-authored-by: odubajDT <[email protected]>
  • Loading branch information
bacherfl and odubajDT authored Dec 4, 2024
1 parent dd32920 commit bd93e61
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 194 deletions.
70 changes: 70 additions & 0 deletions config_examples/k8s_attribute_redaction.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
extensions:
health_check:
endpoint: 0.0.0.0:13133
receivers:
otlp:
protocols:
grpc:
endpoint: ${env:MY_POD_IP}:4317
processors:
k8sattributes:
extract:
metadata:
- k8s.pod.name
- k8s.pod.uid
- k8s.deployment.name
- k8s.statefulset.name
- k8s.daemonset.name
- k8s.job.name
- k8s.cronjob.name
- k8s.namespace.name
- k8s.node.name
- k8s.cluster.uid
pod_association:
- sources:
- from: resource_attribute
name: k8s.pod.name
- from: resource_attribute
name: k8s.namespace.name
- sources:
- from: resource_attribute
name: k8s.pod.ip
- sources:
- from: resource_attribute
name: k8s.pod.uid
- sources:
- from: connection
redaction:
allow_all_keys: false
allowed_keys:
- "k8s.pod.uid"
- "k8s.namespace.name"
- "k8s.cluster.uid"
- "k8s.job.name"
- "k8s.statefulset.name"
- "k8s.deployment.name"
- "k8s.daemonset.name"
ignored_keys:
- "k8s.pod.name"
- "service.name"
blocked_values:
- "^[a-f0-9]{32}$"
- "^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$"
summary: info
exporters:
otlphttp:
endpoint: ${env:DT_ENDPOINT}
headers:
Authorization: "Api-Token ${env:DT_API_TOKEN}"
service:
extensions:
- health_check
pipelines:
traces:
receivers:
- otlp
processors:
- k8sattributes
- redaction
exporters:
- otlphttp
65 changes: 65 additions & 0 deletions config_examples/k8s_enrichment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
extensions:
health_check:
endpoint: 0.0.0.0:13133
receivers:
otlp:
protocols:
grpc:
endpoint: ${env:MY_POD_IP}:4317
processors:
k8sattributes:
extract:
metadata:
- k8s.pod.name
- k8s.pod.uid
- k8s.deployment.name
- k8s.statefulset.name
- k8s.daemonset.name
- k8s.job.name
- k8s.cronjob.name
- k8s.namespace.name
- k8s.node.name
- k8s.cluster.uid
pod_association:
- sources:
- from: resource_attribute
name: k8s.pod.name
- from: resource_attribute
name: k8s.namespace.name
- sources:
- from: resource_attribute
name: k8s.pod.ip
- sources:
- from: resource_attribute
name: k8s.pod.uid
- sources:
- from: connection
transform:
error_mode: ignore
trace_statements:
- context: resource
statements:
- set(attributes["dt.kubernetes.workload.kind"], "statefulset") where IsString(attributes["k8s.statefulset.name"])
- set(attributes["dt.kubernetes.workload.name"], attributes["k8s.statefulset.name"]) where IsString(attributes["k8s.statefulset.name"])
- set(attributes["dt.kubernetes.workload.kind"], "deployment") where IsString(attributes["k8s.deployment.name"])
- set(attributes["dt.kubernetes.workload.name"], attributes["k8s.deployment.name"]) where IsString(attributes["k8s.deployment.name"])
- set(attributes["dt.kubernetes.workload.kind"], "daemonset") where IsString(attributes["k8s.daemonset.name"])
- set(attributes["dt.kubernetes.workload.name"], attributes["k8s.daemonset.name"]) where IsString(attributes["k8s.daemonset.name"])
- set(attributes["dt.kubernetes.cluster.id"], attributes["k8s.cluster.uid"]) where IsString(attributes["k8s.cluster.uid"])
exporters:
otlphttp:
endpoint: ${env:DT_ENDPOINT}
headers:
Authorization: "Api-Token ${env:API_TOKEN}"
service:
extensions:
- health_check
pipelines:
traces:
receivers:
- otlp
processors:
- k8sattributes
- transform
exporters:
- otlphttp
33 changes: 33 additions & 0 deletions config_examples/prometheus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
extensions:
health_check:
endpoint: 0.0.0.0:13133
receivers:
prometheus:
config:
scrape_configs:
- job_name: 'node-exporter'
scrape_interval: 60s
static_configs:
- targets: ['prometheus-node-exporter:9100']
- job_name: opentelemetry-collector
scrape_interval: 60s
static_configs:
- targets:
- 127.0.0.1:8888

processors:
cumulativetodelta:

exporters:
otlphttp:
endpoint: ${env:DT_ENDPOINT}
headers:
Authorization: "Api-Token ${env:DT_API_TOKEN}"

service:
extensions: [health_check]
pipelines:
metrics:
receivers: [prometheus]
processors: [cumulativetodelta]
exporters: [otlphttp]
4 changes: 4 additions & 0 deletions config_examples/zipkin.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
extensions:
health_check:
endpoint: 0.0.0.0:13133
receivers:
zipkin:
endpoint: 0.0.0.0:9411
Expand All @@ -9,6 +12,7 @@ exporters:
Authorization: "Api-Token ${env:API_TOKEN}"

service:
extensions: [health_check]
pipelines:
traces:
receivers: [zipkin]
Expand Down
13 changes: 12 additions & 1 deletion internal/testbed/integration/k8senrichment/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package k8senrichment
import (
"fmt"
"os"
"path"
"path/filepath"
"testing"

Expand All @@ -31,6 +32,7 @@ type expectedValue struct {
// See: https://docs.dynatrace.com/docs/shortlink/otel-collector-cases-k8s-enrich
func TestE2E_ClusterRBAC(t *testing.T) {
testDir := filepath.Join("testdata")
configExamplesDir := "../../../../config_examples"

k8sClient, err := k8stest.NewK8sClient()
require.NoError(t, err)
Expand All @@ -56,7 +58,16 @@ func TestE2E_ClusterRBAC(t *testing.T) {
defer shutdownSinks()

testID := uuid.NewString()[:8]
collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(testDir, "collector"), "")
collectorObjs := k8stest.CreateCollectorObjects(
t,
k8sClient,
testID,
filepath.Join(testDir, "collector"),
path.Join(
configExamplesDir,
"k8s_enrichment.yaml",
),
)
createTeleOpts := &k8stest.TelemetrygenCreateOpts{
ManifestsDir: filepath.Join(testDir, "telemetrygen"),
TestID: testID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,4 @@ metadata:
namespace: e2ek8senrichment
data:
relay: |
extensions:
health_check:
endpoint: 0.0.0.0:13133
receivers:
otlp:
protocols:
grpc:
endpoint: ${env:MY_POD_IP}:4317
processors:
k8sattributes:
extract:
metadata:
- k8s.pod.name
- k8s.pod.uid
- k8s.deployment.name
- k8s.statefulset.name
- k8s.daemonset.name
- k8s.job.name
- k8s.cronjob.name
- k8s.namespace.name
- k8s.node.name
- k8s.cluster.uid
pod_association:
- sources:
- from: resource_attribute
name: k8s.pod.name
- from: resource_attribute
name: k8s.namespace.name
- sources:
- from: resource_attribute
name: k8s.pod.ip
- sources:
- from: resource_attribute
name: k8s.pod.uid
- sources:
- from: connection
transform:
error_mode: ignore
trace_statements:
- context: resource
statements:
- set(attributes["dt.kubernetes.workload.kind"], "statefulset") where IsString(attributes["k8s.statefulset.name"])
- set(attributes["dt.kubernetes.workload.name"], attributes["k8s.statefulset.name"]) where IsString(attributes["k8s.statefulset.name"])
- set(attributes["dt.kubernetes.workload.kind"], "deployment") where IsString(attributes["k8s.deployment.name"])
- set(attributes["dt.kubernetes.workload.name"], attributes["k8s.deployment.name"]) where IsString(attributes["k8s.deployment.name"])
- set(attributes["dt.kubernetes.workload.kind"], "daemonset") where IsString(attributes["k8s.daemonset.name"])
- set(attributes["dt.kubernetes.workload.name"], attributes["k8s.daemonset.name"]) where IsString(attributes["k8s.daemonset.name"])
- set(attributes["dt.kubernetes.cluster.id"], attributes["k8s.cluster.uid"]) where IsString(attributes["k8s.cluster.uid"])
exporters:
otlp:
endpoint: {{ .HostEndpoint }}:4317
tls:
insecure: true
service:
extensions:
- health_check
pipelines:
traces:
receivers:
- otlp
processors:
- k8sattributes
- transform
exporters:
- otlp
{{ .CollectorConfig }}
9 changes: 8 additions & 1 deletion internal/testbed/integration/prometheus/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
// See: https://docs.dynatrace.com/docs/shortlink/otel-collector-cases-prometheus
func TestE2E_PrometheusNodeExporter(t *testing.T) {
testDir := filepath.Join("testdata")
configExamplesDir := "../../../../config_examples"

k8sClient, err := k8stest.NewK8sClient()
require.NoError(t, err)
Expand Down Expand Up @@ -49,7 +50,13 @@ func TestE2E_PrometheusNodeExporter(t *testing.T) {
defer shutdownSinks()

testID := uuid.NewString()[:8]
collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(testDir, "collector"), "")
collectorObjs := k8stest.CreateCollectorObjects(
t,
k8sClient,
testID,
filepath.Join(testDir, "collector"),
filepath.Join(configExamplesDir, "prometheus.yaml"),
)
defer func() {
for _, obj := range collectorObjs {
require.NoErrorf(t, k8stest.DeleteObject(k8sClient, obj), "failed to delete object %s", obj.GetName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,4 @@ metadata:
namespace: e2eprometheus
data:
relay: |
extensions:
health_check:
endpoint: 0.0.0.0:13133
receivers:
prometheus:
config:
scrape_configs:
- job_name: 'node-exporter'
scrape_interval: 60s
static_configs:
- targets: ['prometheus-node-exporter.e2eprometheus.svc.cluster.local:9100']
- job_name: opentelemetry-collector
scrape_interval: 60s
static_configs:
- targets:
- 127.0.0.1:8888
processors:
cumulativetodelta:
exporters:
otlp:
endpoint: {{ .HostEndpoint }}:4317
tls:
insecure: true
service:
extensions:
- health_check
pipelines:
metrics:
receivers:
- prometheus
processors:
- cumulativetodelta
exporters:
- otlp
{{ .CollectorConfig }}
9 changes: 8 additions & 1 deletion internal/testbed/integration/redaction/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

func TestE2E_RedactionProcessor(t *testing.T) {
testDir := filepath.Join("testdata")
configExamplesDir := "../../../../config_examples"

k8sClient, err := k8stest.NewK8sClient()
require.NoError(t, err)
Expand All @@ -42,7 +43,13 @@ func TestE2E_RedactionProcessor(t *testing.T) {
defer shutdownSinks()

testID := uuid.NewString()[:8]
collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(testDir, "collector"), "")
collectorObjs := k8stest.CreateCollectorObjects(
t,
k8sClient,
testID,
filepath.Join(testDir, "collector"),
filepath.Join(configExamplesDir, "k8s_attribute_redaction.yaml"),
)

createTeleOpts := &k8stest.TelemetrygenCreateOpts{
ManifestsDir: filepath.Join(testDir, "telemetrygen"),
Expand Down
Loading

0 comments on commit bd93e61

Please sign in to comment.