Commit Graph
16 Commits
Author SHA1 Message Date
Wez Furlong baa95fbbb0 log_hooks: add optional pre-filter function
This is useful if your hooks have interior logic to decide to
filter out a given record.  For example, you might have multiple
hook endpoints but only messages with certain headers/metadata
should be routed to any one of them for a specific event.

Without the ability to pre-filter, we need to pay the cost of
spooling the event speculatively, and then skipping it when
processing logging for the (hopefully!) batch.

Using pre-filter you can cut out that overhead.

This is not yet documented; we're getting this in to get
some feedback before we finalize this interface.
2026-04-03 09:50:13 +01:00
Wez Furlong 53a6bc3b7e log_hooks: add helper for creating a disposition hook 2025-09-09 10:39:52 +01:00
Wez Furlong 979e69fb8c add min_batch_size and max_batch_latency to lua delivery handler
Previously, we added `batch_size` which acts as a maximum batch
size; this was the simplest possible way to achieve batching
with a constrained upper bound with no additional latency.

This commit introduces a minimum batch size and a maximum latency.
The behavior for delivery handlers that configure min_batch_size > 1
is that once we've started a batch, we'll allow for up to
max_batch_latency time to pass to accumulate more messages into
the batch before we just go ahead and send it.

If you wanted to batch say 5,000-10,000 messages per batch or whatever
you get in a 10 second time period you would set:

* min_batch_size = 5000
* batch_size = 10000
* max_batch_latency = "10s"

Note that the default idle_timeout in the product is "5s" so if you want
max_batch_latency to be effective you will also need to increase the
idle_timeout in your shaping configuration/egress path config for that
handler.
2024-11-14 08:54:14 -07:00
Laurent Marchaud 6142808730 fix a few typos in the docs
Signed-off-by: Laurent Marchaud <laurent@marchaud.com>
2024-10-24 12:10:53 -04:00
Wez Furlong 5e1ae20497 Add batching support for log hooks
This really is adding batching support to custom lua delivery
protocol handlers, but the main use case for these today is
to implement log hooks.

The way that it works is that you can specify a `batch_size`
as part of setting up the lua protocol handler.

Then, when it is time to send messages, if the batch_size is
the default of 1, the lua delivery logic will invoke the `send` method
on the connection object returned from the constructor.  This
is the same as the behavior from before this commit.

However, if the batch_size is greater than 1, then the lua delivery
logic will instead attempt to collect up to batch_size messages
that are immediately available from the ready queue, and then pass
those to a new `send_batch` method.

The send_batch method accepts an array of messages; that array will
always have at least one message, and up to batch_size messages,
depending on the throughput and queue size.

If the send_batch method's return value applies equally to all
messages in the batch, so if it indicates that something failed,
that disposition will apply to all messages.

One of the reasons that I'd avoided implementing batching thus far
was that it makes it awkward to resolve persistent/recurring issues
that are due to a single message in that batch.  If the batch is
always retried together then there is a good chance that it will
always fail together.

There's no explicit mitigation for that issue here, but it may
be probablistically mitigated by the jitter that is applied to
messages that transiently fail.  If a batch transiently fails,
each message in that batch will be subject to its own random
jitter which should cause an offending message to be retried
with a different subset of messages next time around.

The integration test included here demonstrates the batching
working with an http log hook implementation.
2024-09-16 18:14:25 -07:00
aryeh a43fcd6972 Patch bug in log_hooks.lua (#244)
* Patch bug in log_hooks.lua

connection:close was inserted in the wrong place and should be inside the constructor function with the connection object.
2024-07-25 09:48:02 -07:00
Wez Furlong ec795b71d3 mod-http: add client:close() method
Allows explicit closure of any cached connections in the client
object.

Make use of this in the log_hooks:new_json method.
2024-07-09 13:57:46 -07:00
Wez Furlong 426b5b8d31 log_hooks: add typing
This will perform more explicit checks to make sure that the name
is defined and so on. It also now will check for conflicting
log hook names as well.

refs: #211
2024-06-28 12:31:49 -07:00
Wez Furlong fa51666051 add log_hooks:new_json shortcut
Basic usage is as simple as:

```lua
local log_hooks = require 'policy-extras.log_hooks'

log_hooks:new_json {
  name = "webhook",
  url = "http://10.0.0.1:4242/log",
}
```
2023-11-14 15:06:48 -07:00
Wez Furlong 4ac3b4e21b log_hooks: set retry_interval to 1m, with max 20m 2023-11-14 14:55:22 -07:00
ncai 9d0105e51d use logRecord reception_protocol to avoid loop 2023-11-07 13:11:59 -07:00
Wez Furlong d969f87571 multi hooks: use bare return rather than return nil
The way we test whether logs should continue is by looking for
an empty return statement, so we shouldn't `return nil` for these
otherwise we'll indicate that we definitively can't resolve the
queue configuration.
2023-11-06 14:39:37 -07:00
Wez Furlong ac7ef32cd3 log_hooks: fix returning the module 2023-11-06 09:50:25 -07:00
Wez Furlong 951cad53e8 log_hooks: simplify logic and comments a little 2023-11-06 08:46:35 -07:00
Wez Furlong dd93465870 log_hooks: a couple of minor fixes/tweaks 2023-11-06 08:39:31 -07:00
Wez Furlong af92443f7e policy-extras: add log_hooks helper
This should simplify the process of adding log hooks.
2023-11-06 08:31:52 -07:00