Skip to content

Commit

Permalink
Tests and some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanrolds committed Jan 23, 2025
1 parent fe9e861 commit 435f15d
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 129 deletions.
63 changes: 63 additions & 0 deletions test/kubernetes/e2e/features/tracing/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tracing

import (
"context"
"fmt"
"net/http"
"time"

Expand Down Expand Up @@ -219,3 +220,65 @@ func (s *testingSuite) TestSpanNameTransformationsWithRouteDecorator() {
assert.Regexp(c, "Name *: "+routeDescriptorSpanName, logs)
}, time.Second*30, time.Second*3, "otelcol logs contain span with name == routeDescriptor")
}

func (s *testingSuite) TestGatewayWithoutOtelTracingGrpcAuthority() {
s.testInstallation.Assertions.AssertEventuallyConsistentCurlResponse(s.ctx, testdefaults.CurlPodExecOpt,
[]curl.Option{
curl.WithHost(kubeutils.ServiceFQDN(metav1.ObjectMeta{
Name: gatewayProxyHost,
Namespace: s.testInstallation.Metadata.InstallNamespace,
})),
curl.WithHostHeader("example.com"),
curl.WithPort(gatewayProxyPort),
curl.WithPath(pathWithRouteDescriptor),
curl.Silent(),
},
&matchers.HttpResponse{
StatusCode: http.StatusOK,
},
5*time.Second, 30*time.Second,
)

s.EventuallyWithT(func(c *assert.CollectT) {
logs, err := s.testInstallation.Actions.Kubectl().GetContainerLogs(s.ctx, otelcolPod.ObjectMeta.GetNamespace(), otelcolPod.ObjectMeta.GetName())
assert.NoError(c, err, "can get otelcol logs")

fmt.Printf("logs: %s\n", logs)

assert.Regexp(c, `-> authority: Str\(opentelemetry-collector_default\)`, logs)
//s.Fail("this test is not implemented yet")
}, time.Second*30, time.Second*3, "otelcol logs contain cluster name as authority")
}

func (s *testingSuite) TestGatewayWithOtelTracingGrpcAuthority() {
err := s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, gatewayAuthorityConfigManifest,
"-n", s.testInstallation.Metadata.InstallNamespace)
s.NoError(err, "can apply service/gateway-proxy-tracing")

s.testInstallation.Assertions.AssertEventuallyConsistentCurlResponse(s.ctx, testdefaults.CurlPodExecOpt,
[]curl.Option{
curl.WithHost(kubeutils.ServiceFQDN(metav1.ObjectMeta{
Name: gatewayProxyHost,
Namespace: s.testInstallation.Metadata.InstallNamespace,
})),
curl.WithHostHeader("example.com"),
curl.WithPort(gatewayProxyPort),
curl.WithPath(pathWithRouteDescriptor),
curl.Silent(),
},
&matchers.HttpResponse{
StatusCode: http.StatusOK,
},
5*time.Second, 30*time.Second,
)

s.EventuallyWithT(func(c *assert.CollectT) {
logs, err := s.testInstallation.Actions.Kubectl().GetContainerLogs(s.ctx, otelcolPod.ObjectMeta.GetNamespace(), otelcolPod.ObjectMeta.GetName())
assert.NoError(c, err, "can get otelcol logs")

fmt.Printf("logs: %s\n", logs)

assert.Regexp(c, `-> authority: Str\(test-authority\)`, logs)
//s.Fail("this test is not implemented yet")
}, time.Second*30, time.Second*3, "otelcol logs contain authority set in gateway")
}
1 change: 0 additions & 1 deletion test/kubernetes/e2e/features/tracing/testdata/gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ spec:
collectorUpstreamRef:
name: opentelemetry-collector
namespace: default

146 changes: 22 additions & 124 deletions test/kubernetes/e2e/features/tracing/testdata/setup-otelcol.yaml
Original file line number Diff line number Diff line change
@@ -1,93 +1,3 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: otel-agent-conf
labels:
app: opentelemetry
component: otel-agent-conf
data:
otel-agent-config: |
receivers:
otlp:
protocols:
grpc:
http:
exporters:
otlp:
endpoint: "otel-collector.default:4317"
tls:
insecure: true
sending_queue:
num_consumers: 4
queue_size: 100
retry_on_failure:
enabled: true
processors:
batch:
memory_limiter:
# 80% of maximum memory up to 2G
limit_mib: 400
# 25% of limit up to 2G
spike_limit_mib: 100
check_interval: 5s
extensions:
zpages: {}
memory_ballast:
# Memory Ballast size should be max 1/3 to 1/2 of memory.
size_mib: 165
service:
extensions: [zpages, memory_ballast]
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlp]
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: otel-agent
labels:
app: opentelemetry
component: otel-agent
spec:
selector:
matchLabels:
app: opentelemetry
component: otel-agent
template:
metadata:
labels:
app: opentelemetry
component: otel-agent
spec:
containers:
- command:
- "/otelcol"
- "--config=/conf/otel-agent-config.yaml"
image: otel/opentelemetry-collector:0.68.0
name: otel-agent
resources:
limits:
cpu: 500m
memory: 500Mi
requests:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 55679 # ZPages endpoint.
- containerPort: 4317 # Default OpenTelemetry receiver port.
- containerPort: 8888 # Metrics.
volumeMounts:
- name: otel-agent-config-vol
mountPath: /conf
volumes:
- configMap:
name: otel-agent-conf
items:
- key: otel-agent-config
path: otel-agent-config.yaml
name: otel-agent-config-vol
---
apiVersion: v1
kind: ConfigMap
Expand All @@ -102,38 +12,31 @@ data:
otlp:
protocols:
grpc:
include_metadata: true
endpoint: 0.0.0.0:4317
http:
include_metadata: true
endpoint: 0.0.0.0:4318
processors:
batch:
memory_limiter:
# 80% of maximum memory up to 2G
limit_mib: 1500
# 25% of limit up to 2G
spike_limit_mib: 512
check_interval: 5s
extensions:
zpages: {}
memory_ballast:
# Memory Ballast size should be max 1/3 to 1/2 of memory.
size_mib: 683
attributes:
actions:
- key: authority
action: insert
from_context: metadata.:authority
exporters:
logging:
loglevel: debug
zipkin:
endpoint: "http://zipkin:9411/api/v2/spans"
tls:
insecure: true
debug:
verbosity: detailed
service:
extensions: [zpages, memory_ballast]
extensions: []
pipelines:
metrics:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [logging]
processors: [attributes]
exporters: [debug]
traces:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [logging, zipkin]
processors: [attributes]
exporters: [debug]
---
apiVersion: v1
kind: Pod
Expand All @@ -146,9 +49,10 @@ metadata:
spec:
containers:
- command:
- "/otelcol"
- "--config=/conf/otel-collector-config.yaml"
image: otel/opentelemetry-collector:0.68.0
- "/otelcol-contrib"
- "--config"
- "/conf/otel-collector-config.yaml"
image: otel/opentelemetry-collector-contrib:0.116.1
name: otel-collector
resources:
limits:
Expand All @@ -158,12 +62,8 @@ spec:
cpu: 200m
memory: 400Mi
ports: # Comment out ports for platforms as needed.
- containerPort: 55679 # Default endpoint for ZPages.
- containerPort: 4317 # Default endpoint for OpenTelemetry receiver.
- containerPort: 14250 # Default endpoint for Jaeger gRPC receiver.
- containerPort: 14268 # Default endpoint for Jaeger HTTP receiver.
- containerPort: 9411 # Default endpoint for Zipkin receiver.
- containerPort: 8888 # Default endpoint for querying metrics.
- containerPort: 4317 # Default gRPC endpoint for OpenTelemetry receiver.
- containerPort: 4318 # Default http endpoint for OpenTelemetry receiver.
volumeMounts:
- name: otel-collector-config-vol
mountPath: /conf
Expand Down Expand Up @@ -193,7 +93,5 @@ spec:
port: 4318
protocol: TCP
targetPort: 4318
- name: metrics # Default endpoint for querying metrics.
port: 8888
selector:
app.kubernetes.io/name: otel-collector
9 changes: 5 additions & 4 deletions test/kubernetes/e2e/features/tracing/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ const (
)

var (
setupOtelcolManifest = filepath.Join(util.MustGetThisDir(), "testdata", "setup-otelcol.yaml")
tracingConfigManifest = filepath.Join(util.MustGetThisDir(), "testdata", "tracing.yaml")
gatewayConfigManifest = filepath.Join(util.MustGetThisDir(), "testdata", "gateway.yaml")
gatewayProxyServiceManifest = filepath.Join(util.MustGetThisDir(), "testdata", "gw-proxy-tracing-service.yaml")
setupOtelcolManifest = filepath.Join(util.MustGetThisDir(), "testdata", "setup-otelcol.yaml")
tracingConfigManifest = filepath.Join(util.MustGetThisDir(), "testdata", "tracing.yaml")
gatewayConfigManifest = filepath.Join(util.MustGetThisDir(), "testdata", "gateway.yaml")
gatewayAuthorityConfigManifest = filepath.Join(util.MustGetThisDir(), "testdata", "gateway-authority.yaml")
gatewayProxyServiceManifest = filepath.Join(util.MustGetThisDir(), "testdata", "gw-proxy-tracing-service.yaml")

otelcolPod = &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{Name: "otel-collector", Namespace: "default"},
Expand Down

0 comments on commit 435f15d

Please sign in to comment.