From 716d2a1df3c5d2039662c9756d6aaaa6e06c3e57 Mon Sep 17 00:00:00 2001 From: Matej Gera Date: Fri, 24 Jun 2022 08:33:24 +0200 Subject: [PATCH 1/7] Add quickstart script Signed-off-by: Matej Gera --- scripts/alert-compliance-quickstart.sh | 51 ++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 scripts/alert-compliance-quickstart.sh diff --git a/scripts/alert-compliance-quickstart.sh b/scripts/alert-compliance-quickstart.sh new file mode 100755 index 0000000000..8d346dc22f --- /dev/null +++ b/scripts/alert-compliance-quickstart.sh @@ -0,0 +1,51 @@ +#!/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. +# +# After all comopnents are running, you can start the alert generator compliance tester +# with `thanos-example.yaml`` configuration provided in here: +# https://github.com/prometheus/compliance/blob/main/alert_generator/test-prometheus.yaml +set -euo pipefail + +trap 'kill 0' SIGTERM + +THANOS_EXECUTABLE=${THANOS_EXECUTABLE:-"thanos"} + +export TMP_DATA=$(mktemp -d /tmp/data-XXXX) +export ALERT_COMPLIANCE_RULES=$(mktemp /tmp/rules-XXXX.yaml) + +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} & + +# 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} & + +sleep 0.5 + +printf "\nAll services started, you can start the alert compliance tester! Waiting on a signal to quit\n" + +wait From 459f94d4242c270d100be006c8db879b9f0484e6 Mon Sep 17 00:00:00 2001 From: Matej Gera Date: Fri, 24 Jun 2022 09:58:27 +0200 Subject: [PATCH 2/7] Fix formatting Signed-off-by: Matej Gera --- scripts/alert-compliance-quickstart.sh | 30 +++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/scripts/alert-compliance-quickstart.sh b/scripts/alert-compliance-quickstart.sh index 8d346dc22f..5ae7b9920f 100755 --- a/scripts/alert-compliance-quickstart.sh +++ b/scripts/alert-compliance-quickstart.sh @@ -21,28 +21,28 @@ export ALERT_COMPLIANCE_RULES=$(mktemp /tmp/rules-XXXX.yaml) 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} & +${THANOS_EXECUTABLE} receive \ + --label 'receive_replica="0"' \ + --tsdb.path=${TMP_DATA} & # 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" & + --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} & + --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} & sleep 0.5 From 89aa7875d33b4d2e1919b669671031ec628e14aa Mon Sep 17 00:00:00 2001 From: Matej Gera Date: Fri, 24 Jun 2022 10:20:07 +0200 Subject: [PATCH 3/7] Fix shellcheck issues Signed-off-by: Matej Gera --- scripts/alert-compliance-quickstart.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/alert-compliance-quickstart.sh b/scripts/alert-compliance-quickstart.sh index 5ae7b9920f..6f09ea3cad 100755 --- a/scripts/alert-compliance-quickstart.sh +++ b/scripts/alert-compliance-quickstart.sh @@ -16,14 +16,17 @@ trap 'kill 0' SIGTERM THANOS_EXECUTABLE=${THANOS_EXECUTABLE:-"thanos"} -export TMP_DATA=$(mktemp -d /tmp/data-XXXX) -export ALERT_COMPLIANCE_RULES=$(mktemp /tmp/rules-XXXX.yaml) +TMP_DATA=$(mktemp -d /tmp/data-XXXX) +ALERT_COMPLIANCE_RULES=$(mktemp /tmp/rules-XXXX.yaml) -curl -sNL -o ${ALERT_COMPLIANCE_RULES} "https://raw.githubusercontent.com/prometheus/compliance/main/alert_generator/rules.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} & + --tsdb.path="${TMP_DATA}" & # 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). @@ -37,12 +40,12 @@ ${THANOS_EXECUTABLE} query \ # Script downloads the compliance test rules into a tmp file that `--rule-file` is pointing to. ${THANOS_EXECUTABLE} rule \ - --rule-file=${ALERT_COMPLIANCE_RULES} \ + --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} & + --data-dir="${TMP_DATA}" & sleep 0.5 From 65d21040ccd9c9a2d7c59df75559f6bc7d6cd7e9 Mon Sep 17 00:00:00 2001 From: Matej Gera Date: Fri, 24 Jun 2022 16:53:20 +0200 Subject: [PATCH 4/7] More stylistic fixes Signed-off-by: Matej Gera --- scripts/alert-compliance-quickstart.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/alert-compliance-quickstart.sh b/scripts/alert-compliance-quickstart.sh index 6f09ea3cad..7c95eff265 100755 --- a/scripts/alert-compliance-quickstart.sh +++ b/scripts/alert-compliance-quickstart.sh @@ -25,16 +25,16 @@ 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"' \ + --label='receive_replica="0"' \ --tsdb.path="${TMP_DATA}" & # 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 \ + --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" & From aaa3c101298373fb345fa1e0534efae43f40e25b Mon Sep 17 00:00:00 2001 From: Matej Gera Date: Wed, 29 Jun 2022 15:02:03 +0200 Subject: [PATCH 5/7] Use separate data dirs; Add note about which Thanos version to use Signed-off-by: Matej Gera --- scripts/alert-compliance-quickstart.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/alert-compliance-quickstart.sh b/scripts/alert-compliance-quickstart.sh index 7c95eff265..e8c30fbb9b 100755 --- a/scripts/alert-compliance-quickstart.sh +++ b/scripts/alert-compliance-quickstart.sh @@ -7,6 +7,9 @@ # 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' +# branch or with version >= 0.27.0. +# # After all comopnents are running, you can start the alert generator compliance tester # with `thanos-example.yaml`` configuration provided in here: # https://github.com/prometheus/compliance/blob/main/alert_generator/test-prometheus.yaml @@ -16,7 +19,8 @@ trap 'kill 0' SIGTERM THANOS_EXECUTABLE=${THANOS_EXECUTABLE:-"thanos"} -TMP_DATA=$(mktemp -d /tmp/data-XXXX) +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 @@ -26,7 +30,7 @@ curl -sNL -o "${ALERT_COMPLIANCE_RULES}" "https://raw.githubusercontent.com/prom ${THANOS_EXECUTABLE} receive \ --label='receive_replica="0"' \ - --tsdb.path="${TMP_DATA}" & + --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). @@ -45,7 +49,7 @@ ${THANOS_EXECUTABLE} rule \ --query=0.0.0.0:19192 \ --http-address=0.0.0.0:20902 \ --grpc-address=0.0.0.0:20901 \ - --data-dir="${TMP_DATA}" & + --data-dir="${TMP_DATA_RULER}" & sleep 0.5 From 4352209f8e0114e8fa5624d2a49c84b3a8ad8c89 Mon Sep 17 00:00:00 2001 From: Matej Gera <38492574+matej-g@users.noreply.github.com> Date: Wed, 29 Jun 2022 16:09:58 +0200 Subject: [PATCH 6/7] Update scripts/alert-compliance-quickstart.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jéssica Lins Signed-off-by: Matej Gera --- scripts/alert-compliance-quickstart.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/alert-compliance-quickstart.sh b/scripts/alert-compliance-quickstart.sh index e8c30fbb9b..0fa9ac29cd 100755 --- a/scripts/alert-compliance-quickstart.sh +++ b/scripts/alert-compliance-quickstart.sh @@ -10,7 +10,7 @@ # For the test you will need to run Thanos binary built with the latest 'main' # branch or with version >= 0.27.0. # -# After all comopnents are running, you can start the alert generator compliance tester +# After all components are running, you can start the alert generator compliance tester # with `thanos-example.yaml`` configuration provided in here: # https://github.com/prometheus/compliance/blob/main/alert_generator/test-prometheus.yaml set -euo pipefail From feb069a9462836ff5b44eea11e5b6ab85d14ace2 Mon Sep 17 00:00:00 2001 From: Matej Gera Date: Wed, 29 Jun 2022 16:11:43 +0200 Subject: [PATCH 7/7] Correct the test YAML config name Signed-off-by: Matej Gera --- scripts/alert-compliance-quickstart.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/alert-compliance-quickstart.sh b/scripts/alert-compliance-quickstart.sh index 0fa9ac29cd..ca2f188657 100755 --- a/scripts/alert-compliance-quickstart.sh +++ b/scripts/alert-compliance-quickstart.sh @@ -11,8 +11,8 @@ # branch or with version >= 0.27.0. # # After all components are running, you can start the alert generator compliance tester -# with `thanos-example.yaml`` configuration provided in here: -# https://github.com/prometheus/compliance/blob/main/alert_generator/test-prometheus.yaml +# with `test-thanos.yaml` configuration provided in here: +# https://github.com/prometheus/compliance/blob/main/alert_generator/test-thanos.yaml set -euo pipefail trap 'kill 0' SIGTERM