Commit Graph
1851 Commits
Author SHA1 Message Date
Wez Furlong f0fdec1eb0 fixup and fully migrate to metrics 0.22
Commit 12fe5e3b61 updated the
metrics related crates, but not in every one of our crates,
which meant that we were running with a mixture of 0.20
and 0.22.

The result of this was that the memory related metrics
were no long visible to the published prometheus data
because it was only looking at the other version of
the metrics crate!

This commit switches over to using a workspace dep
for metrics so that we update all related crates
together.
2024-04-10 10:02:29 -07:00
Wez Furlong e0326e4c39 queue: make bounce_all do spool removal async
I think we've gone back and forth on this a couple of times.
The motivation for this commit is that we've been troubleshooting
an issue that seems to be triggered by bouncing all the mail.
The symptom is that the system becomes unresponsive after
triggering the bounce.

Here in the context of `bounce_all`, the queue lock is held
so that we can capture the messages, but then we serially
remove them from the spool, so that we can report the total
number back to the originating HTTP request.

For a large queue size that presents a big point of contention
for other tasks or requests that may need to operate on the
queue.

This commit moves that spool removal into another task so that
that task can run asynchronously and independently from the
bounce HTTP request.

The consequence of this is that the numbers reported by the
bounce request will likely be lower than the final count.
The `bounce-list` kcli command can be used to check up on
those numbers.
2024-04-10 08:10:03 -07:00
Wez Furlong 0a831f60de mta-sts: reduce scope of cache lock
We've been troubleshooting a lockup on a system with a low core count.
What we found in a stack trace was that one of the threads was blocking
on the CACHE mutex in the sts logic.  That mutex is intended to be
short-duration in scope, managing the direct lookup or insertion
into the cache, and no more.

However, due to the the way that rust scopes the lifetime of the
MutexGuard that is acquired from the CACHE, we were holding it
across the async DNS operation that is used to validate that
a cached policy is still current.

This can result in a deadlock on a system with a sufficiently
low core count/high enough concurrent volume of traffic to sites
with MTA-STS enabled.

This commit resolves this by introducing a lookup function that
explicitly clones the cached policy without returning a MutexGuard.
2024-04-10 07:23:03 -07:00
Wez Furlong 7632b10ff8 localset: respect TOKIO_WORKER_THREADS concurrency override
This is to aid in replicating issues where the system core
count is lower than the test system.
2024-04-10 06:39:46 -07:00
Wez Furlong e81a5fb6ca fix: msg:set_scheduling didn't immediately recompute due time 2024-04-09 14:34:38 -07:00
Wez Furlong 4cbe681d8d msg: remove stray debug prints from scheduling logic 2024-04-09 14:32:30 -07:00
Mike Hillyer d282ac61ac Documenting Add support for Routing_Domain in the Queues helper. #141 2024-04-08 13:17:17 -04:00
Wez Furlong d05b9136d2 cargo update 2024-04-05 09:16:03 -07:00
Wez Furlong a230e78ce6 add helper script for analyzing stack traces 2024-04-03 07:54:09 -07:00
Mike Hillyer c3cf0d4666 Update shaping based on Comcast documents, add stack trace information to the documentation. 2024-04-03 10:08:43 -04:00
Wez Furlong 5399a833bd Revert "docs: restore social previews"
This reverts commit 69976b5362.

It didn't seem to take and I don't care to troubleshoot this today.
2024-03-31 14:32:21 -07:00
Wez Furlong 898ed52410 add msg:append_text_html and msg:append_text_html
These can be used to insert tracking pixels/links.

closes: https://github.com/KumoCorp/kumomta/issues/120
2024-03-31 14:04:46 -07:00
Wez Furlong bd036a204b mailparsing: introduce PartPointer
This is vaguely reminiscent of a json pointer reference that
symbolically identifies a node in a tree using a sequence of
integers to indicate the child node index by tree level.

The simplified structure method has been re-implemented in terms
of PartPointer.

It is possible to resolve a PartPointer to its associate MimePart
for both mutable and immutable access.

refs: https://github.com/KumoCorp/kumomta/issues/117
refs: https://github.com/KumoCorp/kumomta/issues/120
2024-03-31 09:18:21 -07:00
Wez Furlong 1fb712e2bf Add msg:set_data()
This method allows replacing the message payload arbitrarily.
This is a building block for more advanced and convenient
modification operations.

refs: https://github.com/KumoCorp/kumomta/issues/117
refs: https://github.com/KumoCorp/kumomta/issues/120
2024-03-31 06:57:59 -07:00
Wez Furlong edc56226f7 docs: always pull upstream mkdocs 2024-03-31 06:49:14 -07:00
Wez Furlong 69976b5362 docs: restore social previews
The underlying issue has now been resolved
2024-03-31 06:41:25 -07:00
Wez Furlong e94506fd96 Add new Rejection log event
We skip logging the 421 we generate while shutting down because
it feels a bit redundant; you'll see the server shutting down
in the journal anyway.

refs: https://github.com/KumoCorp/kumomta/issues/88
2024-03-29 16:37:37 -07:00
Wez Furlong 3207c45f3d expose inject_v1 API via lua
closes: https://github.com/KumoCorp/kumomta/issues/102
2024-03-29 09:06:54 -07:00
Wez Furlong 755eb848e2 add glob, read_dir
closes: https://github.com/KumoCorp/kumomta/issues/161
2024-03-29 08:25:51 -07:00
Wez Furlong d4af7c7ce8 trace: increase channel capacity
While inbound tracing isn't intended to be used to trace 100%
of production traffic, it is useful to be able to accomodate
a bit more than very basic levels.

Increasing the capacity here will allow for that, at the cost of
a little bit of residual RAM.
2024-03-28 17:54:39 -07:00
Wez Furlong 4d48db612e docs: nth time's the charm 2024-03-28 15:09:49 -07:00
Wez Furlong 697435c283 docs: second attempt... 2024-03-28 14:53:33 -07:00
Wez Furlong 4d3368c744 docs: disable social plugin due to google font breakage
refs: https://github.com/squidfunk/mkdocs-material/issues/6983
2024-03-28 14:48:19 -07:00
Wez Furlong 0c5794ba31 TSA: Add SuspendTenant, SuspendCampaign
refs: https://github.com/KumoCorp/kumomta/issues/113
2024-03-28 13:08:45 -07:00
Wez Furlong 47cda59f1b tsa: remove local re-resolve of site-name
The rationale was that this would be more robust, but as it turns out,
it may result in discrepenancies with the incoming site_name that
affect how we match back for suspensions.

I saw localhost getting over-resolved in the integration tests so
that it would no longer match.

Let's just KISS and trust the incoming data.
2024-03-28 07:26:36 -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 083913f5e4 tsa: add websocket subscription to suspension data
refs: https://github.com/KumoCorp/kumomta/issues/113
2024-03-28 07:14:36 -07:00
Wez Furlong 39de0e33a6 Expose suspension API to lua
This is very similar to the HTTP suspension API, with the
difference that the suspend method returns just the uuid rather
than the entire suspension object.

refs: https://github.com/KumoCorp/kumomta/issues/113
2024-03-28 07:14:35 -07:00
Wez Furlong 403f80ac26 simple_policy/sink: use temporary file for acct db
These files are used by me (wez!) while hacking things together locally
as a non-privileged user (myself).  They should not contribute to the
overall message accounting database.  Let's give each instantiation a
separate temporary path.
2024-03-28 07:14:35 -07:00
Wez Furlong be80391239 add kumo.http.connect_websocket
refs: https://github.com/KumoCorp/kumomta/issues/113
2024-03-28 07:14:35 -07:00
Wez Furlong 6003976a10 new: kumo.spawn_task function
This function will spawn a new thread that runs a tokio
localset, which in turn will trigger the specified event
and run it.

On it's own it doesn't do a lot, but it provides a way
to perform background tasks in lua.

```lua
kumo.on('init', function()
  kumo.spawn_task {
    event_name = 'my.task',
    args = { 'hello', 'there' },
  }
end)

kumo.on('my.task', function(args)
  -- Prints: `I am the task.  ["hello","there"]`
  print('I am the task.', kumo.json_encode(args))
end)
```
2024-03-28 07:14:35 -07:00
Wez Furlong b0bba25247 tsa: add separate suspension concept
This is the start of unbundling and unwinding the mild hack
that was adding a suspended configuration state.  At the time
that was implemented, there was no plan in place for handling
stuff other than configuration updates for TSA rules.

I have a simple but powerful plan in mind, so let's start
breaking this back out!

refs: https://github.com/KumoCorp/kumomta/issues/113
2024-03-28 07:14:35 -07:00
Wez Furlong 1b451e3acf deps: cargo update 2024-03-28 06:56:31 -07:00
Wez Furlong 0dd1cd0731 deps: update k9 2024-03-28 06:56:10 -07:00
Wez Furlong 12fe5e3b61 deps: update metrics related deps 2024-03-28 06:53:24 -07:00
Wez Furlong c42f0776de deps: update criterion, and fixup dkim benchmarks
This has the side effect of clearing one minor
issue in cargo audit.
2024-03-28 06:44:27 -07:00
Wez Furlong a0b00b2d15 fixup tests for 2fbd9d4c4c 2024-03-27 17:23:53 -07:00
Wez Furlong 1df9948397 fixup low traffic case for maintainer dispatch
I broke this in 3d12702605.
The fix is simple; we just need to trigger the maintain
method when the maintainer starts up.
2024-03-27 17:20:48 -07:00
Wez Furlong 2fbd9d4c4c add provisional knob to control how aggressive we are at open connections
I'm not sure if I want to keep this, but it is currently useful for
testing purposes.

The previous logic was to skip opening an SMTP connection in a
newly constructed Dispatcher if no messages were immediately
available in the ready queue.

This logic makes a lot of sense in a multi-node deployment
with shared throttles, so that other nodes have an opportunity
to open connections to drain their own queues, but when testing
a single node it leaves some throughput on the table.

This boolean option allows selecting whether we aggressively
continue to open an SMTP connection even if we may not have
a message ready to send yet, or, if left at the default `false`
value, continue with the original more conservative logic.
2024-03-27 16:33:18 -07:00
Wez Furlong 3d12702605 amortize ready-q maintainer triggers
Previously, every insertion into the ready queue would cause the
maintainer logic to run in the context of the submitting thread.

For busy, high-concurrency systems this could result in multiple
dispatches of the maintainer for the same queue in quick succession.

This commit adjusts the triggering logic so that the existing
background maintainer task will be woken up to perform those
actions.

This reduces the number of redundant calls to the maintainer,
without harming latency.
2024-03-27 16:33:18 -07:00
Wez Furlong 889cd8223a fix smtp client idle behavior
The intent of the idle behavior is to linger for up to the configured
idle_timeout value, waiting for new messages to arrive in the ready
queue.

The actual behavior was to initiate a wait, but when woken up,
if there were no messages in the ready queue, the connection
would close out, even if there was still time that could be
waited out before the idle period was up.

This commit adds in a loop that will keep the connection open
until the idle timeout is reached, which in turn will improve
throughput, especially if the traffic is a little bursty.
2024-03-27 16:33:18 -07:00
Wez Furlong 661ce43c15 bug: math in ideal_connection_count yields too-big values
This isn't a proper fix, but a bandaid.  When the max connection limit
is large (eg: 1024), the calculation here can produce numbers larger
than the current queue size, which can result in surging to spawn
dispatchers which then realize that they have no work to do, on each
queue insertion operation.

This commit clamps the ideal number to be no larger than the current
queue size.

Will need to follow up on this with the correct math.

On more reasonable queue sizes (such as those covered by the unit
tests), the numbers are reasonable.
2024-03-27 16:33:18 -07:00
Wez Furlong 64ae007654 Add total_messages_received prometheus metric 2024-03-27 16:33:17 -07:00
Wez Furlong 309ea8207a Add back-pressure to enqueue during SMTP reception
I'd previously made the enqueue operation async wrt. the incoming
session, which produced better looking reception metrics, but which
really was causing messages to queue implicitly in the tokio
task queue, where it is not able to participate in our memory
management strategy.

Meanwhile, the client gets a 250 OK and works on sending the
next message.

Let's switch back to absorbing the enqueue cost prior to returning
the 250 OK.
2024-03-27 16:33:17 -07:00
Wez Furlong 15b1fab110 checkpoint some local testing/hacking in my test configs 2024-03-27 16:33:17 -07:00
Wez Furlong 2bc409e5ec deps: reqwest -> 0.12
closes: https://github.com/KumoCorp/kumomta/pull/160
2024-03-26 06:47:56 -07:00
Wez Furlong 584334e30b deps: make reqwest a workspace dependency 2024-03-26 06:46:07 -07:00
Wez Furlong 9d8bd65c49 add tests for and optimize remove_line_break
refs: #157
2024-03-25 14:57:15 -07:00
Wez Furlong abd030cc2c docs: changelog for #157
refs: #157
2024-03-25 14:56:41 -07:00
Nathalie Caiandncai 5ffcd1af5e add serializer for response content field (#157)
* add serializer for response content field

* update formatting

---------

Co-authored-by: ncai <ncai@chapsvision.com>
2024-03-25 14:32:41 -07:00