Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config option for disabling reporting #78

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
sed-i marked this conversation as resolved.
Show resolved Hide resolved
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
sed-i marked this conversation as resolved.
Show resolved Hide resolved
stage-packages:
- libsystemd0
- libbpfcc
Expand Down
Loading