Skip to content

Commit

Permalink
Fix CI scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Dec 3, 2024
1 parent 33ac6db commit 53b2985
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 55 deletions.
2 changes: 1 addition & 1 deletion ci/build_and_push_docker_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
set -euo pipefail
IFS=$'\n\t'

export otp_vsn="${OTP_RELEASE:-25.3}"
export otp_vsn="${OTP_RELEASE:-27.1}"
echo "ERLANG/OTP ${otp_vsn}"

docker buildx build --platform linux/amd64,linux/arm64 \
Expand Down
45 changes: 14 additions & 31 deletions ci/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,38 @@
###############################################################################
## you may need to build 'amoc-arsenal-xmpp' docker image, before running: ##
## ##
## docker-compose up -d --scale amoc-worker=2 ##
## ##
## it can be done using this command: ##
## ##
## docker build . -t amoc-arsenal-xmpp ##
## ##
## alternatively, a custom amoc image can be provided by setting AMOC_IMAGE ##
## environment variable: ##
## ##
## AMOC_IMAGE=mongooseim/amoc-arsenal-xmpp docker-compose up -d ##
## ##
###############################################################################
version: "3.3"
services:

amoc-master:
hostname: "amoc-master"
image: "${AMOC_IMAGE:-amoc-arsenal-xmpp}"
pull_policy: never
environment:
AMOC_PROMETHEUS_IP: '{0, 0, 0, 0}'
ports:
- "4000:4000"
networks:
- amoc-test-network
environment:
AMOC_GRAPHITE_HOST: '"${GRAPHITE_HOST:-host.docker.internal}"'
healthcheck:
test: "amoc_arsenal_xmpp status"

amoc-worker:
image: "${AMOC_IMAGE:-amoc-arsenal-xmpp}"
networks:
- amoc-test-network
pull_policy: never
ulimits: ## ensure that we can use all the ephemeral ports
nofile:
soft: 66000
hard: 66000
environment:
AMOC_GRAPHITE_HOST: '"${GRAPHITE_HOST:-host.docker.internal}"'
AMOC_NODES: "['amoc_arsenal_xmpp@amoc-master']"
AMOC_XMPP_SERVERS: '[[{host, <<"host.docker.internal">>}]]'
entrypoint: [ "sh", "-c", 'AMOC_GRAPHITE_PREFIX="\"amoc-worker.$$HOSTNAME\"" /start_amoc.sh']
AMOC_PROMETHEUS_IP: '{0, 0, 0, 0}'
deploy:
mode: replicated
replicas: 6
healthcheck:
test: "amoc_arsenal_xmpp status"
graphite:
image: "graphiteapp/graphite-statsd:1.1.10-4"

prometheus:
image: "prom/prometheus"
ports:
- "8080:80"
- "2003:2003"
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
profiles:
- with_graphite
networks:
amoc-test-network:
- with_prometheus
18 changes: 18 additions & 0 deletions ci/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
global:
scrape_interval: 5s
evaluation_interval: 5s
scrape_configs:
- job_name: prometheus
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
- job_name: amoc-master
static_configs:
- targets: ["ci-amoc-master-1:9090"]
- job_name: amoc-worker-1
static_configs:
- targets: ["ci-amoc-worker-1:9090"]
- job_name: amoc-worker-2
static_configs:
- targets: ["ci-amoc-worker-2:9090"]
3 changes: 2 additions & 1 deletion ci/start_amoc_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ set -euo pipefail
IFS=$'\n\t'

cd "$(git rev-parse --show-toplevel)/ci"
docker compose --profile with_graphite up --wait --wait-timeout 100 --scale amoc-worker=2
docker compose --profile with_prometheus up --wait \
--wait-timeout 100 --scale amoc-worker=2
2 changes: 1 addition & 1 deletion ci/stop_amoc_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ set -euo pipefail
IFS=$'\n\t'

cd "$(git rev-parse --show-toplevel)/ci"
docker compose --profile with_graphite down
docker compose --profile with_prometheus down
43 changes: 22 additions & 21 deletions ci/test_amoc_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ function assert_match()
exit 1; }
}

function contains()
{
local output="$(cat -)"
local ret= acc=0
for pattern in "$@"; do
ret="$(echo "$output" | grep -q -e "$pattern"; echo "$?")"
if [ "$ret" -ne "0" ]; then
[ "$(($acc))" -eq "0" ] && {
echo "contains FAILED"
echo "output: '${output}'"; }
echo "pattern is missing: '${pattern}'"
fi >&2
acc+="+${ret}"
done
test "$(($acc))" "-eq" "0"
}

function get_nodes()
{
curl -s -X GET "http://localhost:4000/nodes" -H "accept: application/json" \
Expand All @@ -42,13 +59,6 @@ function number_of_nodes()
| jq '.nodes | length'
}

function get_graphite_prefix()
{
local node="$1"
curl -s -X GET "http://localhost:4000/status/$node" -H "accept: application/json" \
| jq '.env.AMOC_GRAPHITE_PREFIX | ltrimstr("\"") | rtrimstr("\"")' | sed 's/"//g'
}

function retry()
{
local n="$1" m="0"
Expand All @@ -62,27 +72,18 @@ function retry()
echo -e "\nsuccess after '$m' retries";
}

function are_metrics_reported()
function metrics_reported()
{
local graphite_prefix="$1"
local length="$(curl -s "http://localhost:8080/metrics/find?query=${graphite_prefix}.*" | jq "length")"
[ "$length" -gt "0" ]
curl -s 'http://localhost:9090/api/v1/targets' | contains "$@"
}

function wait_for_reported_metrics()
{
local graphite_prefix="$1"
retry 60 are_metrics_reported "$graphite_prefix"
function wait_for_metrics() {
retry 60 metrics_reported "$@"
}

assert_equal "number of nodes" 3 "$(number_of_nodes)"

for node in $(get_nodes); do
assert_match "node name" "amoc_arsenal_xmpp@.*" "$node"
if [ "$node" != "amoc_arsenal_xmpp@amoc-master" ]; then
graphite_prefix="$(get_graphite_prefix $node)"
wait_for_reported_metrics "$graphite_prefix"
else
wait_for_reported_metrics "amoc-master"
fi
wait_for_metrics "amoc-master"
done

0 comments on commit 53b2985

Please sign in to comment.