From 46c97914312c7a1f016680af4df1a3cecad3ee0d Mon Sep 17 00:00:00 2001 From: sed-i <82407168+sed-i@users.noreply.github.com> Date: Tue, 12 Nov 2024 18:31:01 -0500 Subject: [PATCH 1/4] Add config for disable-reporting --- snap/hooks/configure | 31 +++++++++++++++++++++++++++++++ snap/hooks/install | 7 +++---- snap/local/agent-wrapper | 13 +++++++++++-- 3 files changed, 45 insertions(+), 6 deletions(-) create mode 100755 snap/hooks/configure diff --git a/snap/hooks/configure b/snap/hooks/configure new file mode 100755 index 0000000..123b1d3 --- /dev/null +++ b/snap/hooks/configure @@ -0,0 +1,31 @@ +#!/bin/sh -e + +DEFAULT_REPORTING_ENABLED="1" + +get_reporting_enabled() { + value="$(snapctl get reporting_enabled)" + if [ -z "$value" ]; then + value="$DEFAULT_REPORTING_ENABLED" + set_reporting_enabled $value + fi + echo "$value" +} + +set_reporting_enabled() { + snapctl set reporting_enabled="$1" +} + +handle_reporting_enabled() { + reporting_enabled="$(get_reporting_enabled)" + + # Validate + if ! expr "$reporting_enabled" : '^[0-1]$' > /dev/null; then + echo "\"$reporting_enabled\" must be either 0 (false) or 1 (true)" >&2 + return 1 + fi + + set_reporting_enabled "$reporting_enabled" + snapctl restart grafana-agent +} + +handle_reporting_enabled diff --git a/snap/hooks/install b/snap/hooks/install index 3621085..d5c3e49 100755 --- a/snap/hooks/install +++ b/snap/hooks/install @@ -1,10 +1,10 @@ #!/bin/sh -e -mkdir -p $SNAP_DATA/etc/ +mkdir -p "${SNAP_DATA}/etc/" -if [ ! -f $SNAP_DATA/etc/grafana-agent.yaml ] +if [ ! -f "${SNAP_DATA}/etc/grafana-agent.yaml" ] then - cat < $SNAP_DATA/etc/grafana-agent.yaml + cat < "${SNAP_DATA}/etc/grafana-agent.yaml" integrations: agent: enabled: true @@ -12,4 +12,3 @@ integrations: enabled: true EOF fi - diff --git a/snap/local/agent-wrapper b/snap/local/agent-wrapper index cbb8ef5..a0bffab 100755 --- a/snap/local/agent-wrapper +++ b/snap/local/agent-wrapper @@ -5,8 +5,17 @@ IS_CONNECTED=$(snapctl is-connected etc-grafana-agent; echo $?) if [ "${IS_CONNECTED}" = "0" -a -r /etc/grafana-agent.yaml ] then echo "Launched with config from the host filesystem" | systemd-cat - exec "${SNAP}/agent" -config.expand-env -config.file "/etc/grafana-agent.yaml" + CONFIG_FILE="/etc/grafana-agent.yaml" else echo "Launched with minimal default config from the snap" | systemd-cat - exec "${SNAP}/agent" -config.expand-env -config.file "$SNAP_DATA/etc/grafana-agent.yaml" + CONFIG_FILE="$SNAP_DATA/etc/grafana-agent.yaml" fi + +if [ "$(snapctl get reporting_enabled)" = "0" ] +then + REPORTING_ARG="-disable-reporting" +else + REPORTING_ARG="" +fi + +exec "${SNAP}/agent" -config.expand-env -config.file "${CONFIG_FILE}" "${REPORTING_ARG}" From cd57f0e6e4215798af0be4661ca98cfa052d69ce Mon Sep 17 00:00:00 2001 From: sed-i <82407168+sed-i@users.noreply.github.com> Date: Tue, 12 Nov 2024 19:37:13 -0500 Subject: [PATCH 2/4] Fixes --- snap/hooks/configure | 4 ++-- snap/local/agent-wrapper | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/snap/hooks/configure b/snap/hooks/configure index 123b1d3..1aa2712 100755 --- a/snap/hooks/configure +++ b/snap/hooks/configure @@ -3,7 +3,7 @@ DEFAULT_REPORTING_ENABLED="1" get_reporting_enabled() { - value="$(snapctl get reporting_enabled)" + value="$(snapctl get reporting-enabled)" if [ -z "$value" ]; then value="$DEFAULT_REPORTING_ENABLED" set_reporting_enabled $value @@ -12,7 +12,7 @@ get_reporting_enabled() { } set_reporting_enabled() { - snapctl set reporting_enabled="$1" + snapctl set reporting-enabled="$1" } handle_reporting_enabled() { diff --git a/snap/local/agent-wrapper b/snap/local/agent-wrapper index a0bffab..8e4852d 100755 --- a/snap/local/agent-wrapper +++ b/snap/local/agent-wrapper @@ -11,10 +11,12 @@ else CONFIG_FILE="$SNAP_DATA/etc/grafana-agent.yaml" fi -if [ "$(snapctl get reporting_enabled)" = "0" ] +if [ "$(snapctl get reporting-enabled)" = "0" ] then + echo "Launched with reporting disabled" | systemd-cat REPORTING_ARG="-disable-reporting" else + echo "Launched with reporting enabled" | systemd-cat REPORTING_ARG="" fi From c76b7afa5b3408b5bc6b2604ec9cd3cc2e76acf7 Mon Sep 17 00:00:00 2001 From: sed-i <82407168+sed-i@users.noreply.github.com> Date: Tue, 12 Nov 2024 19:37:16 -0500 Subject: [PATCH 3/4] Revert "Build for arm64 on amd64" This reverts commit d7a65e8b69f0d4b51f390b6a59e1a96aaa44e0f6. --- snap/snapcraft.yaml | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 74426b6..e4b4d5c 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -43,10 +43,8 @@ apps: - etc-grafana-agent - proc-sys-kernel-random architectures: - - build-on: [amd64] - - build-on: [amd64, arm64] - build-for: [arm64] - + - build-on: amd64 + - build-on: arm64 parts: wrapper: plugin: dump @@ -66,18 +64,6 @@ parts: - libsystemd-dev - libbpfcc-dev - bpfcc-tools - - on amd64 to arm64: - - gcc-aarch64-linux-gnu - - linux-libc-dev-arm64-cross - - libc6-dev-arm64-cross - build-environment: - - to amd64: - - GOOS: linux - - GOARCH: amd64 - - to arm64: - - GOOS: linux - - GOARCH: arm64 - - CC: /usr/bin/aarch64-linux-gnu-gcc stage-packages: - libsystemd0 - libbpfcc From f4687644d8b501bc8902e1d33d0f143ca670c61a Mon Sep 17 00:00:00 2001 From: sed-i <82407168+sed-i@users.noreply.github.com> Date: Wed, 13 Nov 2024 00:45:37 -0500 Subject: [PATCH 4/4] Pin go version to 1.22 https://github.com/grafana/agent/issues/6972 --- snap/snapcraft.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index e4b4d5c..89ab43a 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -58,7 +58,7 @@ parts: source-type: git source-tag: "v0.40.4" build-snaps: - - go + - go/1.22/stable build-packages: - build-essential - libsystemd-dev