1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2026-02-02 21:45:55 +00:00

test: Add a Prometheus integration test

This patch adds a Prometheus integration test, that runs a Prometheus
instance which scrapes chasquid, and then does a basic query to ensure
the scraping is working correctly.
This commit is contained in:
Alberto Bertogli
2026-02-02 19:20:08 +00:00
parent 1a4c672ac3
commit af7b1d895c
8 changed files with 88 additions and 1 deletions

View File

@@ -27,7 +27,8 @@ RUN apt-get install -y -q \
gettext-base dovecot-imapd \
exim4-daemon-light \
haproxy \
python3-dkim
python3-dkim \
prometheus promtool
# Install sudo, needed for the docker entrypoint.
RUN apt-get install -y -q sudo

View File

@@ -44,6 +44,8 @@ if the dependencies are not found:
- `haproxy`
- `t-19-dkimpy`: [dkimpy](https://pypi.org/project/dkimpy/) integration tests:
- `python3-dkim`
- `t-23-prometheus`: [Prometheus](https://prometheus.io/) integration tests:
- `prometheus promtool`
For some tests, python >= 3.5 is required; they will be skipped if it's not
available.

View File

@@ -0,0 +1,10 @@
smtp_address: ":1025"
submission_address: ":1587"
submission_over_tls_address: ":1465"
monitoring_address: ":1099"
mail_delivery_agent_bin: "test-mda"
mail_delivery_agent_args: "%to%"
data_dir: "../.data"
mail_log_path: "../.logs/mail_log"

View File

@@ -0,0 +1,4 @@
Subject: Prueba desde el test
Crece desde el test el futuro
Crece desde el test

View File

@@ -0,0 +1 @@
testserver localhost

View File

@@ -0,0 +1,12 @@
# Prometheus configuration file for testing chasquid metrics.
global:
# Reduce intervals to speed up the tests.
scrape_interval: 100ms
scrape_timeout: 100ms
evaluation_interval: 100ms
scrape_configs:
- job_name: 'chasquid'
static_configs:
- targets: ['localhost:1099']

53
test/t-23-prometheus/run.sh Executable file
View File

@@ -0,0 +1,53 @@
#!/bin/bash
set -e
. "$(dirname "$0")/../util/lib.sh"
init
check_hostaliases
# This is an integration test with Prometheus, so skip if it is not present.
if ! prometheus --version > /dev/null; then
skip "prometheus not installed"
fi
if ! promtool help > /dev/null; then
skip "promtool not installed"
fi
# Start chasquid and prometheus.
rm -rf .logs/ .prometheus/
mkdir -p .logs .prometheus
generate_certs_for testserver
chasquid-util-user-add user@testserver secretpassword
chasquid -v=2 --logfile=.logs/chasquid.log --config_dir=config &
prometheus \
--config.file=prometheus.yml \
--storage.tsdb.path=.prometheus/ \
> .prometheus/log 2>&1 &
# Wait until they're both up and running.
wait_until_ready 1025
wait_until "promtool check ready 2>/dev/null"
# Send an email.
smtpc user@testserver < content
wait_for_file .mail/user@testserver
mail_diff content .mail/user@testserver
# Query Prometheus and validate that it has scraped chasquid correctly.
function expect_value() {
promtool query instant http://localhost:9090 "$1" > ".logs/value-$1"
grep -q "=> $2" ".logs/value-$1"
}
# Note that it takes Prometheus ~5s to start scraping targets on the first
# run, for reasons currently unknown.
# If we don't clear up .prometheus/, then subsequent runs are faster, but
# starting with an empty data directory makes the test more hermetic.
wait_until expect_value chasquid_queue_putCount 1
success

View File

@@ -0,0 +1,4 @@
addr localhost:1465
server_cert config/certs/testserver/fullchain.pem
user user@testserver
password secretpassword