Skip to content

Commit

Permalink
Add config option for disabling reporting (#78)
Browse files Browse the repository at this point in the history
* Add config for disable-reporting
* Revert "Build for arm64 on amd64"

This reverts commit d7a65e8.

* Pin go version to 1.22
grafana/agent#6972
  • Loading branch information
sed-i authored Nov 14, 2024
1 parent d7a65e8 commit 1da2001
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 23 deletions.
31 changes: 31 additions & 0 deletions snap/hooks/configure
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions snap/hooks/install
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#!/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 <<EOF > $SNAP_DATA/etc/grafana-agent.yaml
cat <<EOF > "${SNAP_DATA}/etc/grafana-agent.yaml"
integrations:
agent:
enabled: true
node_exporter:
enabled: true
EOF
fi

15 changes: 13 additions & 2 deletions snap/local/agent-wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
20 changes: 3 additions & 17 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 1da2001

Please sign in to comment.