From 6b307c63e93380bfc0cbe475cd7025331f7556ee Mon Sep 17 00:00:00 2001 From: Pankaj Kumar Date: Tue, 21 Oct 2025 16:51:16 +0530 Subject: [PATCH] chore: making otelcol collector for tailing in working state --- sidecar/otelcol/.goreleaser.yaml | 2 +- sidecar/otelcol/.otelcol-builder.yaml | 25 +++------ sidecar/otelcol/Dockerfile | 19 ++----- sidecar/otelcol/Makefile | 40 +++++++++---- sidecar/otelcol/examples/example1.log | 2 + sidecar/otelcol/examples/example2.log | 2 + .../examples/pod_with_tailing_sidecars.yaml | 56 +++++++++++++++++++ sidecar/otelcol/tests/test.sh | 9 +++ 8 files changed, 112 insertions(+), 43 deletions(-) create mode 100644 sidecar/otelcol/examples/example1.log create mode 100644 sidecar/otelcol/examples/example2.log create mode 100644 sidecar/otelcol/examples/pod_with_tailing_sidecars.yaml create mode 100755 sidecar/otelcol/tests/test.sh diff --git a/sidecar/otelcol/.goreleaser.yaml b/sidecar/otelcol/.goreleaser.yaml index 35aa7eb1..d279bad9 100644 --- a/sidecar/otelcol/.goreleaser.yaml +++ b/sidecar/otelcol/.goreleaser.yaml @@ -6,7 +6,7 @@ # yaml-language-server: $schema=https://goreleaser.com/static/schema.json # vim: set ts=2 sw=2 tw=0 fo=cnqoj -version: 1 +version: 2 project_name: otelcol-sidecar diff --git a/sidecar/otelcol/.otelcol-builder.yaml b/sidecar/otelcol/.otelcol-builder.yaml index c6ab175a..18dded6d 100644 --- a/sidecar/otelcol/.otelcol-builder.yaml +++ b/sidecar/otelcol/.otelcol-builder.yaml @@ -4,30 +4,23 @@ dist: # the module name for the new distribution, following Go mod conventions. Optional, but recommended. module: github.com/SumoLogic/tailing-sidecar/sidecar # the OpenTelemetry Collector version to use as base for the distribution. - otelcol_version: 0.90.1 + otelcol_version: 0.137.0 # the path to write the output (sources and binary). output_path: ./cmd exporters: - - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/fileexporter v0.90.1 + - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/fileexporter v0.137.0 # Note: These components aren't strictly necessary, but they don't measurably increase the binary size processors: - - gomod: go.opentelemetry.io/collector/processor/batchprocessor v0.90.1 - - gomod: go.opentelemetry.io/collector/processor/memorylimiterprocessor v0.90.1 - - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/groupbyattrsprocessor v0.90.1 + - gomod: go.opentelemetry.io/collector/processor/batchprocessor v0.137.0 + - gomod: go.opentelemetry.io/collector/processor/memorylimiterprocessor v0.137.0 + - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/groupbyattrsprocessor v0.137.0 receivers: - - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filelogreceiver v0.90.1 + - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filelogreceiver v0.137.0 extensions: - - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension v0.90.1 - - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage v0.90.1 - import: github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage/filestorage - - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding v0.90.1 - import: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/textencodingextension - -# Replacement paths are relative to the output_path (location of source files) -replaces: - - github.com/open-telemetry/opentelemetry-collector-contrib/exporter/fileexporter => github.com/SumoLogic/opentelemetry-collector-contrib/exporter/fileexporter 687035f9f64c57e96d74d523b398f526e698f9e4 - - github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/textencodingextension => github.com/SumoLogic/opentelemetry-collector-contrib/extension/encoding/textencodingextension 687035f9f64c57e96d74d523b398f526e698f9e4 + - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension v0.137.0 + - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage/filestorage v0.137.0 + - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/textencodingextension v0.137.0 diff --git a/sidecar/otelcol/Dockerfile b/sidecar/otelcol/Dockerfile index e369bacc..37da808a 100644 --- a/sidecar/otelcol/Dockerfile +++ b/sidecar/otelcol/Dockerfile @@ -1,21 +1,10 @@ -# Prepare the necessary directories in an Alpine container where we have the necessary tooling -FROM alpine:3.21.3 AS directories -RUN mkdir /etc/otel/ -RUN mkdir /var/lib/otc -RUN touch /var/log/otelcol.log +FROM alpine:3.21.3 -FROM scratch -ARG USER_UID=10001 -USER ${USER_UID} - -COPY --from=directories --chown=${USER_UID}:${USER_UID} /etc/otel/ /etc/otel/ -COPY --from=directories --chown=${USER_UID}:${USER_UID} /var/lib/otc /var/lib/otc -COPY --from=directories --chown=${USER_UID}:${USER_UID} /var/log/otelcol.log /var/log/otelcol.log - -# copy the default tailing-sidecar configuration file +RUN mkdir -p /etc/otel /var/lib/otc /var/log COPY ./config.yaml /etc/otel/config.yaml +COPY dist/otelcol-sidecar_linux_arm64_*/otelcol-sidecar /otelcol +RUN chmod +x /otelcol -COPY otelcol-sidecar /otelcol ENTRYPOINT ["/otelcol"] CMD ["--config", "/etc/otel/config.yaml"] diff --git a/sidecar/otelcol/Makefile b/sidecar/otelcol/Makefile index 5786a265..664eafac 100644 --- a/sidecar/otelcol/Makefile +++ b/sidecar/otelcol/Makefile @@ -1,17 +1,18 @@ BINARY_NAME ?= otelcol-sidecar -OTELCOL_VERSION ?= 0.90.1 -BUILDER_REPO ?= github.com/open-telemetry/opentelemetry-collector +OTELCOL_VERSION ?= 0.137.0 +BUILDER_REPO ?= github.com/open-telemetry/opentelemetry-collector-releases GO ?= go OS ?= $(shell uname -s | tr A-Z a-z) ARCH ?= $(shell uname -m | sed s/aarch64/arm64/ | sed s/x86_64/amd64/) LOCALBIN ?= $(shell pwd)/bin -GORELEASER ?= $(LOCALBIN)/goreleaser BUILDER_BIN_NAME ?= opentelemetry-collector-builder$(BUILDER_BIN_EXT) BUILDER_BIN_PATH ?= $(LOCALBIN) BUILDER=$(BUILDER_BIN_PATH)/$(BUILDER_BIN_NAME) +GORELEASER ?= $(BUILDER_BIN_PATH)/goreleaser + INSTALLED_VERSION := $(shell $(BUILDER) version 2>&1) @@ -39,18 +40,37 @@ install-builder: .PHONY: install-goreleaser install-goreleaser: - $(call go-get-tool,$(GORELEASER),github.com/goreleaser/goreleaser,latest) + @echo "Installing GoReleaser..." + @mkdir -p $(BUILDER_BIN_PATH) + @VERSION=$$(curl -sf https://goreleaser.com/static/latest); \ + OS=$$(uname -s ); \ + ARCH=$$(uname -m); \ + echo "Detected OS: $$OS"; \ + echo "Detected ARCH: $$ARCH"; \ + TAR_FILE="goreleaser_${OS}_${ARCH}.tar.gz";\ + RELEASES_URL="https://github.com/goreleaser/goreleaser/releases"; \ + echo "Downloading GoReleaser $$VERSION..."; \ + echo "Download URL: $$RELEASES_URL/download/$$VERSION/$$TAR_FILE";\ + curl -sfLO "$$RELEASES_URL/download/$$VERSION/$$TAR_FILE"; \ + tar -xzf "$$TAR_FILE" -C $(BUILDER_BIN_PATH) ; \ + rm "$$TAR_FILE"; \ + echo "GoReleaser binary installed at $(BUILDER_BIN_PATH)/goreleaser" + .PHONY: ensure-correct-builder-version ensure-correct-builder-version: -ifneq ($(lastword $(INSTALLED_VERSION)),$(OTELCOL_VERSION)) - @$(error Installed opentelemetry-collector-builder version \ +ifeq (,$(findstring $(OTELCOL_VERSION),$(lastword $(INSTALLED_VERSION)))) + @$(error Installed ocb version \ "$(INSTALLED_VERSION)" \ - does not match the requested "$(OTELCOL_VERSION)" \ - Please check if "$(BUILDER_BIN_PATH)" can be found in your PATH \ - and if not, then install it using 'make install-builder' from otelcolbuilder's directory\ + does not match the requested "$(OTELCOL_VERSION)". The correct version of \ + ocb can be installed by running 'make install-builder' from the \ + otelcolbuilder directory.\ ) +else + @printf "Installed ocb (%s) is at the correct version %s\n" \ + "$(shell type $(OCB) | cut -d' ' -f 3)" \ + "$(INSTALLED_VERSION)" endif .PHONY: build @@ -80,8 +100,6 @@ build-test-image: build .PHONY: generate-sources generate-sources: $(BUILDER) \ - --go $(GO) \ - --version "$(VERSION)" \ --config .otelcol-builder.yaml \ --skip-compilation=true diff --git a/sidecar/otelcol/examples/example1.log b/sidecar/otelcol/examples/example1.log new file mode 100644 index 00000000..d59ebe60 --- /dev/null +++ b/sidecar/otelcol/examples/example1.log @@ -0,0 +1,2 @@ +This is the first line of example1.log +This is the second line of example1.log diff --git a/sidecar/otelcol/examples/example2.log b/sidecar/otelcol/examples/example2.log new file mode 100644 index 00000000..b02d93e8 --- /dev/null +++ b/sidecar/otelcol/examples/example2.log @@ -0,0 +1,2 @@ +This is the first line of example2.log +This is the second line of example2.log diff --git a/sidecar/otelcol/examples/pod_with_tailing_sidecars.yaml b/sidecar/otelcol/examples/pod_with_tailing_sidecars.yaml new file mode 100644 index 00000000..cc7acf46 --- /dev/null +++ b/sidecar/otelcol/examples/pod_with_tailing_sidecars.yaml @@ -0,0 +1,56 @@ +apiVersion: v1 +kind: Pod +metadata: + name: example-with-otelcol-tailing-sidecars +spec: + containers: + - name: count + image: busybox + args: + - /bin/sh + - -c + - > + i=0; + while true; + do + echo "example1: $i $(date)" >> /var/log/example1.log; + echo "example2: $i $(date)" >> /var/log/example2.log; + i=$((i+1)); + sleep 1; + done + volumeMounts: + - name: varlog + mountPath: /var/log + - name: sidecar1 + image: otel-side-car:latest + imagePullPolicy: Never + env: + - name: PATH_TO_TAIL + value: /var/log/example1.log + volumeMounts: + - name: varlog + mountPath: /var/log + - name: volume-sidecar-1 + mountPath: /tailing-sidecar/var + - name: sidecar2 + image: otel-side-car:latest + imagePullPolicy: Never + env: + - name: PATH_TO_TAIL + value: /var/log/example2.log + volumeMounts: + - name: varlog + mountPath: /var/log + - name: volume-sidecar-2 + mountPath: /tailing-sidecar/var + volumes: + - name: varlog + emptyDir: {} + - name: volume-sidecar-1 + hostPath: + path: /var/log/sidecar1 + type: DirectoryOrCreate + - name: volume-sidecar-2 + hostPath: + path: /var/log/sidecar2 + type: DirectoryOrCreate diff --git a/sidecar/otelcol/tests/test.sh b/sidecar/otelcol/tests/test.sh new file mode 100755 index 00000000..fc91e859 --- /dev/null +++ b/sidecar/otelcol/tests/test.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -e + +[[ $(kubectl logs --tail 5 example-with-otelcol-tailing-sidecars sidecar1 | grep example1 | wc -l) -ne 5 ]] && exit 1 +[[ $(kubectl logs --tail 5 example-with-otelcol-tailing-sidecars sidecar2 | grep example2 | wc -l) -ne 5 ]] && exit 1 + +echo "ok" +exit 0