Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OTLP exporter TLS integration test #4732

Merged
merged 10 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
- uses: actions/checkout@v3

- name: Run OTLP Exporter docker-compose.integration
run: docker-compose --file=test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/docker-compose.yml --file=build/docker-compose.${{ matrix.version }}.yml --project-directory=. up --exit-code-from=tests --build
run: docker-compose --file=test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest/docker-compose.yml --file=build/docker-compose.${{ matrix.version }}.yml --project-directory=. up --exit-code-from=tests --build
4 changes: 2 additions & 2 deletions build/docker-compose.net6.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ services:
build:
args:
PUBLISH_FRAMEWORK: net6.0
TEST_SDK_VERSION: 6.0
BUILD_SDK_VERSION: 7.0
TEST_SDK_VERSION: "6.0"
BUILD_SDK_VERSION: "7.0"
4 changes: 2 additions & 2 deletions build/docker-compose.net7.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ services:
build:
args:
PUBLISH_FRAMEWORK: net7.0
TEST_SDK_VERSION: 7.0
BUILD_SDK_VERSION: 7.0
TEST_SDK_VERSION: "7.0"
BUILD_SDK_VERSION: "7.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Self-signed cert generated by integration test
otel-collector.crt
otel-collector.key
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Create a container for running the OpenTelemetry Collector integration tests.
# This should be run from the root of the repo:
# docker build --file test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/Dockerfile
# docker build --file test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest/Dockerfile

ARG BUILD_SDK_VERSION=7.0
ARG TEST_SDK_VERSION=7.0
Expand All @@ -16,4 +16,5 @@ RUN dotnet publish "OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests.csproj" -
FROM mcr.microsoft.com/dotnet/sdk:${TEST_SDK_VERSION} AS final
WORKDIR /test
COPY --from=build /drop .
ENTRYPOINT ["dotnet", "vstest", "OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests.dll", "--logger:console;verbosity=detailed"]

RUN apt-get update && apt-get install ca-certificates
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ public void Dispose()
[InlineData(OtlpExportProtocol.HttpProtobuf, ":4318/v1/traces", ExportProcessorType.Simple, false)]
[InlineData(OtlpExportProtocol.Grpc, ":4317", ExportProcessorType.Simple, true)]
[InlineData(OtlpExportProtocol.HttpProtobuf, ":4318/v1/traces", ExportProcessorType.Simple, true)]
[InlineData(OtlpExportProtocol.Grpc, ":5317", ExportProcessorType.Simple, true, "https")]
[InlineData(OtlpExportProtocol.HttpProtobuf, ":5318/v1/traces", ExportProcessorType.Simple, true, "https")]
[Trait("CategoryName", "CollectorIntegrationTests")]
[SkipUnlessEnvVarFoundTheory(CollectorHostnameEnvVarName)]
public void TraceExportResultIsSuccess(OtlpExportProtocol protocol, string endpoint, ExportProcessorType exportProcessorType, bool forceFlush)
public void TraceExportResultIsSuccess(OtlpExportProtocol protocol, string endpoint, ExportProcessorType exportProcessorType, bool forceFlush, string scheme = "http")
{
using EventWaitHandle handle = new ManualResetEvent(false);

var exporterOptions = new OtlpExporterOptions
{
Endpoint = new Uri($"http://{CollectorHostname}{endpoint}"),
Endpoint = new Uri($"{scheme}://{CollectorHostname}{endpoint}"),
Protocol = protocol,
ExportProcessorType = exportProcessorType,
BatchExportProcessorOptions = new()
Expand Down Expand Up @@ -133,15 +135,17 @@ public void TraceExportResultIsSuccess(OtlpExportProtocol protocol, string endpo
[InlineData(OtlpExportProtocol.HttpProtobuf, ":4318/v1/metrics", true, false)]
[InlineData(OtlpExportProtocol.Grpc, ":4317", true, true)]
[InlineData(OtlpExportProtocol.HttpProtobuf, ":4318/v1/metrics", true, true)]
[InlineData(OtlpExportProtocol.Grpc, ":5317", true, true, "https")]
[InlineData(OtlpExportProtocol.HttpProtobuf, ":5318/v1/metrics", true, true, "https")]
[Trait("CategoryName", "CollectorIntegrationTests")]
[SkipUnlessEnvVarFoundTheory(CollectorHostnameEnvVarName)]
public void MetricExportResultIsSuccess(OtlpExportProtocol protocol, string endpoint, bool useManualExport, bool forceFlush)
public void MetricExportResultIsSuccess(OtlpExportProtocol protocol, string endpoint, bool useManualExport, bool forceFlush, string scheme = "http")
{
using EventWaitHandle handle = new ManualResetEvent(false);

var exporterOptions = new OtlpExporterOptions
{
Endpoint = new Uri($"http://{CollectorHostname}{endpoint}"),
Endpoint = new Uri($"{scheme}://{CollectorHostname}{endpoint}"),
Protocol = protocol,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# Generate self-signed certificate for the collector
openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 \
-subj "/CN=otel-collector" \
-keyout /otel-collector.key -out /otel-collector.crt

# Copy the certificate and private key file to shared volume that the collector
# container and test container can access
cp /otel-collector.crt /otel-collector.key /cfg

chmod 644 /cfg/otel-collector.key

# The integration test is run via docker-compose with the --exit-code-from
# option. The --exit-code-from option implies --abort-on-container-exit
# which means when any container exits then all containers are stopped.
# Since the container running this script would be otherwise short-lived
# we sleep here. If the test does not finish within this time then the test
# container will be stopped and have a non-zero exit code.
sleep 300
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
# Starts an OpenTelemetry Collector and then runs the OTLP exporter integration tests.
# This should be run from the root of the repo:
# docker-compose --file=test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/docker-compose.yml --project-directory=. up --exit-code-from=tests --build
# docker-compose --file=test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest/docker-compose.yml --project-directory=. up --exit-code-from=tests --build

version: '3.7'

services:
create-cert:
image: mcr.microsoft.com/dotnet/sdk:7.0
volumes:
- ./test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest:/cfg
command: /cfg/create-cert.sh

otel-collector:
image: otel/opentelemetry-collector
volumes:
- ./test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests:/cfg
command: --config=/cfg/config.yaml
ports:
- "4317:4317"
- "4318:4318"
- ./test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest:/cfg
command: --config=/cfg/otel-collector-config.yaml
depends_on:
- create-cert

tests:
build:
context: .
dockerfile: ./test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/Dockerfile
command: --TestCaseFilter:CategoryName=CollectorIntegrationTests
dockerfile: ./test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest/Dockerfile
volumes:
- ./test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest:/cfg
command: /cfg/run-test.sh
environment:
- OTEL_COLLECTOR_HOSTNAME=otel-collector
- OTEL_MOCK_COLLECTOR_HOSTNAME=mock-otel-collector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,28 @@ receivers:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
otlp/tls:
protocols:
grpc:
endpoint: 0.0.0.0:5317
tls:
cert_file: /cfg/otel-collector.crt
key_file: /cfg/otel-collector.key
http:
endpoint: 0.0.0.0:5318
tls:
cert_file: /cfg/otel-collector.crt
key_file: /cfg/otel-collector.key

exporters:
logging:
loglevel: debug
verbosity: detailed

service:
pipelines:
traces:
receivers: [otlp]
receivers: [otlp, otlp/tls]
exporters: [logging]
metrics:
receivers: [otlp]
receivers: [otlp, otlp/tls]
exporters: [logging]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Trust the self-signed certificated used by the collector
cp /cfg/otel-collector.crt /usr/local/share/ca-certificates/
update-ca-certificates --verbose

dotnet test OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests.dll --TestCaseFilter:CategoryName=CollectorIntegrationTests --logger "console;verbosity=detailed"