canonical / grafana-agent-snap

Snap of Grafana Agent, a telemetry collector for sending metrics, logs and traces to the Grafana's LGTM stack.
https://snapcraft.io/grafana-agent
Apache License 2.0
1 stars 5 forks source link

Enable loki.source.journal so systemd logs can be read #51

Closed Guillaumebeuzeboc closed 6 months ago

Guillaumebeuzeboc commented 7 months ago

Loki source journal must be enabled (CGO_ENABLED=1 and promtail_journal_enabled) at build time so that the agent can collect the systemd logs.

If not enabled, configuring loki to collect journalD logs will fail at startup.

Guillaumebeuzeboc commented 4 months ago

I tried to use the new version after this PR got merged, and it seems that the agent is still complaining about promtail being disabled.

If we look into the logs of snapcraft we can see:

2024-04-19 15:24:06.362 :: 2024-04-19 15:15:10.492 :: + export USE_CONTAINER=0
2024-04-19 15:24:06.362 :: 2024-04-19 15:15:10.493 :: + USE_CONTAINER=0
2024-04-19 15:24:06.362 :: 2024-04-19 15:15:10.493 :: + export 'GOFLAGS=-mod=readonly -tags=promtail_journal_enabled'
2024-04-19 15:24:06.362 :: 2024-04-19 15:15:10.493 :: + GOFLAGS='-mod=readonly -tags=promtail_journal_enabled'
2024-04-19 15:24:06.362 :: 2024-04-19 15:15:10.493 :: + make agent agentctl
2024-04-19 15:24:06.362 :: 2024-04-19 15:15:11.454 :: GOOS=linux GOARCH=amd64 GOARM= CGO_ENABLED=1 go build  -ldflags "-X github.com/grafana/agent/pkg/build.Branch=HEAD -X github.com/grafana/agent/pkg/build.Version=v0.40.4 -X github.com/grafana/agent/pkg/build.Revision=477a074cb -X github.com/grafana/agent/pkg/build.BuildUser=root@snapcraft-grafana-agent-on-amd64-for-amd64-44042628 -X github.com/grafana/agent/pkg/build.BuildDate=2024-04-19T13:15:11Z" -tags "" -o build/grafana-agent ./cmd/grafana-agent

The -tags "" remains empty.

So the GOFLAGS set doesn't seem to have an impact, at least on the tags. Setting export GO_TAGS="promtail_journal_enabled" instead should work.