Skip to content

Commit

Permalink
Add e2e test for Datadog tracing
Browse files Browse the repository at this point in the history
Signed-off-by: Hartigan <hartigans@live.com>
  • Loading branch information
Hartigan committed Oct 18, 2024
1 parent 5a1c065 commit afe3895
Show file tree
Hide file tree
Showing 2 changed files with 227 additions and 1 deletion.
161 changes: 161 additions & 0 deletions test/e2e/testdata/tracing-datadog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: eg-special-case-datadog
namespace: gateway-conformance-infra
spec:
gatewayClassName: "{GATEWAY_CLASS_NAME}"
listeners:
- name: http
port: 80
protocol: HTTP
allowedRoutes:
namespaces:
from: All
infrastructure:
parametersRef:
group: gateway.envoyproxy.io
kind: EnvoyProxy
name: datadog-tracing
---
apiVersion: v1
kind: ConfigMap
metadata:
name: alloy-config
namespace: monitoring
data:
config.alloy: |
logging {
level = "debug"
format = "logfmt"
}
otelcol.processor.batch "default" {
output {
metrics = [otelcol.exporter.otlp.default.input]
traces = [otelcol.exporter.otlp.default.input]
}
}
otelcol.processor.deltatocumulative "default" {
max_stale = "5m"
max_streams = 100
output {
metrics = [otelcol.processor.batch.default.input]
}
}
otelcol.exporter.otlp "default" {
client {
endpoint = "otel-collector:4317"
tls {
insecure = true
}
}
}
otelcol.receiver.datadog "default" {
endpoint = "0.0.0.0:8126"
output {
metrics = [otelcol.processor.deltatocumulative.default.input]
traces = [otelcol.processor.batch.default.input]
}
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: alloy-deployment
namespace: monitoring
spec:
replicas: 1
selector:
matchLabels:
app: alloy
template:
metadata:
labels:
app: alloy
spec:
containers:
- name: alloy
image: grafana/alloy:v1.4.2
volumeMounts:
- name: config-volume
mountPath: /etc/alloy/config.alloy
subPath: config.alloy
command: ["alloy", "run", "--stability.level=experimental", "--server.http.listen-addr=0.0.0.0:12345", "--storage.path=/var/lib/alloy/data", "/etc/alloy/config.alloy"]
volumes:
- name: config-volume
configMap:
name: alloy-config
---
apiVersion: v1
kind: Service
metadata:
name: alloy-collector
namespace: monitoring
spec:
selector:
app: alloy
ports:
- protocol: TCP
port: 8126
targetPort: 8126
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyProxy
metadata:
name: datadog-tracing
namespace: gateway-conformance-infra
spec:
logging:
level:
default: debug
telemetry:
tracing:
provider:
type: Datadog
backendRefs:
- name: alloy-collector
namespace: monitoring
port: 8126
customTags:
"provider":
type: Literal
literal:
value: "datadog"
"k8s.cluster.name":
type: Literal
literal:
value: "envoy-gateway"
"k8s.pod.name":
type: Environment
environment:
name: ENVOY_POD_NAME
defaultValue: "-"
"k8s.namespace.name":
type: Environment
environment:
name: ENVOY_GATEWAY_NAMESPACE
defaultValue: "envoy-gateway-system"
shutdown:
drainTimeout: 5s
minDrainDuration: 1s
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: tracing-datadog
namespace: gateway-conformance-infra
spec:
parentRefs:
- name: eg-special-case-datadog
rules:
- matches:
- path:
type: PathPrefix
value: /datadog
backendRefs:
- name: infra-backend-v2
port: 8080
67 changes: 66 additions & 1 deletion test/e2e/tests/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func init() {
ConformanceTests = append(ConformanceTests, OpenTelemetryTracingTest, ZipkinTracingTest)
ConformanceTests = append(ConformanceTests, OpenTelemetryTracingTest, ZipkinTracingTest, DatadogTracingTest)
}

var OpenTelemetryTracingTest = suite.ConformanceTest{
Expand Down Expand Up @@ -141,3 +141,68 @@ var ZipkinTracingTest = suite.ConformanceTest{
})
},
}

var DatadogTracingTest = suite.ConformanceTest{
ShortName: "DatadogTracing",
Description: "Make sure Datadog tracing is working",
Manifests: []string{"testdata/tracing-datadog.yaml"},
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
t.Run("tempo", func(t *testing.T) {
ns := "gateway-conformance-infra"
routeNN := types.NamespacedName{Name: "tracing-datadog", Namespace: ns}
gwNN := types.NamespacedName{Name: "eg-special-case-datadog", Namespace: ns}
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)

expectedResponse := httputils.ExpectedResponse{
Request: httputils.Request{
Path: "/datadog",
},
Response: httputils.Response{
StatusCode: 200,
},
Namespace: ns,
}
// make sure listener is ready
httputils.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse)

tags := map[string]string{
"component": "proxy",
"provider": "datadog",
"service.name": fmt.Sprintf("%s.%s", gwNN.Name, gwNN.Namespace),
}
if err := wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute, true,
func(ctx context.Context) (bool, error) {
preCount, err := QueryTraceFromTempo(t, suite.Client, tags)
if err != nil {
tlog.Logf(t, "failed to get trace count from tempo: %v", err)
return false, nil
}

httputils.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse)

// looks like we need almost 15 seconds to get the trace from Tempo?
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, 60*time.Second, true, func(ctx context.Context) (done bool, err error) {
curCount, err := QueryTraceFromTempo(t, suite.Client, tags)
if err != nil {
tlog.Logf(t, "failed to get curCount count from tempo: %v", err)
return false, nil
}

if curCount > preCount {
return true, nil
}

return false, nil
})
if err != nil {
tlog.Logf(t, "failed to get current count from tempo: %v", err)
return false, nil
}

return true, nil
}); err != nil {
t.Errorf("failed to get trace from tempo: %v", err)
}
})
},
}

0 comments on commit afe3895

Please sign in to comment.