Skip to content

Commit

Permalink
Merge pull request #4 from tosuke-homelab/otelcol
Browse files Browse the repository at this point in the history
Add OpenTelemetry Collector
  • Loading branch information
tosuke authored Apr 1, 2024
2 parents 42c93c3 + 715f388 commit ad2f941
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/otelcol.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: OpenTelemtry Collector

on:
push:
branches: [ "main" ]
paths:
- otelcol/**
- .github/workflows/**
pull_request:
paths:
- otelcol/**
- .github/workflows/**

jobs:
earthly:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
FORCE_COLOR: 1
EARTHLY_CI: true
EARTHLY_REMOTE_CACHE: ghcr.io/${{ github.repository_owner }}/otelcol:cache
IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/otelcol
steps:
- uses: earthly/actions-setup@v1
with:
version: v0.8.0
- uses: docker/setup-qemu-action@v3
- name: Login to ghcr.io
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/checkout@v4
- name: Build otelcol for home router
run: earthly --push ./otelcol/router+all --IMAGE_NAME="${IMAGE_NAME}"

1 change: 1 addition & 0 deletions otelcol/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin/
81 changes: 81 additions & 0 deletions otelcol/Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
VERSION 0.8

ARG --global IMAGE_NAME = otelcol
ARG --global BASE_DIR
ARG --global TAG_PREFIX

all:
BUILD +test-all-platforms
BUILD +build-image-all-platforms

build-image-all-platforms:
BUILD --platform linux/amd64 --platform linux/arm64 +build-image

test-all-platforms:
BUILD --platform linux/amd64 --platform linux/arm64 +test

build-image:
ARG EARTHLY_GIT_BRANCH
ARG EARTHLY_GIT_SHORT_HASH
ARG NATIVEPLATFORM
FROM --platform=$NATIVEPLATFORM +tools
BUILD +image --TAG="${TAG_PREFIX}${EARTHLY_GIT_SHORT_HASH}"
IF [ "${EARTHLY_GIT_BRANCH}" = "main" ]
BUILD +image --TAG="${TAG_PREFIX}latest"
END

test:
FROM debian:bullseye-slim
COPY --chmod 644 "${BASE_DIR}config.yaml" /etc/otelcol/config.yaml
COPY +bin/otelcol /otelcol
RUN /otelcol validate --config=file:/etc/otelcol/config.yaml

tools:
FROM golang:1.22
ENV GOMODCACHE /go/pkg/mod
ENV GOCACHE /go-cache
RUN --mount=type=cache,sharing=locked,target=/go/mod/cache/ --mount=type=cache,target=/go-cache/ \
go install go.opentelemetry.io/collector/cmd/builder@v0.97.0 && \
go install github.com/mikefarah/yq/v4@v4.43.1
SAVE ARTIFACT /go/bin/builder builder AS LOCAL bin/builder
SAVE IMAGE --cache-hint

otel-modules:
FROM +tools
WORKDIR /work
COPY "${BASE_DIR}manifest.yaml" /work/manifest.yaml
RUN --mount=type=cache,sharing=locked,target=/go/mod/cache/ \
builder --config /work/manifest.yaml --skip-compilation

bin:
ARG TARGETOS
ARG TARGETARCH
ARG NATIVEPLATFORM
FROM --platform=$NATIVEPLATFORM +otel-modules
RUN --mount=type=cache,target=/go-cache/ \
CGO_ENABLED=0 GOARCH=${TARGETARCH} GOOS=${TARGETOS} builder \
--skip-generate --skip-get-modules \
--config /work/manifest.yaml
SAVE ARTIFACT /work/build/otelcol otelcol AS LOCAL bin/otelcol

image:
ARG EARTHLY_GIT_ORIGIN_URL
ARG EARTHLY_GIT_HASH
ARG NATIVEPLATFORM
ARG --required TAG

FROM --platform=$NATIVEPLATFORM +tools
WORKDIR /work
COPY "${BASE_DIR}manifest.yaml" /work/manifest.yaml
LET description = $(yq '.dist.description' /work/manifest.yaml)

FROM gcr.io/distroless/static:nonroot
LABEL org.opencontainers.image.src="https://github.com/tosuke-homelab/containers"
LABEL org.opencontainers.image.revision="${EARTHLY_GIT_HASH}"
LABEL org.opencontainers.image.description="${description}"
COPY --chmod 644 "${BASE_DIR}config.yaml" /etc/otelcol/config.yaml
COPY --chmod 755 +bin/otelcol /otelcol
ENTRYPOINT ["/otelcol"]
CMD ["--config", "file:/etc/otelcol/config.yaml"]
SAVE IMAGE --push "${IMAGE_NAME}:${TAG}"

12 changes: 12 additions & 0 deletions otelcol/router/Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
VERSION 0.8

IMPORT ../ AS common

ARG --global BASE_DIR = ./router/
ARG --global TAG_PREFIX = router-

all:
BUILD --pass-args common+all

test:
BUILD --pass-args common+test
45 changes: 45 additions & 0 deletions otelcol/router/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
extensions:
zpages:
endpoint: 0.0.0.0:55679

receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
loki:
protocols:
http:
endpoint: 0.0.0.0:3500
grpc:
endpoint: 0.0.0.0:3600
use_incoming_timestamp: true
syslog/bsd:
protocol: rfc3164
udp:
listen_address: 0.0.0.0:514

processors:
batch:

exporters:
debug:
verbosity: detailed

service:
extensions: [zpages]
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [debug]
metrics:
receivers: [otlp]
processors: [batch]
exporters: [debug]
logs:
receivers: [otlp, loki, syslog/bsd]
processors: [batch]
exporters: [debug]
26 changes: 26 additions & 0 deletions otelcol/router/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
dist:
name: otelcol
description: OpenTelemetry Collector for network facilities
output_path: ./build
otelcol_version: 0.97.0
debug_compilation: false

receivers:
- gomod: go.opentelemetry.io/collector/receiver/otlpreceiver v0.97.0
# - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusremotewritereceiver v0.97.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/lokireceiver v0.97.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/syslogreceiver v0.97.0

exporters:
- gomod: go.opentelemetry.io/collector/exporter/debugexporter v0.97.0
- gomod: go.opentelemetry.io/collector/exporter/otlpexporter v0.97.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/lokiexporter v0.97.0

extensions:
- gomod: go.opentelemetry.io/collector/extension/zpagesextension v0.97.0

processors:
- gomod: go.opentelemetry.io/collector/processor/batchprocessor v0.97.0

replaces:
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusremotewritereceiver => github.com/tosuke-lab/opentelemetry-collector-contrib-prometheusremotewrite/receiver/prometheusremotewritereceiver 909646fa7bdfa1a233c4201e4620fdb13a966f7b

0 comments on commit ad2f941

Please sign in to comment.