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

Scripts: Add quickstart script for alert generator compliance test #5441

Closed
wants to merge 7 commits into from
Closed
Changes from 5 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
58 changes: 58 additions & 0 deletions scripts/alert-compliance-quickstart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash
#
# This is a script for running the Prometheus Alert Generator Compliance
# test suite. Read more at: https://github.com/prometheus/compliance/tree/main/alert_generator
#
# It is the most minimal setup you can use for testing on a local machine.
# The script will start all necessary components (receive, ruler, querier)
# with appropriate confguration.
#
# For the test you will need to run Thanos binary built with the latest 'main'
matej-g marked this conversation as resolved.
Show resolved Hide resolved
# branch or with version >= 0.27.0.
#
# After all comopnents are running, you can start the alert generator compliance tester
matej-g marked this conversation as resolved.
Show resolved Hide resolved
# with `thanos-example.yaml`` configuration provided in here:
# https://github.com/prometheus/compliance/blob/main/alert_generator/test-prometheus.yaml
matej-g marked this conversation as resolved.
Show resolved Hide resolved
set -euo pipefail

trap 'kill 0' SIGTERM

THANOS_EXECUTABLE=${THANOS_EXECUTABLE:-"thanos"}

TMP_DATA_RECEIVER=$(mktemp -d /tmp/data-receive-XXXX)
TMP_DATA_RULER=$(mktemp -d /tmp/data-ruler-XXXX)
ALERT_COMPLIANCE_RULES=$(mktemp /tmp/rules-XXXX.yaml)

export TMP_DATA
export ALERT_COMPLIANCE_RULES

curl -sNL -o "${ALERT_COMPLIANCE_RULES}" "https://raw.githubusercontent.com/prometheus/compliance/main/alert_generator/rules.yaml"

${THANOS_EXECUTABLE} receive \
--label='receive_replica="0"' \
--tsdb.path="${TMP_DATA_RECEIVER}" &

# We make sure to filter out the 'receive_replica' and 'tenant_id' labels,
# which are added by the receiver (they cannot be present during the test).
${THANOS_EXECUTABLE} query \
--http-address=0.0.0.0:19192 \
--store=0.0.0.0:10901 \
--rule=0.0.0.0:20901 \
--grpc-address=0.0.0.0:19099 \
--query.replica-label="tenant_id" \
--query.replica-label="receive_replica" &

# Script downloads the compliance test rules into a tmp file that `--rule-file` is pointing to.
${THANOS_EXECUTABLE} rule \
--rule-file="${ALERT_COMPLIANCE_RULES}" \
--alertmanagers.url="http://0.0.0.0:8080" \
--query=0.0.0.0:19192 \
--http-address=0.0.0.0:20902 \
--grpc-address=0.0.0.0:20901 \
--data-dir="${TMP_DATA_RULER}" &

sleep 0.5

printf "\nAll services started, you can start the alert compliance tester! Waiting on a signal to quit\n"

wait