Commit Graph
60 Commits
Author SHA1 Message Date
Wez Furlong 12b3ae51ac fix TSA SuspendTenant rules always set duration to 5 minutes 2024-09-18 09:37:31 -07:00
Wez Furlong bb3a84fff5 provider-summary: make order of C/Q consistent with queue-summary 2024-09-16 18:24:31 -07:00
Wez Furlong a0d9fd7164 kcli: make bounce-list easier to read by default
Sites with lots of tenants and campaigns would produce an overwhelming
amount of output with the default json output mode.

Let's make json opt-in and default to a human readable output
mode that is more concise.

```console
$ kcli bounce-list
ID                                   REASON REMAIN                   BOUNCED CRITERIA
0d2402cc-2dce-44c8-85f6-a4c056300f55 boingo 4m 31s 150ms 560us 575ns  10,990 domain=hotmail.com
```
2024-09-13 08:52:54 -07:00
Wez Furlong be2eeda1f5 the bounce API endpoint is now always asynchronous
In systems with very large numbers of queues, it will take an
effectively unbounded amount of time to produce the initial
summary of results if we were to wait for the bounce to be
applied to every queue.

Let's adjust the output of the kcli to indicate that it is async,
and update the docs which already suggested that the numbers would
be partial to indicate that you can only really consume the id
from the response.
2024-09-13 08:52:54 -07:00
Wez Furlong 2366efad7e kcli queue-summary: show bounce/suspend reason
Include the reason for the bounce/suspension in the status annotation
that we show alongside a queue.

Previously, I considered this to be potentially noisy, but if you
consider that the most likely source of these annotations is likely
to be TSA, having that additional context is helpful.
2024-09-13 08:52:54 -07:00
Wez Furlong ed92367ea9 kcli: queue-summary: fix displaying suspension status
When rendering the suspension and bounce status, the various
queue name component parameters were flipped wrt. to the
suspension and bounce entries, causing them not to match.

This commit fixes that and restores stop sign and trash can
emoji status annotations to the output.
2024-09-13 08:52:54 -07:00
Wez Furlong 9c05e5e681 kcli queue-summary: fixup --limit handling for scheduled queues
The optimization to window over the minimal set wasn't excluding results
in the right way, so let's just remove that; we handle truncating
the overall results at a later stage anyway.
2024-09-13 08:52:54 -07:00
Wez Furlong aecb0d9713 kcli: *summary: use thousands separators for numeric output
Especially with provider-summary, the numbers can be very large
and adding the thousands separators makes them easier for humans
to parse.
2024-09-13 08:52:54 -07:00
Wez Furlong a90445a921 kcli: queue-summary: fixup output mentioning metrics endpoint
We switched from metrics.json to the main metrics endpoint,
so update this help text.
2024-09-13 08:52:54 -07:00
Wez Furlong ab12b9bc6a metrics: add provider rollups
Introduces the following new metrics:

* total_messages_(delivered|fail|transfail)_by_provider
  (labels: provider) - gives aggregates for a given provider/site.
* total_messages_(delivered|fail|transfail)_by_provider_and_source
  (labels: provider, source, pool) - gives aggregates for a given source
  to a specific provider/site.

These queued_count metrics sum the scheduled and ready queue counter
based on the provider, and provider_and_pool:

* queued_count_by_provider
  (labels: provider)
* queued_count_by_provider_and_pool
  (labels: provider, prool)

The provider label in this context is taken from the provider_name that
is set on the associated queue, or if none is set, the site name without
any source or protocol decoration.  This way it is relatively easy to
see at a glance the total queued volume for a given provider/site,
and also to see that broken down by the source *pool*.

And connection counts in a similar veing to the queued_counts:

* connection_count_by_provider
  (labels: provider) - number of connections currently established to
  a provider
* connection_count_by_provider_and_pool
  (labels: provider, pool) - number of connections currently established
  from a pool to a provider.

A new `kcli provider-summary` command shows a provider-centric view of
the queues, using these provider and pool based rollups.

refs: https://github.com/KumoCorp/kumomta/issues/274
2024-09-13 08:52:54 -07:00
Wez Furlong ad9a110920 rustfmt 2024-09-05 08:24:54 -07:00
Wez Furlong 5d4648782d kcli queue-summary: fix D and T columns in output
The recent changes in the streaming metrics parser made these look
at the wrong metric names.
2024-09-05 07:44:35 -07:00
Wez Furlong b384fb73a4 kcli trace-smtp-(client|server): improve usage for busy sites
This commit adds a couple of options that make it a bit easier
to make sense of high traffic environments.

It also fixes an issue with displaying timing: previously, if
we'd never seen the official start of a session, we'd never
show a reasonable time delta, and every record for that session
would be reported as `0ns`.

Now we assume that the first record for a session is as good as
the starting time for the session. That allows us to show
some meaningful timing information in the case that we attach
to an in-flight session for which we missing the start.
2024-09-03 06:25:09 -07:00
Wez Furlong c824985042 deps: upgrade http ecosystem crates so that we're on rusttls 0.23
The blocker for this was axum-server which has been holding us back
for a while. There is now a released version with rustls 0.23 support,
so bump up the various crates in the ecosystem.
2024-09-02 10:42:15 -07:00
Wez Furlong 03c80d5672 kcli top: modularize time series collection
Previously, we had a bunch of individually updated vecs of numbers
and hardcoded logic to translate them all to sparklines in the UI.
This was a bit awkward to maintain and extend.

This commit modularizes all that logic by introducing:

* An Accumulator concept that produces some output value from the
  complete set of input metrics. There are concrete instances of
  the accumulator that look for specific metrics by name, or
  that can aggregate across labelled metrics, or produce composite
  values from multiple different metrics.
* A RateAccumulator that adapts an input accumulator by outputing
  its rate of change.
* TimeSeries which tracks the output of a (possibly composite)
  accumulator
* A Factory concept that can dynamically instantiate a TimeSeries
  based on observed metrics. We use this to show the various
  latency and thread pool metrics.
2024-09-02 10:42:15 -07:00
Wez Furlong 484e8aeb4a kcli: adopt streaming metrics parser for top
This makes performance super fast in the prescence of millions
of queues.
2024-09-02 10:42:15 -07:00
Wez Furlong 285f246bc7 kcli: adopt streaming prometheus parser for queue-summary
This makes it work faster when there are a large number of queues.
2024-09-02 10:42:15 -07:00
Wez Furlong 982c91158a kcli top: adopt tokio interval with skip policy for updates
In situations where the server is under heavy stress, the metrics
endpoint can take longer than the update interval to return.
Over a period of time this can result in a backlog of pending
update requests that put more pressure on the server, and that
will also be late.

This commit switchers to an alternative interval approach that
knows to skip intervals if we're running behind.
2024-08-25 10:24:47 -07:00
Wez Furlong 8c1bfe4c7e kcli: handle list form of json metrics
```
  "scheduled_by_tenant_campaign": {
    "help": "number of messages in the scheduled queue for a specific tenant and campaign combination",
    "type": "gauge",
    "value": [
      {
        "@": 0.0,
        "campaign": "my-campaign",
        "tenant": "my-tenant"
      },
      ]
```
2024-08-22 14:20:16 -07:00
Wez Furlong fedf1c5569 kcli top: switch latency back from p90 to avg
The bucketing in the histograms on a second-to-second
time span makes the p90 less useful; it always just shows
the upper bound of one of the buckets because there's not enough
data in any bucket for the interpolation to show anything else.

We'll need to do some math over a long sampling period than the
kcli update interval for it to be more useful.

So, for now, we're showing the avg.
2024-08-22 11:07:08 -07:00
Wez Furlong d68859969d kcli: make it easier to add and consume histograms
Add a pass over the metrics data to collect the items more dynamically
than previously. This should parse out any newly added metric without
requiring that it be specifically named in the metrics struct in
here, making for less boilerplate.
2024-08-22 11:07:07 -07:00
Wez Furlong a9daff1f42 metrics: kcli: display p90 instead of avg
This commit adjusts the formatting of the json rendition of
histogram buckets, and then teaches kcli how to compute
quantiles over the buckets.

We use that to collect and show the p90 rather than the avg
latency in kcli top.

I want to add more histogram specific presentation options
to kcli in a follow up commit; this is just capturing
the quantile logic.
2024-08-22 11:07:07 -07:00
Wez Furlong b7754fe509 smtp server: add histograms around reading and processing data 2024-08-20 11:06:52 -07:00
Wez Furlong 0d8cbf32c1 smtp server: add overall transaction latency histogram 2024-08-20 10:43:05 -07:00
Wez Furlong 6fcb8ca47e add dkim signing histograms to metrics 2024-08-20 10:03:26 -07:00
Wez Furlong abab4a2759 kcli: add latency metrics to kcli top
I'm not totally happy with how these render, as it looks a little
cluttered, but it's nice to have the rates for the various
events shown along with the average latencies.
2024-08-17 14:24:12 -07:00
Wez Furlong 2b3648326d http injections: track number of receptions
Count them and sum them up with the smtp receptions in kcli
2024-08-15 10:09:18 -07:00
Wez Furlong a00e8d0f0a NEW: add tracing to smtp client, kcli trace-smtp-client
It is now possible to trace outbound SMTP sessions, filtering
by a variety of properties.

Details are in `kcli trace-smtp-client --help` and also in
the docs at /reference/kcli/trace-smtp-client.md

refs: #87
2024-07-11 08:56:25 -07:00
Wez Furlong 5b0d936ef7 docs: improve markdown output for the kcli help 2024-06-27 15:40:39 -07:00
Wez Furlong fa2c6225e8 docs: add kcli reference docs
These are automatically extracted from `kcli --help`.
2024-06-27 15:18:07 -07:00
Wez Furlong 6bb74f88da fix some warnings
These are all harmless; we do rely on printing these things
in Debug impls when under test.
2024-06-25 07:41:40 -07:00
Wez Furlong 785feb4510 cidr: update dep and revise error handling
The upstream cidr crate has a released a version that exposes the more
relaxed parser, so refactor the prior work from
7eb5bdcb5f (which was pointing to a
temporary development branch) to reference its "final form".

This is done by exposing a `parse_cidr` function from our cidr-map
crate, and standardizing all callers to route through that.

refs: https://github.com/stbuehler/rust-cidr/issues/8
2024-06-25 07:34:18 -07:00
Wez Furlong a2d76df7a9 NEW: rebind API and kcli subcommand
refs: https://github.com/KumoCorp/kumomta/issues/209
2024-06-24 12:26:06 -07:00
Wez Furlong 29e4ec312d provide helpful reminder that bouncing is async
closes: https://github.com/KumoCorp/kumomta/issues/191
2024-05-30 16:46:03 -07:00
Wez Furlong 138a1eab72 kcli top: clock the thread pool data during error states
I noticed that these were static while the other time series
were moving to the left, so let's fix that!
2024-05-07 14:14:30 -07:00
Wez Furlong 1554f1bf53 spool: add spoolin pool
This is so that we don't over-saturate the RUNTIME/localset pool during
startup.  I observed that we can block `kcli top` for some time with
the new defaults for localset size, because the spoolin logic was
assuming that it could spawn more tasks than there were localset
threads.

This commit includes some tweaks to allow a thread pool to be short
lived and tear itself down, and some also in `kcli top` so that
we can sanely present the thread pool finishing up and going away.
2024-05-07 12:09:21 -07:00
Wez Furlong 6b98eb1f4b kcli: add a default timeout to internal http requests 2024-05-07 08:46:25 -07:00
Wez Furlong 39dc6c73a7 kcli top: increase min width
Makes the titles look less cluttered when the terminal is large
2024-05-06 20:14:49 -07:00
Wez Furlong bef8baebc2 kcli top: improve layout, add metrics
Add permfail and thread pool utilization metrics.
Make the vertical layout work a bit better.
2024-05-06 20:06:34 -07:00
Wez Furlong 69aa8b9b7c rustfmt 2024-05-04 15:55:54 -07:00
Wez Furlong b8a0b26936 NEW: kcli top
This will shows some TUI sparkline charts of major system metrics
over time.
2024-05-04 13:13:09 -07:00
Wez Furlong e41b4297ea tsa: hook up websocket suspension stream
This commit connects the new websocket based suspension feed
up to shaping.lua. This allows ready-q suspensions to be
enacted in realtime, as well as sets things up to support
scheduled queue suspensions in a later commit.

refs: https://github.com/KumoCorp/kumomta/issues/113
2024-03-28 07:14:36 -07:00
Wez Furlong c40f86e039 Add suppress-logging option to admin bounces
closes: https://github.com/KumoCorp/kumomta/issues/75
2023-11-23 08:36:07 -07:00
Wez Furlong 5bea1013da trace_smtp_server: add colorized output
Makes it easier to see the sent vs. received data
2023-08-13 16:57:00 -07:00
Wez Furlong 4f53566fde trace_smtp_server: show meta keys one per line
This makes it easier to read and see what changed
2023-08-13 16:40:04 -07:00
Wez Furlong c3e6a4fce7 trace_smtp_server: add timestamp to trace events 2023-08-13 15:34:28 -07:00
Wez Furlong 81ff4043e3 add kcli trace-smtp-server subcommand
This allows tracing incoming SMTP sessions.

Sessions are traced through to the cli in realtime.

The implementation is via a websocket, which makes this also potentially
pluggable into a webui in the future, although care must be taken to
ensure that only authorized system operators can enable this, as it can
reveal authentication secrets in the traced dialog, as well as the
content of messages.

This commit doesn't include documentation on the shape of the websocket
JSON at this time.

refs: https://github.com/KumoCorp/kumomta/issues/44

```
; ./target/debug/kcli trace-smtp-server
[127.0.0.1:51778->127.0.0.1:2025] === Connected {"received_from":"127.0.0.1:51778","received_via":"127.0.0.1:2025","reception_protocol":"ESMTP"}
[127.0.0.1:51778->127.0.0.1:2025] <-  220 foo Welcome to KumoMTA!
[127.0.0.1:51778->127.0.0.1:2025]  -> EHLO foo.lan
[127.0.0.1:51778->127.0.0.1:2025] === smtp_server_ehlo: Ok
[127.0.0.1:51778->127.0.0.1:2025] <-  250-foo Aloha foo.lan
[127.0.0.1:51778->127.0.0.1:2025] <-  250-PIPELINING
[127.0.0.1:51778->127.0.0.1:2025] <-  250-ENHANCEDSTATUSCODES
[127.0.0.1:51778->127.0.0.1:2025] <-  250 STARTTLS
[127.0.0.1:51778->127.0.0.1:2025]  -> STARTTLS
[127.0.0.1:51778->127.0.0.1:2025] <-  220 Ready to Start TLS
[127.0.0.1:51778->127.0.0.1:2025]  -> EHLO foo.lan
[127.0.0.1:51778->127.0.0.1:2025] === smtp_server_ehlo: Ok
[127.0.0.1:51778->127.0.0.1:2025] <-  250-foo Aloha foo.lan
[127.0.0.1:51778->127.0.0.1:2025] <-  250-PIPELINING
[127.0.0.1:51778->127.0.0.1:2025] <-  250-ENHANCEDSTATUSCODES
[127.0.0.1:51778->127.0.0.1:2025] <-  250 AUTH PLAIN
[127.0.0.1:51778->127.0.0.1:2025]  -> AUTH PLAIN AHNjb3R0AHRpZ2Vy
[127.0.0.1:51778->127.0.0.1:2025] === smtp_server_auth_plain: Ok: Bool(true)
[127.0.0.1:51778->127.0.0.1:2025] <-  235 2.7.0 AUTH OK!
[127.0.0.1:51778->127.0.0.1:2025] === conn_meta updated to {"authn_id":"scott","authz_id":"scott","received_from":"127.0.0.1:51778","received_via":"127.0.0.1:2025","reception_protocol":"ESMTP"}
[127.0.0.1:51778->127.0.0.1:2025]  -> MAIL FROM:<wez@example.com>
[127.0.0.1:51778->127.0.0.1:2025] === smtp_server_mail_from: Ok
[127.0.0.1:51778->127.0.0.1:2025] <-  250 OK EnvelopeAddress(\"wez@example.com\")
[127.0.0.1:51778->127.0.0.1:2025]  -> RCPT TO:<wez@wezfurlong.org>
[127.0.0.1:51778->127.0.0.1:2025] === smtp_server_rcpt_to: Ok
[127.0.0.1:51778->127.0.0.1:2025] <-  250 OK EnvelopeAddress(\"wez@wezfurlong.org\")
[127.0.0.1:51778->127.0.0.1:2025]  -> DATA
[127.0.0.1:51778->127.0.0.1:2025] <-  354 Send body; end with CRLF.CRLF
[127.0.0.1:51778->127.0.0.1:2025]  -> Date: Sun, 13 Aug 2023 10:10:40 -0700
[127.0.0.1:51778->127.0.0.1:2025]  -> To: wez@wezfurlong.org
[127.0.0.1:51778->127.0.0.1:2025]  -> From: wez@example.com
[127.0.0.1:51778->127.0.0.1:2025]  -> Subject: test Sun, 13 Aug 2023 10:10:40 -0700
[127.0.0.1:51778->127.0.0.1:2025]  -> Message-Id: <20230813101040.1426417@foo>
[127.0.0.1:51778->127.0.0.1:2025]  -> X-Mailer: swaks v20201014.0 jetmore.org/john/code/swaks/
[127.0.0.1:51778->127.0.0.1:2025]  ->
[127.0.0.1:51778->127.0.0.1:2025]  -> This is a test mailing
[127.0.0.1:51778->127.0.0.1:2025]  ->
[127.0.0.1:51778->127.0.0.1:2025]  ->
[127.0.0.1:51778->127.0.0.1:2025]  -> .
[127.0.0.1:51778->127.0.0.1:2025] === smtp_server_message_received: Ok
[127.0.0.1:51778->127.0.0.1:2025] === Message from=wez@example.com to=wez@wezfurlong.org id=5465de7739fc11ee8af250ebf67f93bd
[127.0.0.1:51778->127.0.0.1:2025] === Message queue=wezfurlong.org relay=true log_arf=false log_oob=false
[127.0.0.1:51778->127.0.0.1:2025] === Message meta: {"authn_id":"scott","authz_id":"scott","received_from":"127.0.0.1:51778","received_via":"127.0.0.1:2025","reception_protocol":"ESMTP"}
[127.0.0.1:51778->127.0.0.1:2025] <-  250 OK ids=5465de7739fc11ee8af250ebf67f93bd
[127.0.0.1:51778->127.0.0.1:2025]  -> QUIT
[127.0.0.1:51778->127.0.0.1:2025] <-  221 So long, and thanks for all the fish!
[127.0.0.1:51778->127.0.0.1:2025] === Closed
```
2023-08-13 10:17:04 -07:00
Wez Furlong 29ce975970 kcli: add routing_domain support to bounce API and commands 2023-08-10 22:02:07 -07:00
Wez Furlong fbb140026d kcli queue-summary: use stop emoji rather than pause emoji
It looks clearer and easier to understand than the pause emoji,
especially at normal terminal font sizes.
2023-08-07 08:06:39 -07:00
Wez Furlong 927e18dd58 kcli queue-summary: use emoji to indicate suspensions and bounces
Use the pause emoji for suspensions, and the wastebasket emoji for
bounces.  These are shown in the final column of the respective
sections.

Note that for bounces there will only be a short time window where you
will see a bounced domain show up in the list because the bounce will
remove it from the system fairly quickly.
2023-08-05 13:43:58 -07:00