Commit Graph
72 Commits
Author SHA1 Message Date
Dirkjan Ochtman 16c73dfff8 Drop direct tungstenite dependency in favor of tokio-tungstenite 2024-11-13 13:50:27 -07:00
Dirkjan Ochtman 18db31f204 Manage all external dependencies at the workspace level 2024-11-13 13:50:27 -07:00
Wez Furlong a510e0d90c fix kcli double counting the ready queue size 2024-11-07 16:29:11 -07:00
Dirkjan Ochtman 6c37410042 Use a workspace dependency for serde 2024-10-15 06:04:53 -07:00
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 03afe2080a metrics: improve /metrics and /metrics.json endpoint performance
Up until now we've been using the upstream prometheus crate for all of
our metrics.  However, in recent tests with over 1 million scheduled
queues, we've been observing that the latency of the metrics collection
endpoints has been in the 10's of second range.

Looking more deeply at the prometheus crate we can see that its gather
operation works by assembling an array of arrays of individual metrics,
where each of the inner arrays has its own owned copy of the metric
labels and values; there's a lot of duplication of data here.

When there are millions of metrics this data model represents a
non-trivial resource overhead both in terms of RAM and in terms of the
time and CPU it consumes to construct this data.  That data is then
passed on to a renderer that produces either a single contiguous text
buffer of >100MB (for the prometheus exposition format), or an
intermediate JSON object structure for the json format, before then
returning it via the HTTP endpoint.

This commit seeks to address this issue by introducing a streaming
metric collection interface that allows data to incrementally gathered,
encoded and sent to the requestor.

To do this, we have our own registry for Counter and Gauge metrics. They
are both the same type to minimize boilerplate, but they report their
prometheus metric type appropriately.

We can construct either pruning or retaining registries for specific
named counters.  The keys are strongly typed both to avoid
mis-labelling bugs and also to avoid needing to store duplicate copies
of the label key names or values.  This makes it a little less convenient
to index the counter registry, but we were already wrapping that
up behind accessor functions anyway.

The collection operation directly encodes the text or json to a series
of 4k buffers that then get streamed out to the client. We currently
make no effort to escape or encode the counter names in the interest
of raw speed. That's fine because we don't have any counter names
that require encoding.

With these changes the latency of a `/metrics` fetch when >1 million
queues are present falls from a highly variable 10+seconds (I've seen as
high as 44s!) to a more reasonable 0.5s-0.75s spread:

```
; time curl -s 'http://127.0.0.1:8000/metrics' > /tmp/metrics && ls -lh /tmp/metrics
curl -s 'http://127.0.0.1:8000/metrics' > /tmp/metrics  0.01s user 0.18s system 32% cpu 0.567 total
-rw-r--r-- 1 wez wez 124M Aug 31 13:52 /tmp/metrics
```

The `/metrics.json` endpoint had worse latency prior to these changes,
but now has similar latency to `/metrics`.

```
; time curl -s 'http://127.0.0.1:8000/metrics.json' > /tmp/metrics.json && ls -lh /tmp/metrics.json
curl -s 'http://127.0.0.1:8000/metrics.json' > /tmp/metrics.json  0.01s user 0.10s system 18% cpu 0.589 total
-rw-r--r-- 1 wez wez 72M Aug 31 13:53 /tmp/metrics.json
```

With compression, the latency is higher because the compression takes
additional work at the default compression level:

```
; time curl -H 'Accept-encoding: gzip' -s 'http://127.0.0.1:8000/metrics' > /tmp/metrics.gz && ls -lh /tmp/metrics.gz
curl -H 'Accept-encoding: gzip' -s 'http://127.0.0.1:8000/metrics' >   0.02s user 0.06s system 4% cpu 1.607 total
-rw-r--r-- 1 wez wez 11M Aug 31 13:53 /tmp/metrics.gz
```

```
; time curl -H 'Accept-encoding: gzip' -s 'http://127.0.0.1:8000/metrics.json' > /tmp/metrics.json.gz && ls -lh /tmp/metrics.json.gz
curl -H 'Accept-encoding: gzip' -s 'http://127.0.0.1:8000/metrics.json' >   0.02s user 0.06s system 4% cpu 1.569 total
-rw-r--r-- 1 wez wez 10M Aug 31 13:53 /tmp/metrics.json.gz
```

Using Fastest compression (which is what landed in main prior to this
commit), those latencies are cut by almost 50%, hovering around 0.7s but
I did see as high as 1s:

```
; time curl -H 'Accept-encoding: gzip' -s 'http://127.0.0.1:8000/metrics' > /tmp/metrics.gz && ls -lh /tmp/metrics.gz
curl -H 'Accept-encoding: gzip' -s 'http://127.0.0.1:8000/metrics' >   0.02s user 0.04s system 8% cpu 0.727 total
-rw-r--r-- 1 wez wez 14M Aug 31 14:12 /tmp/metrics.gz

; time curl -H 'Accept-encoding: gzip' -s 'http://127.0.0.1:8000/metrics.json' > /tmp/metrics.json.gz && ls -lh /tmp/metrics.json.gz
curl -H 'Accept-encoding: gzip' -s 'http://127.0.0.1:8000/metrics.json' >   0.01s user 0.05s system 7% cpu 0.789 total
-rw-r--r-- 1 wez wez 13M Aug 31 14:12 /tmp/metrics.json.gz
```

The use of compression in kcli remains disabled in favor of lower
latency for queue-summary and top, however, I think there's plenty of
scope for optimizing both of those subcommands use of metrics, which is
something for a follow-up commit.
2024-09-02 10:42:14 -07:00
Wez Furlong b2c121d911 add support for compressed http output
The client needs to request this via Accept-Encoding.
We support either gzip or deflate; we want this to be
as cheap as possible to compress.

Note that this doesn't enable requesting compressed output in
kcli, because compression increases the latency around collecting
metrics and we want that (typically locally-run) command to have
lower latency for queue-summary and top.
2024-09-02 10:42:14 -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 584334e30b deps: make reqwest a workspace dependency 2024-03-26 06:46:07 -07:00
dependabot[bot] 10d14ed2c1 build(deps): bump the all group with 9 updates
Bumps the all group with 9 updates:

| Package | From | To |
| --- | --- | --- |
| [tempfile](https://github.com/Stebalien/tempfile) | `3.10.0` | `3.10.1` |
| [strum](https://github.com/Peternator7/strum) | `0.26.1` | `0.26.2` |
| [chrono](https://github.com/chronotope/chrono) | `0.4.34` | `0.4.35` |
| [clap](https://github.com/clap-rs/clap) | `4.5.1` | `4.5.2` |
| [reqwest](https://github.com/seanmonstar/reqwest) | `0.11.24` | `0.11.25` |
| [env_logger](https://github.com/rust-cli/env_logger) | `0.11.2` | `0.11.3` |
| [log](https://github.com/rust-lang/log) | `0.4.20` | `0.4.21` |
| [pest](https://github.com/pest-parser/pest) | `2.7.7` | `2.7.8` |
| [pest_derive](https://github.com/pest-parser/pest) | `2.7.7` | `2.7.8` |


Updates `tempfile` from 3.10.0 to 3.10.1
- [Changelog](https://github.com/Stebalien/tempfile/blob/master/CHANGELOG.md)
- [Commits](https://github.com/Stebalien/tempfile/compare/v3.10.0...v3.10.1)

Updates `strum` from 0.26.1 to 0.26.2
- [Release notes](https://github.com/Peternator7/strum/releases)
- [Changelog](https://github.com/Peternator7/strum/blob/master/CHANGELOG.md)
- [Commits](https://github.com/Peternator7/strum/commits)

Updates `chrono` from 0.4.34 to 0.4.35
- [Release notes](https://github.com/chronotope/chrono/releases)
- [Changelog](https://github.com/chronotope/chrono/blob/main/CHANGELOG.md)
- [Commits](https://github.com/chronotope/chrono/compare/v0.4.34...v0.4.35)

Updates `clap` from 4.5.1 to 4.5.2
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.5.1...v4.5.2)

Updates `reqwest` from 0.11.24 to 0.11.25
- [Release notes](https://github.com/seanmonstar/reqwest/releases)
- [Changelog](https://github.com/seanmonstar/reqwest/blob/master/CHANGELOG.md)
- [Commits](https://github.com/seanmonstar/reqwest/compare/v0.11.24...v0.11.25)

Updates `env_logger` from 0.11.2 to 0.11.3
- [Release notes](https://github.com/rust-cli/env_logger/releases)
- [Changelog](https://github.com/rust-cli/env_logger/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-cli/env_logger/compare/v0.11.2...v0.11.3)

Updates `log` from 0.4.20 to 0.4.21
- [Release notes](https://github.com/rust-lang/log/releases)
- [Changelog](https://github.com/rust-lang/log/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/log/compare/0.4.20...0.4.21)

Updates `pest` from 2.7.7 to 2.7.8
- [Release notes](https://github.com/pest-parser/pest/releases)
- [Commits](https://github.com/pest-parser/pest/compare/v2.7.7...v2.7.8)

Updates `pest_derive` from 2.7.7 to 2.7.8
- [Release notes](https://github.com/pest-parser/pest/releases)
- [Commits](https://github.com/pest-parser/pest/compare/v2.7.7...v2.7.8)

---
updated-dependencies:
- dependency-name: tempfile
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all
- dependency-name: strum
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all
- dependency-name: chrono
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all
- dependency-name: clap
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all
- dependency-name: reqwest
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all
- dependency-name: env_logger
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all
- dependency-name: log
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all
- dependency-name: pest
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all
- dependency-name: pest_derive
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-11 07:01:49 -07:00