Email subscriptions newsletter build by using Rust and actix-web.
You'll need to install:
- Rust
- Podman or Docker
- PostgreSQL CLI client
- Optionally for loadtesting: k6
- For building v0.1.1 at least rustc 1.75.0 (coming from dependency deadpool-runtime>0.1.4)
On Ubuntu/Debian
apt install podman
On CentOs >= 8
dnf install podman
On Max OS X
brew install podman
On Ubuntu/Debian
apt install postgresql-client
On CentOs >= 8
dnf install postgresql
On Mac OS X using Homebrew
brew install libpq
echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc
Launch a (migrated) Postgres database via a container engine (default Podman, optionally Docker):
./scripts/launch_postgres.bash
Run application using cargo
:
cargo run
Send subscription entries by using the /subscription
endpoint
curl -s -w'\n%{http_code}\n' "http://127.0.0.1:8000/subscription" -d "email=email%40drconopoima.com&name=Jane%20Doe"
Test correct operation by using /healthcheck
endpoint
curl -s -w'\n%{http_code}\n' http://127.0.0.1:65080/healthcheck | jq '.'
{
"status": "pass",
"checks": {
"postgres_read": {
"status": "pass",
"time": "2022-03-06T23:32:10.555806Z",
"output": "",
"version": "PostgreSQL 14.2 (Debian 14.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit"
},
"postgres_write": {
"status": "pass",
"time": "2022-03-06T23:32:10.556877Z",
"pg_is_in_recovery": false,
"output": "",
"version": "PostgreSQL 14.2 (Debian 14.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit"
}
},
"output": "",
"time": "2022-03-06T23:32:10.547917389Z",
"version": "0.1.0"
}
200
By default, newsletter-rs is configured with Actix Logger Middleware in INFO logging level. It can be customized with RUST_LOG environment variable at runtime.
export RUST_LOG=DEBUG # Valid options trace|debug|info|warn|error|fatal
cargo run
export RUST_BACKTRACE=1 # Valid options 1|full
cargo run
Using cargo
:
cargo build
Using cargo
:
cargo test
Logging output from test logs is suppressed. Set environment variable TEST_LOG
for output:
TEST_LOG=true cargo test
To beautify the tracing output, you can use a process substitution and a JSON processing library, like jq
:
while read -r line; do echo "${line}" | jq -R 'fromjson? | .'; done< <(TEST_LOG=true cargo test)
Using K6
cargo run --release
k6 run --vus 200 ./testdata/k6_get_healthcheck.js --duration 60s
k6 run --vus 200 ./testdata/k6_post_subscription.js --duration 60s
Each configuration parameter is obtained from files within relative directory 'configuration'. The base configuration file is main.yaml
You can generate custom override configuration files, and launch by using variable 'APP__ENVIRONMENT'
E.g. to launch with example production settings, you would use:
APP__ENVIRONMENT=production cargo run --release
You can override any parameter with environment variables, by using the prefix "APP__" and field separator "_":
export APP__DATABASE_PASSWORD='Some$ecretPassword'
APP__APPLICATION_PORT=8080 cargo run --release
Would be equivalent as fabricating a custom override configuration file:
application:
port: 8080
database:
password: 'Some$ecretPassword'
Check the database diagram section.
The default migration scripts included in ./migrations
require at least Postgres 14 to work. You can replace scripts if need compatibility. Error in older versions 'syntax error at or near "TRIGGER"'.