Skip to content

Commit 324b2fb

Browse files
authored
T-8810: container metadata for logs/metrics/spans (#12)
1 parent 84558ca commit 324b2fb

File tree

12 files changed

+660
-10
lines changed

12 files changed

+660
-10
lines changed

.github/workflows/docker-build.yml

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
- main
1212

1313
jobs:
14-
build:
14+
build-collector:
1515
runs-on: ubuntu-latest
1616
permissions:
1717
contents: read
@@ -80,4 +80,63 @@ jobs:
8080
labels: ${{ steps.meta.outputs.labels }}
8181
build-args: |
8282
COLLECTOR_VERSION=${{ github.ref_name }}
83+
84+
build-beyla:
85+
runs-on: ubuntu-latest
86+
permissions:
87+
contents: read
88+
packages: write
89+
90+
steps:
91+
- name: Checkout code
92+
uses: actions/checkout@v4
93+
with:
94+
submodules: true
8395

96+
- name: Determine repository and tags
97+
id: repo
98+
run: |
99+
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
100+
# Tagged versions go to public repo
101+
echo "repository=betterstack/collector-beyla" >> $GITHUB_OUTPUT
102+
echo "push=true" >> $GITHUB_OUTPUT
103+
else
104+
# Everything else goes to private repo
105+
echo "repository=betterstack/collector-beyla-private" >> $GITHUB_OUTPUT
106+
echo "push=true" >> $GITHUB_OUTPUT
107+
fi
108+
109+
- name: Set up Docker metadata
110+
id: meta
111+
uses: docker/metadata-action@v5
112+
with:
113+
images: ${{ steps.repo.outputs.repository }}
114+
tags: |
115+
# For version tags, tag as version and latest (public repo)
116+
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
117+
type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
118+
# For main branch, tag as main-sha (private repo)
119+
type=raw,value=main-sha-{{sha}},enable=${{ github.ref == 'refs/heads/main' }}
120+
# For pull requests, tag as pr-number-sha (private repo)
121+
type=raw,value=pr-${{ github.event.pull_request.number }}-sha-{{sha}},enable=${{ github.event_name == 'pull_request' }}
122+
123+
- name: Log in to Docker Hub
124+
uses: docker/login-action@v3
125+
with:
126+
username: ${{ secrets.DOCKERHUB_USERNAME }}
127+
password: ${{ secrets.DOCKERHUB_TOKEN }}
128+
129+
- name: Set up Depot
130+
uses: depot/setup-action@v1
131+
132+
- name: Build and push Docker image
133+
uses: depot/build-push-action@v1
134+
with:
135+
project: ${{ secrets.DEPOT_PROJECT_ID }}
136+
token: ${{ secrets.DEPOT_API_TOKEN }}
137+
context: .
138+
file: Dockerfile.beyla
139+
platforms: linux/amd64,linux/arm64
140+
push: ${{ steps.repo.outputs.push }}
141+
tags: ${{ steps.meta.outputs.tags }}
142+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ RUN mkdir -p /versions/0-default \
4646
# Set environment variables
4747
ENV BASE_URL=https://telemetry.betterstack.com
4848
ENV CLUSTER_COLLECTOR=false
49-
ENV COLLECTOR_VERSION=1.0.3
49+
ENV COLLECTOR_VERSION=1.0.4
5050
ENV VECTOR_VERSION=0.47.0
5151
ENV BEYLA_VERSION=2.2.4
5252
ENV CLUSTER_AGENT_VERSION=1.2.4

Dockerfile.beyla

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Build dockerprobe
2+
FROM golang:1.24.4-alpine3.22 AS dockerprobe-builder
3+
WORKDIR /src
4+
COPY dockerprobe/go.mod dockerprobe/go.sum ./
5+
RUN go mod download
6+
COPY dockerprobe/main.go ./
7+
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags='-s -w' -o /bin/dockerprobe .
8+
9+
# Get Beyla files from official image
10+
FROM grafana/beyla:2.2.4 AS beyla-source
11+
12+
# Final stage - Alpine based
13+
FROM alpine:3.22
14+
15+
# Install supervisor and ca-certificates
16+
RUN apk add --no-cache supervisor ca-certificates
17+
18+
# Create necessary directories
19+
RUN mkdir -p /etc/supervisor/conf.d /var/log/supervisor /enrichment
20+
21+
# Copy Beyla files from official image and set permissions
22+
COPY --from=beyla-source --chmod=755 /beyla /usr/local/bin/beyla
23+
COPY --from=beyla-source /LICENSE /LICENSE
24+
COPY --from=beyla-source /NOTICE /NOTICE
25+
COPY --from=beyla-source /third_party_licenses.csv /third_party_licenses.csv
26+
27+
# Copy dockerprobe binary with permissions
28+
COPY --from=dockerprobe-builder --chmod=755 /bin/dockerprobe /usr/local/bin/dockerprobe
29+
30+
# Copy configuration files
31+
COPY beyla/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
32+
COPY --chmod=755 beyla/entrypoint.sh /entrypoint.sh
33+
34+
# Copy Beyla configuration
35+
COPY beyla.yaml /etc/beyla/beyla.yaml
36+
37+
# Default command
38+
CMD ["/entrypoint.sh"]

beyla/entrypoint.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
# Enable dockerprobe if ENABLE_DOCKERPROBE is set to true or 1
4+
if [ "${ENABLE_DOCKERPROBE}" = "true" ] || [ "${ENABLE_DOCKERPROBE}" = "1" ]; then
5+
echo "Enabling dockerprobe (ENABLE_DOCKERPROBE=${ENABLE_DOCKERPROBE})"
6+
# Replace autostart=false with autostart=true for dockerprobe
7+
sed -i '/\[program:dockerprobe\]/,/^\[/ s/autostart=false/autostart=true/' /etc/supervisor/supervisord.conf
8+
else
9+
echo "Dockerprobe disabled (ENABLE_DOCKERPROBE=${ENABLE_DOCKERPROBE})"
10+
fi
11+
12+
# Start supervisord
13+
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf

beyla/supervisord.conf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[supervisord]
2+
nodaemon=true
3+
logfile=/var/log/supervisor/supervisord.log
4+
loglevel=info
5+
6+
[program:beyla]
7+
command=/usr/local/bin/beyla
8+
autostart=true
9+
autorestart=true
10+
stdout_logfile=/var/log/supervisor/beyla.out.log
11+
stderr_logfile=/var/log/supervisor/beyla.err.log
12+
environment=PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
13+
14+
# Runs the `dockerprobe` binary to produce a CSV file associating process IDs to container IDs and names.
15+
# This CSV file is shared from the Beyla container to the Collector container via the docker-metadata volume mounted at /enrichment.
16+
# Sources for the `dockerprobe` binary are located in the `dockerprobe` directory.
17+
#
18+
# autostart disabled by default here; enabled in entrypoint.sh if ENABLE_DOCKERPROBE is set to true or 1
19+
# (for disabling in e.g. Kubernetes, or when not desired). ENABLE_DOCKERPROBE is set to true by default in docker-compose.yml.
20+
[program:dockerprobe]
21+
autostart=false
22+
command=/usr/local/bin/dockerprobe
23+
autorestart=true
24+
stdout_logfile=/var/log/supervisor/dockerprobe.out.log
25+
stderr_logfile=/var/log/supervisor/dockerprobe.err.log
26+
environment=DOCKER_HOST="unix:///var/run/docker.sock",DOCKERPROBE_OUTPUT_PATH="/enrichment/docker-mappings.csv",DOCKERPROBE_INTERVAL="15"

docker-compose.seccomp.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ services:
2323
- /var/log:/host/var/log:ro
2424
# Collect Docker container logs
2525
- /var/lib/docker/containers:/host/var/lib/docker/containers:ro
26+
# dockerprobe running in the beyla container writes a map of PIDs->container IDs and names to this volume
27+
# Vector uses this file as an enrichment table to tag logs, metrics, and traces with container metadata.
28+
- docker-metadata:/enrichment:ro
2629
ports:
2730
# Bind to localhost only for security - Beyla will connect via host network
2831
- "127.0.0.1:34320:34320"
2932

3033
beyla:
31-
image: grafana/beyla:2.2.4
34+
build:
35+
context: .
36+
dockerfile: Dockerfile.beyla
37+
image: betterstack/collector-beyla:latest
3238
container_name: better-stack-beyla
3339
restart: always
3440
privileged: true
@@ -44,10 +50,22 @@ services:
4450
- BEYLA_BPF_TRACK_REQUEST_HEADERS=true
4551
- BEYLA_METRICS_INTERVAL=15s
4652
- BEYLA_CONFIG_PATH=/etc/beyla/beyla.yaml
53+
# Enable dockerprobe by default (set to false to disable)
54+
- ENABLE_DOCKERPROBE=${ENABLE_DOCKERPROBE:-true}
4755
volumes:
48-
- ./beyla.yaml:/etc/beyla/beyla.yaml:ro
4956
- /sys/kernel/tracing:/sys/kernel/tracing:rw
5057
- /sys/kernel/debug:/sys/kernel/debug:rw
5158
- /sys/kernel/security:/sys/kernel/security:ro
59+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
60+
# Docker socket for dockerprobe
61+
- /var/run/docker.sock:/var/run/docker.sock:ro
62+
# dockerprobe running in the beyla container writes a map of PIDs->container IDs and names to this volume
63+
# Vector uses this file as an enrichment table to tag logs, metrics, and traces with container metadata.
64+
- docker-metadata:/enrichment:rw
5265
depends_on:
5366
- collector
67+
68+
volumes:
69+
docker-metadata:
70+
71+

docker-compose.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@ services:
2121
- /var/log:/host/var/log:ro
2222
# Collect Docker container logs
2323
- /var/lib/docker/containers:/host/var/lib/docker/containers:ro
24+
# dockerprobe running in the beyla container writes a map of PIDs->container IDs and names to this volume
25+
# Vector uses this file as an enrichment table to tag logs, metrics, and traces with container metadata.
26+
- docker-metadata:/enrichment:ro
2427
ports:
2528
# Bind to localhost only for security - Beyla will connect via host network
2629
- "127.0.0.1:34320:34320"
2730

2831
beyla:
29-
image: grafana/beyla:2.2.4
32+
build:
33+
context: .
34+
dockerfile: Dockerfile.beyla
35+
image: betterstack/collector-beyla:latest
3036
container_name: better-stack-beyla
3137
restart: always
3238
privileged: true
@@ -42,10 +48,20 @@ services:
4248
- BEYLA_BPF_TRACK_REQUEST_HEADERS=true
4349
- BEYLA_METRICS_INTERVAL=15s
4450
- BEYLA_CONFIG_PATH=/etc/beyla/beyla.yaml
51+
# Enable dockerprobe by default (set to false to disable)
52+
- ENABLE_DOCKERPROBE=${ENABLE_DOCKERPROBE:-true}
4553
volumes:
46-
- ./beyla.yaml:/etc/beyla/beyla.yaml:ro
4754
- /sys/kernel/tracing:/sys/kernel/tracing:rw
4855
- /sys/kernel/debug:/sys/kernel/debug:rw
4956
- /sys/kernel/security:/sys/kernel/security:ro
57+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
58+
# Docker socket for dockerprobe
59+
- /var/run/docker.sock:/var/run/docker.sock:ro
60+
# dockerprobe running in the beyla container writes a map of PIDs->container IDs and names to this volume
61+
# Vector uses this file as an enrichment table to tag logs, metrics, and traces with container metadata.
62+
- docker-metadata:/enrichment:rw
5063
depends_on:
5164
- collector
65+
66+
volumes:
67+
docker-metadata:

dockerprobe/go.mod

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module dockerprobe
2+
3+
go 1.24.4
4+
5+
require github.com/docker/docker v27.5.0+incompatible
6+
7+
require (
8+
github.com/Microsoft/go-winio v0.6.2 // indirect
9+
github.com/containerd/log v0.1.0 // indirect
10+
github.com/distribution/reference v0.6.0 // indirect
11+
github.com/docker/go-connections v0.5.0 // indirect
12+
github.com/docker/go-units v0.5.0 // indirect
13+
github.com/felixge/httpsnoop v1.0.4 // indirect
14+
github.com/go-logr/logr v1.4.2 // indirect
15+
github.com/go-logr/stdr v1.2.2 // indirect
16+
github.com/gogo/protobuf v1.3.2 // indirect
17+
github.com/moby/docker-image-spec v1.3.1 // indirect
18+
github.com/moby/term v0.5.0 // indirect
19+
github.com/morikuni/aec v1.0.0 // indirect
20+
github.com/opencontainers/go-digest v1.0.0 // indirect
21+
github.com/opencontainers/image-spec v1.1.0 // indirect
22+
github.com/pkg/errors v0.9.1 // indirect
23+
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
24+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0 // indirect
25+
go.opentelemetry.io/otel v1.33.0 // indirect
26+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.33.0 // indirect
27+
go.opentelemetry.io/otel/metric v1.33.0 // indirect
28+
go.opentelemetry.io/otel/sdk v1.33.0 // indirect
29+
go.opentelemetry.io/otel/trace v1.33.0 // indirect
30+
golang.org/x/sys v0.29.0 // indirect
31+
golang.org/x/time v0.12.0 // indirect
32+
gotest.tools/v3 v3.5.2 // indirect
33+
)

0 commit comments

Comments
 (0)