From 1420ad946d3788e743aa22710139ca53342f327a Mon Sep 17 00:00:00 2001 From: Anthony Date: Thu, 13 Nov 2025 11:10:41 +0100 Subject: [PATCH] Migrate to Grafana Alloy as the recommended replacement for log forwarding. Changes: - Add alloy/config.alloy.example configuration - Move promtail/run.sh to alloy/run.sh - Update logging.yml to use Alloy - Remove promtail/config.yml.example --- alloy/config.alloy.example | 87 +++++++++++++++++++++++++++++++++++++ alloy/run.sh | 34 +++++++++++++++ logging.yml | 11 +++-- promtail/config.yml.example | 49 --------------------- promtail/run.sh | 26 ----------- 5 files changed, 126 insertions(+), 81 deletions(-) create mode 100644 alloy/config.alloy.example create mode 100755 alloy/run.sh delete mode 100644 promtail/config.yml.example delete mode 100755 promtail/run.sh diff --git a/alloy/config.alloy.example b/alloy/config.alloy.example new file mode 100644 index 00000000..1329e9f5 --- /dev/null +++ b/alloy/config.alloy.example @@ -0,0 +1,87 @@ +discovery.docker "docker" { + host = "unix:///var/run/docker.sock" +} + +loki.process "docker" { + forward_to = [loki.write.default.receiver] + + stage.docker { } +} + +discovery.relabel "docker" { + targets = discovery.docker.docker.targets + + rule { + source_labels = ["__meta_docker_container_label_promtail_monitored"] + regex = "true" + action = "keep" + } + + rule { + source_labels = ["__meta_docker_container_name"] + regex = "/(.*)" + target_label = "container" + } + + rule { + source_labels = ["container"] + regex = ".*charon.*" + target_label = "job" + replacement = "charon" + } + + rule { + source_labels = ["container"] + regex = ".*nethermind.*" + target_label = "job" + replacement = "nethermind" + } + + rule { + source_labels = ["container"] + regex = ".*lodestar.*" + target_label = "job" + replacement = "lodestar" + } + + rule { + source_labels = ["container"] + regex = ".*lighthouse.*" + target_label = "job" + replacement = "lighthouse" + } + + rule { + source_labels = ["container"] + regex = ".*mev-boost.*" + target_label = "job" + replacement = "mev-boost" + } + + rule { + target_label = "cluster_name" + replacement = "$CLUSTER_NAME" + } + + rule { + target_label = "cluster_peer" + replacement = "$CLUSTER_PEER" + } +} + +loki.source.docker "docker" { + host = "unix:///var/run/docker.sock" + targets = discovery.docker.docker.targets + forward_to = [loki.process.docker.receiver] + relabel_rules = discovery.relabel.docker.rules +} + +loki.write "default" { + endpoint { + url = "$CHARON_LOKI_ADDRESSES" + } + external_labels = { + cluster_name = "$CLUSTER_NAME", + cluster_peer = "$CLUSTER_PEER", + } +} diff --git a/alloy/run.sh b/alloy/run.sh new file mode 100755 index 00000000..a1290119 --- /dev/null +++ b/alloy/run.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +if [ -z "${CHARON_LOKI_ADDRESSES:-}" ]; then + echo "Error: \$CHARON_LOKI_ADDRESSES variable is empty" >&2 + exit 1 +fi + +if [ -z "${CLUSTER_NAME:-}" ]; then + echo "Error: \$CLUSTER_NAME variable is empty" >&2 + exit 1 +fi + +if [ -z "${CLUSTER_PEER:-}" ]; then + echo "Error: \$CLUSTER_PEER variable is empty" >&2 + exit 1 +fi + +SRC="/etc/alloy/config.alloy.example" +DST="/etc/alloy/config.alloy" + +echo "Rendering template: $SRC -> $DST" + +sed -e "s|\$CHARON_LOKI_ADDRESSES|${CHARON_LOKI_ADDRESSES}|g" \ + -e "s|\$CLUSTER_NAME|${CLUSTER_NAME}|g" \ + -e "s|\$CLUSTER_PEER|${CLUSTER_PEER}|g" \ + "$SRC" > "$DST" + +echo "Config successfully rendered to $DST" + +# Execute the command passed as arguments if any +if [ $# -gt 0 ]; then + echo "Executing: $@" + exec "$@" +fi diff --git a/logging.yml b/logging.yml index b57c2bc3..121c1761 100644 --- a/logging.yml +++ b/logging.yml @@ -1,17 +1,16 @@ services: - - promtail: - image: grafana/promtail:${PROMTAIL_VERSION:-2.8.2} + alloy: + image: grafana/alloy:${ALLOY_VERSION:-v1.11.3} environment: CHARON_LOKI_ADDRESSES: ${CHARON_LOKI_ADDRESSES} CLUSTER_NAME: ${CLUSTER_NAME} CLUSTER_PEER: ${CLUSTER_PEER} - command: -config.file=/etc/promtail/config.yml volumes: - - ./promtail:/etc/promtail + - ./alloy:/etc/alloy - /var/run/docker.sock:/var/run/docker.sock networks: [dvnode] - entrypoint: /etc/promtail/run.sh + entrypoint: /etc/alloy/run.sh + command: ["/bin/alloy", "run", "/etc/alloy/config.alloy", "--storage.path=/var/lib/alloy/data"] restart: unless-stopped networks: diff --git a/promtail/config.yml.example b/promtail/config.yml.example deleted file mode 100644 index 87e61447..00000000 --- a/promtail/config.yml.example +++ /dev/null @@ -1,49 +0,0 @@ -server: - http_listen_port: 9080 - grpc_listen_port: 0 - -positions: - filename: /tmp/positions.yaml - -clients: - - url: $CHARON_LOKI_ADDRESSES - -scrape_configs: - - job_name: docker - docker_sd_configs: - - host: unix:///var/run/docker.sock - relabel_configs: - - source_labels: - [__meta_docker_container_label_promtail_monitored] - regex: "true" - action: keep - - source_labels: ['__meta_docker_container_name'] - regex: '/(.*)' - replacement: '$1' - target_label: 'container' - - source_labels: ['container'] - regex: '.*charon.*' - replacement: 'charon' - target_label: 'job' - - source_labels: ['container'] - regex: '.*nethermind.*' - replacement: 'nethermind' - target_label: 'job' - - source_labels: ['container'] - regex: '.*lodestar.*' - replacement: 'lodestar' - target_label: 'job' - - source_labels: ['container'] - regex: '.*lighthouse.*' - replacement: 'lighthouse' - target_label: 'job' - - source_labels: ['container'] - regex: '.*mev-boost.*' - replacement: 'mev-boost' - target_label: 'job' - - target_label: 'cluster_name' - replacement: $CLUSTER_NAME - - target_label: 'cluster_peer' - replacement: $CLUSTER_PEER - pipeline_stages: - - docker: {} diff --git a/promtail/run.sh b/promtail/run.sh deleted file mode 100755 index f8d33360..00000000 --- a/promtail/run.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh - -if [ -z "$CHARON_LOKI_ADDRESSES" ]; then - echo "Error: \$CHARON_LOKI_ADDRESSES variable is empty" >&2 - exit 1 -fi - -if [ -z "$CLUSTER_NAME" ]; then - echo "Error: \$CLUSTER_NAME variable is empty" >&2 - exit 1 -fi - -if [ -z "$CLUSTER_PEER" ]; then - echo "Error: \$CLUSTER_PEER variable is empty" >&2 - exit 1 -fi - -# Process the template file once -sed -e "s|\$CHARON_LOKI_ADDRESSES|${CHARON_LOKI_ADDRESSES}|g" \ - -e "s|\$CLUSTER_NAME|${CLUSTER_NAME}|g" \ - -e "s|\$CLUSTER_PEER|${CLUSTER_PEER}|g" \ - /etc/promtail/config.yml.example > /etc/promtail/config.yml - -# Start Promtail with the generated config -/usr/bin/promtail \ - -config.file=/etc/promtail/config.yml