diff --git a/snap/hooks/configure b/snap/hooks/configure new file mode 100755 index 0000000..1aa2712 --- /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..8e4852d 100755 --- a/snap/local/agent-wrapper +++ b/snap/local/agent-wrapper @@ -5,8 +5,19 @@ 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 + echo "Launched with reporting disabled" | systemd-cat + REPORTING_ARG="-disable-reporting" +else + echo "Launched with reporting enabled" | systemd-cat + REPORTING_ARG="" +fi + +exec "${SNAP}/agent" -config.expand-env -config.file "${CONFIG_FILE}" "${REPORTING_ARG}" diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 74426b6..89ab43a 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 @@ -60,24 +58,12 @@ parts: source-type: git source-tag: "v0.40.4" build-snaps: - - go + - go/1.22/stable build-packages: - build-essential - 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