From afbaf0338ff0462047a6ec0f7a04ac23629733a4 Mon Sep 17 00:00:00 2001 From: Irina Marchuk Date: Thu, 3 Nov 2022 08:24:21 +0000 Subject: [PATCH 1/2] Promtail: Add go build tag promtail_journal_enbaled --- CHANGELOG.md | 1 + Makefile | 7 +++++-- README.md | 9 +++++---- clients/cmd/promtail/Dockerfile | 2 +- clients/cmd/promtail/Dockerfile.arm32 | 2 +- clients/cmd/promtail/Dockerfile.cross | 2 +- clients/cmd/promtail/Dockerfile.debug | 2 +- clients/pkg/promtail/targets/journal/journaltarget.go | 4 ++-- .../pkg/promtail/targets/journal/journaltarget_test.go | 4 ++-- .../pkg/promtail/targets/journal/journaltargetmanager.go | 4 ++-- .../targets/journal/journaltargetmanager_linux.go | 4 ++-- 11 files changed, 23 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c1d397b56c6..08aaf0002037 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ Check the history of the branch FIXME. * [7263](https://github.com/grafana/loki/pull/7263) **bboreham**: Dependencies: klauspost/compress package to v1.15.11; improves performance. * [7270](https://github.com/grafana/loki/pull/7270) **wilfriedroset**: Add support for `username` to redis cache configuration. * [6952](https://github.com/grafana/loki/pull/6952) **DylanGuedes**: Experimental: Introduce a new feature named stream sharding. +* [7587](https://github.com/grafana/loki/pull/7587) **mar4uk**: Add go build tag `promtail_journal_enabled` to include/exclude promtail journald code from binary. ##### Fixes * [7453](https://github.com/grafana/loki/pull/7453) **periklis**: Add single compactor http client for delete and gennumber clients diff --git a/Makefile b/Makefile index 8eb9e89375d4..19531edcb112 100644 --- a/Makefile +++ b/Makefile @@ -186,6 +186,9 @@ PROMTAIL_GO_FLAGS = $(DYN_GO_FLAGS) PROMTAIL_DEBUG_GO_FLAGS = $(DYN_DEBUG_GO_FLAGS) endif endif +ifeq ($(PROMTAIL_JOURNAL_ENABLED), true) +PROMTAIL_GO_TAGS = promtail_journal_enabled +endif .PHONY: clients/cmd/promtail/promtail clients/cmd/promtail/promtail-debug promtail: clients/cmd/promtail/promtail promtail-debug: clients/cmd/promtail/promtail-debug @@ -199,10 +202,10 @@ $(PROMTAIL_GENERATED_FILE): $(PROMTAIL_UI_FILES) GOOS=$(shell go env GOHOSTOS) go generate -x -v ./clients/pkg/promtail/server/ui clients/cmd/promtail/promtail: - CGO_ENABLED=$(PROMTAIL_CGO) go build $(PROMTAIL_GO_FLAGS) -o $@ ./$(@D) + CGO_ENABLED=$(PROMTAIL_CGO) go build $(PROMTAIL_GO_FLAGS) --tags=$(PROMTAIL_GO_TAGS) -o $@ ./$(@D) clients/cmd/promtail/promtail-debug: - CGO_ENABLED=$(PROMTAIL_CGO) go build $(PROMTAIL_DEBUG_GO_FLAGS) -o $@ ./$(@D) + CGO_ENABLED=$(PROMTAIL_CGO) go build $(PROMTAIL_DEBUG_GO_FLAGS) --tags=$(PROMTAIL_GO_TAGS) -o $@ ./$(@D) ######### # Mixin # diff --git a/README.md b/README.md index 2d40f90ee77f..19c466caf5de 100644 --- a/README.md +++ b/README.md @@ -113,21 +113,22 @@ To build Promtail on non-Linux platforms, use the following command: $ go build ./clients/cmd/promtail ``` -On Linux, Promtail requires the systemd headers to be installed for -Journal support. +On Linux, Promtail requires the systemd headers to be installed if +Journal support is enabled. +To enable Journal support the go build tag flag `promtail_journal_enabled` should be passed With Journal support on Ubuntu, run with the following commands: ```bash $ sudo apt install -y libsystemd-dev -$ go build ./clients/cmd/promtail +$ go build ./clients/cmd/promtail --tags=promtail_journal_enabled ``` With Journal support on CentOS, run with the following commands: ```bash $ sudo yum install -y systemd-devel -$ go build ./clients/cmd/promtail +$ go build ./clients/cmd/promtail --tags=promtail_journal_enabled ``` Otherwise, to build Promtail without Journal support, run `go build` diff --git a/clients/cmd/promtail/Dockerfile b/clients/cmd/promtail/Dockerfile index 8cd85c2d4122..4a4c131a0d83 100644 --- a/clients/cmd/promtail/Dockerfile +++ b/clients/cmd/promtail/Dockerfile @@ -5,7 +5,7 @@ WORKDIR /src/loki # Backports repo required to get a libsystemd version 246 or newer which is required to handle journal +ZSTD compression RUN echo "deb http://deb.debian.org/debian bullseye-backports main" >> /etc/apt/sources.list RUN apt-get update && apt-get install -t bullseye-backports -qy libsystemd-dev -RUN make clean && make BUILD_IN_CONTAINER=false promtail +RUN make clean && make BUILD_IN_CONTAINER=false PROMTAIL_JOURNAL_ENABLED=true promtail # Promtail requires debian as the base image to support systemd journal reading FROM debian:bullseye-slim diff --git a/clients/cmd/promtail/Dockerfile.arm32 b/clients/cmd/promtail/Dockerfile.arm32 index f8e33b40a47a..1fc591763e25 100644 --- a/clients/cmd/promtail/Dockerfile.arm32 +++ b/clients/cmd/promtail/Dockerfile.arm32 @@ -5,7 +5,7 @@ WORKDIR /src/loki # Backports repo required to get a libsystemd version 246 or newer which is required to handle journal +ZSTD compression RUN echo "deb http://deb.debian.org/debian bullseye-backports main" >> /etc/apt/sources.list RUN apt-get update && apt-get install -t bullseye-backports -qy libsystemd-dev -RUN make clean && make BUILD_IN_CONTAINER=false promtail +RUN make clean && make BUILD_IN_CONTAINER=false PROMTAIL_JOURNAL_ENABLED=true promtail # Promtail requires debian as the base image to support systemd journal reading FROM debian:bullseye-slim diff --git a/clients/cmd/promtail/Dockerfile.cross b/clients/cmd/promtail/Dockerfile.cross index 88373286df2d..3ba7b3dfeb92 100644 --- a/clients/cmd/promtail/Dockerfile.cross +++ b/clients/cmd/promtail/Dockerfile.cross @@ -10,7 +10,7 @@ FROM --platform=linux/amd64 $BUILD_IMAGE as build COPY --from=goenv /goarch /goarm / COPY . /src/loki WORKDIR /src/loki -RUN make clean && GOARCH=$(cat /goarch) GOARM=$(cat /goarm) make BUILD_IN_CONTAINER=false promtail +RUN make clean && GOARCH=$(cat /goarch) GOARM=$(cat /goarm) make BUILD_IN_CONTAINER=false PROMTAIL_JOURNAL_ENABLED=true promtail # Promtail requires debian as the base image to support systemd journal reading FROM debian:stretch-slim diff --git a/clients/cmd/promtail/Dockerfile.debug b/clients/cmd/promtail/Dockerfile.debug index 2c9369bd16ec..2d9737458148 100644 --- a/clients/cmd/promtail/Dockerfile.debug +++ b/clients/cmd/promtail/Dockerfile.debug @@ -6,7 +6,7 @@ FROM grafana/loki-build-image as build ARG GOARCH="amd64" COPY . /src/loki WORKDIR /src/loki -RUN make clean && make BUILD_IN_CONTAINER=false promtail-debug +RUN make clean && make BUILD_IN_CONTAINER=false PROMTAIL_JOURNAL_ENABLED=true promtail-debug FROM alpine:3.16.2 diff --git a/clients/pkg/promtail/targets/journal/journaltarget.go b/clients/pkg/promtail/targets/journal/journaltarget.go index 000268daf48a..c0b152d46529 100644 --- a/clients/pkg/promtail/targets/journal/journaltarget.go +++ b/clients/pkg/promtail/targets/journal/journaltarget.go @@ -1,5 +1,5 @@ -//go:build linux && cgo -// +build linux,cgo +//go:build linux && cgo && promtail_journal_enabled +// +build linux,cgo,promtail_journal_enabled package journal diff --git a/clients/pkg/promtail/targets/journal/journaltarget_test.go b/clients/pkg/promtail/targets/journal/journaltarget_test.go index 14d7c28fc512..72220f5ca421 100644 --- a/clients/pkg/promtail/targets/journal/journaltarget_test.go +++ b/clients/pkg/promtail/targets/journal/journaltarget_test.go @@ -1,5 +1,5 @@ -//go:build linux && cgo -// +build linux,cgo +//go:build linux && cgo && promtail_journal_enabled +// +build linux,cgo,promtail_journal_enabled package journal diff --git a/clients/pkg/promtail/targets/journal/journaltargetmanager.go b/clients/pkg/promtail/targets/journal/journaltargetmanager.go index 172cac17850b..5ec2922a2a8c 100644 --- a/clients/pkg/promtail/targets/journal/journaltargetmanager.go +++ b/clients/pkg/promtail/targets/journal/journaltargetmanager.go @@ -1,5 +1,5 @@ -//go:build !linux || !cgo -// +build !linux !cgo +//go:build !linux || !cgo || !promtail_journal_enabled +// +build !linux !cgo !promtail_journal_enabled package journal diff --git a/clients/pkg/promtail/targets/journal/journaltargetmanager_linux.go b/clients/pkg/promtail/targets/journal/journaltargetmanager_linux.go index 0fd5e7c85649..6940d57ead5d 100644 --- a/clients/pkg/promtail/targets/journal/journaltargetmanager_linux.go +++ b/clients/pkg/promtail/targets/journal/journaltargetmanager_linux.go @@ -1,5 +1,5 @@ -//go:build cgo -// +build cgo +//go:build cgo && promtail_journal_enabled +// +build cgo,promtail_journal_enabled package journal From 899a7a3b704227d6559e2c7444ad5ead9d3e88dc Mon Sep 17 00:00:00 2001 From: Irina Marchuk Date: Tue, 8 Nov 2022 08:53:15 +0000 Subject: [PATCH 2/2] Promtail: Add go build tag promtail_journal_enbaled. Add doc, update changelog --- CHANGELOG.md | 2 +- docs/sources/upgrading/_index.md | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08aaf0002037..e9aece7e5e2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ ##### Fixes ##### Changes +* [7587](https://github.com/grafana/loki/pull/7587) **mar4uk**: Add go build tag `promtail_journal_enabled` to include/exclude Promtail journald code from binary. #### Fluent Bit @@ -61,7 +62,6 @@ Check the history of the branch FIXME. * [7263](https://github.com/grafana/loki/pull/7263) **bboreham**: Dependencies: klauspost/compress package to v1.15.11; improves performance. * [7270](https://github.com/grafana/loki/pull/7270) **wilfriedroset**: Add support for `username` to redis cache configuration. * [6952](https://github.com/grafana/loki/pull/6952) **DylanGuedes**: Experimental: Introduce a new feature named stream sharding. -* [7587](https://github.com/grafana/loki/pull/7587) **mar4uk**: Add go build tag `promtail_journal_enabled` to include/exclude promtail journald code from binary. ##### Fixes * [7453](https://github.com/grafana/loki/pull/7453) **periklis**: Add single compactor http client for delete and gennumber clients diff --git a/docs/sources/upgrading/_index.md b/docs/sources/upgrading/_index.md index 6d2fa1b1323b..bbf2a1f0ed56 100644 --- a/docs/sources/upgrading/_index.md +++ b/docs/sources/upgrading/_index.md @@ -32,6 +32,18 @@ The output is incredibly verbose as it shows the entire internal config struct u ## Main / Unreleased +### Promtail + +#### The go build tag `promtail_journal_enabled` was introduced + +The go build tag `promtail_journal_enabled` should be passed to include Journal support to the promtail binary. +If you need Journal support you will need to run go build with tag `promtail_journal_enabled`: + +```shell +go build ./clients/cmd/promtail --tags=promtail_journal_enabled +``` +Introducing this tag aims to relieve Linux/CentOS users with CGO enabled from installing libsystemd-dev/systemd-devel libraries if they don't need Journal support. + ## 2.7.0 ### Loki