-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(sink: amqp): add priority property #22243
base: master
Are you sure you want to change the base?
Conversation
Let me see if I can make Templating work here... It would prevent a future breaking change here |
Sounds good. (Although, I don't think the change would be breaking since the config would accept both constants and templated values.) |
Yeah, exactly. Templates can just be raw literals like |
Fair enough; my thinking currently is to make it default to
Would that be better than a runtime error, in the event that the template renders an invalid type? I'm working on a integration test (with templating) right now. |
Good question 🤔 Typically for "template errors" we consider them fatal and drop the event, but I can see the argument here that there is a safe default. I'd be 👍 to falling back to that default and just emitting a warning if the template fails to render correctly (rather than an error). |
I updated the configuration to allow templating of sources:
in:
type: stdin
transforms:
prioritize:
type: remap
inputs:
- in
source: |
.priority = random_int(1, 10)
sinks:
sink_amqp:
type: amqp
inputs:
- prioritize
connection_string: amqp://user:password@127.0.0.1:5672/%2f?timeout=10
exchange: example
encoding:
codec: json
properties:
priority: "{{ .priority }}" Because it is treated as a string, it must be
I also added integration tests for the various cases. I did not cover the case where an invalid template drops the event; if you could point me to an example on how to catch dropped events through instrumentation/counters I could add a case for that. |
First of all, thanks for extending this and including the tests 👍
Hmm, this is not great UX, especially since the rabbitmq docs clearly ask for a number. Still if we extend templating to accept numbers as well it improve the UX automatically. Maybe worth adding a note to the docs so users aren't surprised cc @jszwedko |
Agreed, the UX here isn't great for literals. Could we change the way Again, happy to see the original PR go in without template support if you don't want to take that on right now 🙂 |
Agreed, I will give it a shot! |
I pushed a solution for the configuration of numeric values as optional templates:
There could be a performance optimization done for numeric values to skip the For serialization, it is simply converting to a Tested with both configs: sinks:
sink_amqp:
type: amqp
inputs:
- prioritize
connection_string: amqp://user:password@127.0.0.1:5672/%2f?timeout=10
exchange: example
encoding:
codec: json
properties:
priority: 1 sinks:
sink_amqp:
type: amqp
inputs:
- prioritize
connection_string: amqp://user:password@127.0.0.1:5672/%2f?timeout=10
exchange: example
encoding:
codec: json
properties:
priority: "{{ .priority }}" Also, here is the warning message when the template evaluates to a non-numeric or negative value:
And when it evaluates to an out-of-bounds value above 255:
On an invalid template, such as a missing field (dropped):
|
Summary
Provides the option to set the
priority
of messages sent by theamqp
sink. RabbitMQ documentation.Priority is a useful way to order messages when they are sent to the same exchange/queue through different sinks.
The property is a numeric value (
u8
) that also allows templating. The template must resolve to an integer between0-255
, otherwise the priority will not be set on the message (default behavior is priority0
). An invalid template will log and drop the event.Change Type
Is this a breaking change?
How did you test this PR?
x-max-priority
argument set (values up to 5 recommended).amqp
sink in Vector, publishing to theexchange
and withproperties.priority
configured. It can be a template: ("{{ .priority }}"
), or a constant:1
.Does this PR include user facing changes?
Checklist
make check-all
is a good command to run locally. This check isdefined here. Some of these
checks might not be relevant to your PR. For Rust changes, at the very least you should run:
cargo fmt --all
cargo clippy --workspace --all-targets -- -D warnings
cargo nextest run --workspace
(alternatively, you can runcargo test --all
)Cargo.lock
), pleaserun
dd-rust-license-tool write
to regenerate the license inventory and commit the changes (if any). More details here.References