Skip to content

Commit 05d74aa

Browse files
Stress: build our own custom otel collector (#7900)
Build our own custom otel distribution using their official `otb` tool. It reduces the amount of code significantly by cutting it down to azure monitor and removing all other contrib components. As a bonus we can also control the Docker images used, which is helpful for other things.
1 parent 2d7823a commit 05d74aa

6 files changed

Lines changed: 55 additions & 9 deletions

File tree

tools/stress-cluster/services/otelcollector/Dockerfile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
FROM mcr.microsoft.com/oss/otel/opentelemetry-collector-contrib:0.94.0 as otel
1+
FROM mcr.microsoft.com/oss/go/microsoft/golang:1.21 as build
2+
RUN apt update -y && apt upgrade -y && apt install -y build-essential git
23

3-
FROM busybox:latest as busybox
4-
COPY --from=otel / /
5-
ADD ./otel-collector-config.yml /otel-collector-config.yml
4+
# this lets us build a custom otel-collector image, with a minimal set of
5+
# adapters, etc...
6+
RUN go install go.opentelemetry.io/collector/cmd/builder@latest
7+
COPY ./otel-builder.yml /otel-builder.yml
8+
# builds to /tmp/dist
9+
RUN builder --config=/otel-builder.yml
10+
11+
# this is the actual image we'll upload - it's got a shell so we can
12+
# run startup.sh but is otherwise pristine.
13+
FROM mcr.microsoft.com/cbl-mariner/busybox:2.0
14+
COPY --from=build /tmp/dist/otelcol-custom /otelcol-custom
15+
COPY ./otel-collector-config.yml /otel-collector-config.yml
616
ADD ./startup.sh /startup.sh
717

818
EXPOSE 4317
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# OpenTelemetry custom distro for stress testing
2+
3+
This `Dockerfile` builds the image we use for our OpenTelemetry collector in the stress testing cluster.
4+
5+
It includes only the Azure Monitor and 'debug' exporters, which shrinks it down quite a bit and uses only mariner-based images, for both building and for the final app image.
6+
7+
To test this out locally:
8+
9+
1. Create a .env file that looks like this:
10+
11+
```bash
12+
# make sure you bring in the quotes
13+
APPLICATIONINSIGHTS_CONNECTION_STRING='<appinsights connection string from the Azure portal>'
14+
```
15+
16+
2. Run ./localtest.sh
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#!/bin/bash
22

3-
docker build -t oteltest .
3+
set -ex
4+
5+
docker build --no-cache -t oteltest .
6+
47
docker run -it \
58
-e ENV_FILE=/.env \
69
-v `pwd`/.env:/.env \
10+
-P \
711
oteltest
812

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This is used as an input to the `ocb` app that lets you build a customized OpenTelemetry collector,
2+
# as described here: https://opentelemetry.io/docs/collector/custom-collector/
3+
dist:
4+
name: otelcol-custom
5+
description: Local OpenTelemetry Collector binary
6+
output_path: /tmp/dist
7+
otelcol_version: 0.96.0
8+
exporters:
9+
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/azuremonitorexporter v0.96.0
10+
- gomod: go.opentelemetry.io/collector/exporter/debugexporter v0.96.0
11+
12+
receivers:
13+
- gomod: go.opentelemetry.io/collector/receiver/otlpreceiver v0.96.0
14+
15+
processors:
16+
- gomod: go.opentelemetry.io/collector/processor/batchprocessor v0.96.0

tools/stress-cluster/services/otelcollector/otel-collector-config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ service:
1111
traces:
1212
receivers: [otlp]
1313
processors: [batch]
14-
exporters: [logging, azuremonitor]
14+
exporters: [debug, azuremonitor]
1515
metrics:
1616
receivers: [otlp]
1717
processors: [batch]
1818
exporters: [azuremonitor]
1919
logs:
2020
receivers: [otlp]
2121
processors: [batch]
22-
exporters: [logging, azuremonitor]
22+
exporters: [debug, azuremonitor]
2323

2424
exporters:
25-
logging:
25+
debug:
2626
verbosity: "${env:OTEL_LOG_LEVEL}"
2727
azuremonitor:
2828
connection_string: "${env:APPLICATIONINSIGHTS_CONNECTION_STRING}"

tools/stress-cluster/services/otelcollector/startup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ set -ex
44

55
source $ENV_FILE
66
export APPLICATIONINSIGHTS_CONNECTION_STRING
7-
/otelcol-contrib --config otel-collector-config.yml $@
7+
/otelcol-custom --config otel-collector-config.yml $@

0 commit comments

Comments
 (0)