add docs
This commit is contained in:
@@ -21,9 +21,28 @@ If `send` would make a counter reach a warning threshold or a limit, it refuses
|
||||
It also prints where those notifications would go. **Check that line says `receive`'s address before adding the flag.** With the real URLs, the web app
|
||||
emails the customer and posts to Telegram.
|
||||
|
||||
The commands below use `/tmp/countersend`, the default config path, and `test@yourdomain`. Replace them with your own.
|
||||
The commands below use `/tmp/countersend`, the default config path, and the test domain `dimitrijedimitrijevic.com`. Change the paths if yours differ.
|
||||
Run them as a user that can read the daemon's config, because `send` takes the address and token from it.
|
||||
|
||||
### The test domain
|
||||
|
||||
`dimitrijedimitrijevic.com` is in organisation `2741`. Its limits come from the CDB on the server, so check them in step 3 before relying on the numbers here:
|
||||
|
||||
| Row | In | Out | Out warning (80%) |
|
||||
|---|---|---|---|
|
||||
| Mailboxes `me@`, `biz@`, `helloworld@` | 1000 | 25 | 20 |
|
||||
| Other mailboxes | 1000 | 120 | 96 |
|
||||
| Domain `dimitrijedimitrijevic.com` | 1000 | 120 | 96 |
|
||||
| Organisation `2741` | 1000 | 120 | 96 |
|
||||
|
||||
The steps use three mailboxes, each with a 25 outgoing limit, so a test crosses a limit in a few requests. They are:
|
||||
`me@` for most steps, `biz@` in step 7 and `helloworld@` in step 9.
|
||||
|
||||
- **These are real mailboxes.** Your own mail today counts on the same counters, and a mailbox taken past 25 stays there until midnight UTC.
|
||||
- **The domain and organisation share one budget of 120 outgoing per day.** It covers every mailbox, and the organisation also has four other domains.
|
||||
The steps add 88 outgoing in all, below the 96 warning. If real mail today adds more, the domain and organisation warn too.
|
||||
- **Do not take the incoming side to its limit.** Incoming is 1000 at every level, so crossing it on a mailbox also crosses it on the domain and the organisation.
|
||||
|
||||
## 1. Build and copy
|
||||
|
||||
On your machine:
|
||||
@@ -65,24 +84,26 @@ service migadu_counters restart
|
||||
## 3. Read the test mailbox's limits
|
||||
|
||||
```
|
||||
counterctl --address test@yourdomain
|
||||
counterctl --address me@dimitrijedimitrijevic.com
|
||||
```
|
||||
|
||||
```
|
||||
LEVEL ID IN LIMIT OUT LIMIT
|
||||
A test@yourdomain 0 200 0 20
|
||||
D yourdomain 0 200 0 20
|
||||
O 1049 0 200 0 20
|
||||
A me@dimitrijedimitrijevic.com 0 1000 0 25
|
||||
D dimitrijedimitrijevic.com 0 1000 0 120
|
||||
O 2741 0 1000 0 120
|
||||
```
|
||||
|
||||
The examples below assume this mailbox: outgoing limit 20, nothing sent today. The warning threshold is 80% of the limit, rounded up, so 16 here.
|
||||
Limits of 1 and 2 have no warning. Adjust `--n` for your own limits.
|
||||
The examples below assume these limits and nothing sent today. The warning threshold is 80% of the limit, rounded up, so 20 for `me@`.
|
||||
Limits of 1 and 2 have no warning. If the counts are not 0 because of your own mail today, lower each `--n` by that amount.
|
||||
|
||||
Also check `biz@` and `helloworld@` with `counterctl --address`. Each should show an outgoing limit of 25.
|
||||
|
||||
## 4. Counting works
|
||||
|
||||
```
|
||||
/tmp/countersend send --route in --recipient test@yourdomain --n 10
|
||||
/tmp/countersend send --route out --auth-user test@yourdomain --recipient someone@gmail.com --n 2
|
||||
/tmp/countersend send --route in --recipient me@dimitrijedimitrijevic.com --n 10
|
||||
/tmp/countersend send --route out --auth-user me@dimitrijedimitrijevic.com --recipient someone@gmail.com --n 2
|
||||
```
|
||||
|
||||
Each run ends in `OK`, exit code 0, and shows what moved:
|
||||
@@ -91,15 +112,15 @@ Each run ends in `OK`, exit code 0, and shows what moved:
|
||||
POST http://localhost:5555/in n=10 concurrency=1 trace ids: countersend-3d66700b-*
|
||||
status: 202=10
|
||||
timing: 1.426ms total, 7011 req/s, p50 80µs, p99 435µs
|
||||
recipient test@yourdomain, incoming
|
||||
recipient me@dimitrijedimitrijevic.com, incoming
|
||||
LEVEL ID BEFORE AFTER CHANGE LIMIT
|
||||
A test@yourdomain 0 10 +10 200
|
||||
D yourdomain 0 10 +10 200
|
||||
O 1049 0 10 +10 200
|
||||
A me@dimitrijedimitrijevic.com 0 10 +10 1000
|
||||
D dimitrijedimitrijevic.com 0 10 +10 1000
|
||||
O 2741 0 10 +10 1000
|
||||
OK
|
||||
```
|
||||
|
||||
`--url http://HOST:5555` sends to another daemon. To check independently, `counterctl --address test@yourdomain` shows the same numbers, and this shows the whole run in the log:
|
||||
`--url http://HOST:5555` sends to another daemon. To check independently, `counterctl --address me@dimitrijedimitrijevic.com` shows the same numbers, and this shows the whole run in the log:
|
||||
|
||||
```
|
||||
grep countersend-3d66700b /var/log/migadu_counters/counting.log
|
||||
@@ -114,7 +135,7 @@ grep countersend-3d66700b /var/log/migadu_counters/counting.log
|
||||
|---|---|
|
||||
| `/tmp/countersend send --route in --recipient someone@countersend.invalid` | `domain not hosted: nothing should move`, `OK` |
|
||||
| `/tmp/countersend send --route in --recipient support@migadu.com` | `exempt address in this request: nothing should move`, `OK` |
|
||||
| `/tmp/countersend send --route in --recipient test@yourdomain --junk` | Changes stay `+0` when `count_junk = false`. `send` does not judge this one. |
|
||||
| `/tmp/countersend send --route in --recipient me@dimitrijedimitrijevic.com --junk` | Changes stay `+0` when `count_junk = false`. `send` does not judge this one. |
|
||||
| `/tmp/countersend send --route in --recipient not-an-address` | `status: 400=1`, `FAIL`, exit 1. That is the daemon correctly refusing it. |
|
||||
|
||||
## 6. The 80% warning and the breach are each sent once
|
||||
@@ -123,76 +144,75 @@ Files appear within a moment of the run. Mailbox outgoing is at 2 after step 4.
|
||||
|
||||
| Command | Counter | New files |
|
||||
|---|---|---|
|
||||
| `send --route out --auth-user test@yourdomain --recipient someone@gmail.com --n 13` | 15 | None |
|
||||
| `send --route out --auth-user me@dimitrijedimitrijevic.com --recipient someone@gmail.com --n 17` | 19 | None |
|
||||
| Same with `--n 1` | | None: refused, nothing sent, exit 1. This is the guard working. |
|
||||
| Same with `--n 1 --allow-notify` | 16 | One `warning` per level |
|
||||
| Same with `--n 3` | 19 | None |
|
||||
| Same with `--n 1 --allow-notify` | 20 | One `limit` per level |
|
||||
| Same with `--n 5` | 25 | None: past the limit nothing is sent again |
|
||||
| Same with `--n 1 --allow-notify` | 20 | One `warning` for `A` |
|
||||
| Same with `--n 4` | 24 | None |
|
||||
| Same with `--n 1 --allow-notify` | 25 | One `limit` for `A` |
|
||||
| Same with `--n 5` | 30 | None: past the limit nothing is sent again |
|
||||
|
||||
Only the mailbox row (`A`) notifies. The domain and organisation end at 30 of 120, below their warning.
|
||||
|
||||
```
|
||||
ls /var/tmp/countersend/notifications
|
||||
```
|
||||
|
||||
```
|
||||
20261110T074614.022873Z-000001-warning-A-o-test@yourdomain.json
|
||||
20261110T074614.022878Z-000003-warning-O-o-1049.json
|
||||
20261110T074614.022920Z-000002-warning-D-o-yourdomain.json
|
||||
20261110T074614.573333Z-000004-limit-A-o-test@yourdomain.json
|
||||
20261110T074614.573359Z-000005-limit-D-o-yourdomain.json
|
||||
20261110T074614.573470Z-000006-limit-O-o-1049.json
|
||||
20261110T074614.022873Z-000001-warning-A-o-me@dimitrijedimitrijevic.com.json
|
||||
20261110T074614.573333Z-000002-limit-A-o-me@dimitrijedimitrijevic.com.json
|
||||
```
|
||||
|
||||
The name is `<UTC time>-<sequence>-<limit|warning>-<level>-<flow>-<id>.json`, and each notification gets its own file, so **two files with the same kind, level, flow and id in one day
|
||||
are a repeat**. Open one to check the values. `count` must be 16 on a warning and 20 on a limit here:
|
||||
are a repeat**. Open one to check the values. `count` must be 20 on a warning and 25 on a limit here:
|
||||
|
||||
```json
|
||||
{
|
||||
"received_at": "2026-11-10T07:46:14.022873Z",
|
||||
"kind": "warning",
|
||||
"level": "A",
|
||||
"id": "test@yourdomain",
|
||||
"id": "me@dimitrijedimitrijevic.com",
|
||||
"flow": "o",
|
||||
"period": "d",
|
||||
"by": "test@yourdomain",
|
||||
"count": "16",
|
||||
"limit": "20",
|
||||
"by": "me@dimitrijedimitrijevic.com",
|
||||
"count": "20",
|
||||
"limit": "25",
|
||||
"percent": "80",
|
||||
"path": "/api/limits/warning",
|
||||
"raw_query": "level=A&id=test%40yourdomain&flow=o&...",
|
||||
"raw_query": "level=A&id=me%40dimitrijedimitrijevic.com&flow=o&...",
|
||||
"remote_addr": "127.0.0.1:55395",
|
||||
"auth_user": "weblogin"
|
||||
}
|
||||
```
|
||||
|
||||
`auth_user` is the login the daemon sent. The password is never stored. Your levels differ if the domain or organisation has other limits or other mail today.
|
||||
`auth_user` is the login the daemon sent. The password is never stored.
|
||||
|
||||
## 7. Concurrent requests still notify once
|
||||
|
||||
Use the incoming side, with enough requests to pass the limit (the current count of 10 and limit of 200 need at least 190):
|
||||
Use a second mailbox with a 25 outgoing limit, and send enough to pass it in one concurrent run:
|
||||
|
||||
```
|
||||
/tmp/countersend send --route in --recipient test@yourdomain --n 220 --concurrency 16 --allow-notify
|
||||
ls /var/tmp/countersend/notifications | grep -- '-i-'
|
||||
/tmp/countersend send --route out --auth-user biz@dimitrijedimitrijevic.com --recipient someone@gmail.com --n 30 --concurrency 16 --allow-notify
|
||||
ls /var/tmp/countersend/notifications | grep biz@
|
||||
```
|
||||
|
||||
Expected: the counters rise by exactly 220, and there is one `warning` and one `limit` file per level.
|
||||
Expected: the counters rise by exactly 30, and there is one `warning` and one `limit` file for `A`, `biz@dimitrijedimitrijevic.com`.
|
||||
The domain and organisation reach 60 of 120 and send nothing.
|
||||
|
||||
## 8. No repeat after a restart
|
||||
|
||||
```
|
||||
service migadu_counters restart
|
||||
/tmp/countersend send --route out --auth-user test@yourdomain --recipient someone@gmail.com --n 3
|
||||
/tmp/countersend send --route out --auth-user me@dimitrijedimitrijevic.com --recipient someone@gmail.com --n 3
|
||||
```
|
||||
|
||||
Expected: the counter continues from where it was and there are no new files.
|
||||
Expected: the counter continues from 30 to 33 and there are no new files.
|
||||
|
||||
## 9. When the web app is unreachable
|
||||
|
||||
Stop `receive` with Ctrl-C, then use a second test mailbox and take it across a limit:
|
||||
Stop `receive` with Ctrl-C, then take a third mailbox across its limit:
|
||||
|
||||
```
|
||||
/tmp/countersend send --route out --auth-user test2@yourdomain --recipient someone@gmail.com --n 20 --allow-notify
|
||||
/tmp/countersend send --route out --auth-user helloworld@dimitrijedimitrijevic.com --recipient someone@gmail.com --n 25 --allow-notify
|
||||
```
|
||||
|
||||
The daemon tries 5 times over about 15 s and then gives up:
|
||||
@@ -205,6 +225,8 @@ fetch -qo - http://127.0.0.1:9095/metrics | grep 'notifications_total.*failed'
|
||||
Expected: a `failed limit exceeded notification ... after 5 attempts` line, and the metric at 1 or more. That notification is not sent later, since delivery is at most once by design.
|
||||
If `admin_addr` is not on `127.0.0.1:9095`, use yours. Start `receive` again afterwards.
|
||||
|
||||
The domain and organisation are now at 88 of 120 outgoing. Any further outgoing test passes their 96 warning.
|
||||
|
||||
## 10. Load
|
||||
|
||||
```
|
||||
@@ -212,23 +234,26 @@ If `admin_addr` is not on `127.0.0.1:9095`, use yours. Start `receive` again aft
|
||||
fetch -qo - http://127.0.0.1:9095/metrics | grep -E '^migadu_counters_(queue_depth|dropped_total)'
|
||||
```
|
||||
|
||||
A `.invalid` recipient tests the HTTP side and the queue without writing to Redis. To load Redis as well, use the test mailbox as `--recipient`, which adds that many real counts and may need `--allow-notify`.
|
||||
A `.invalid` recipient tests the HTTP side and the queue without writing to Redis. Keep it that way here.
|
||||
Using a mailbox on the test domain as `--recipient` would add that many real counts and take the domain and organisation past their 1000 incoming limit.
|
||||
|
||||
Expected: all `202`, `queue_depth` back to 0, and `dropped_total` absent or unchanged. A `503` in the tally means the queue was full.
|
||||
|
||||
## 11. Repeating a test on the same day
|
||||
|
||||
A counter already past a limit will not cross it again, so either use a new test mailbox or clear this one. On the Redis **master**, with the day in UTC (`date -u +%F`):
|
||||
A counter already past a limit will not cross it again, so either use another mailbox or clear this one. On the Redis **master**, with the day in UTC (`date -u +%F`):
|
||||
|
||||
```
|
||||
redis-cli -h MASTER -a PASSWORD DEL cnt/A/test@yourdomain/d/2026-11-10/o ntf/A/test@yourdomain/d/2026-11-10/o/warn ntf/A/test@yourdomain/d/2026-11-10/o/limit
|
||||
redis-cli -h MASTER -a PASSWORD DEL cnt/A/me@dimitrijedimitrijevic.com/d/2026-11-10/o ntf/A/me@dimitrijedimitrijevic.com/d/2026-11-10/o/warn ntf/A/me@dimitrijedimitrijevic.com/d/2026-11-10/o/limit
|
||||
```
|
||||
|
||||
Use `/i` in place of `/o` for incoming. Only delete mailbox (`A`) keys unless the domain and organisation are yours alone, because the `D` and `O` keys hold every mailbox's count.
|
||||
Use `/i` in place of `/o` for incoming. This also clears `me@`'s real mail count for today.
|
||||
Only delete mailbox (`A`) keys. The `D` key holds every mailbox's count on the domain, and the `O/2741` key also holds the organisation's other domains.
|
||||
|
||||
## 12. When you finish
|
||||
|
||||
1. Put the original `[notify]` section back and run `service migadu_counters restart`. Until the web app has `GET /api/limits/warning` deployed, leave `warn_*_url` empty.
|
||||
2. Read the config once more: no notify URL may still contain `127.0.0.1:8099`.
|
||||
3. Stop `receive`, and delete `/var/tmp/countersend/notifications` when you are done reading it.
|
||||
4. What stays behind: the test counts (31 days) and the `ntf/` markers (48 hours). Today's real limits for the test domain are reached sooner because of them.
|
||||
4. What stays behind: the test counts (31 days) and the `ntf/` markers (48 hours). Today `me@`, `biz@` and `helloworld@` are past their outgoing limit,
|
||||
and the domain and organisation 2741 have 88 of 120 outgoing and 10 of 1000 incoming used.
|
||||
|
||||
Reference in New Issue
Block a user