Skip to content
Draft
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 sidecar/otelcol/.goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 9 additions & 16 deletions sidecar/otelcol/.otelcol-builder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 4 additions & 15 deletions sidecar/otelcol/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
40 changes: 29 additions & 11 deletions sidecar/otelcol/Makefile
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

2 changes: 2 additions & 0 deletions sidecar/otelcol/examples/example1.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This is the first line of example1.log
This is the second line of example1.log
2 changes: 2 additions & 0 deletions sidecar/otelcol/examples/example2.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This is the first line of example2.log
This is the second line of example2.log
56 changes: 56 additions & 0 deletions sidecar/otelcol/examples/pod_with_tailing_sidecars.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions sidecar/otelcol/tests/test.sh
Original file line number Diff line number Diff line change
@@ -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
Loading