Add hook HookQueueStateCount + read middleware as hooks and vice versa#1203
Open
Add hook HookQueueStateCount + read middleware as hooks and vice versa#1203
HookQueueStateCount + read middleware as hooks and vice versa#1203Conversation
af432f2 to
f202436
Compare
brandur
added a commit
to riverqueue/rivercontrib
that referenced
this pull request
Apr 12, 2026
See [1] for context, but here we implement `HookQueueStateCount` in the existing OTEL middleware so that it can emit metrics around queue counts, a pretty handy feature that we have on definitive request for, but which I'd guess most River users would like to have access to. [1] riverqueue/river#1203
Contributor
Author
|
@codex review |
f202436 to
109e1fe
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f2024369e5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
7266cb8 to
b7694fa
Compare
brandur
added a commit
to riverqueue/rivercontrib
that referenced
this pull request
Apr 12, 2026
See [1] for context, but here we implement `HookQueueStateCount` in the existing OTEL middleware so that it can emit metrics around queue counts, a pretty handy feature that we have on definitive request for, but which I'd guess most River users would like to have access to. [1] riverqueue/river#1203
Here, add a new hook called `HookQueueStateCount` which gets invoked to produce job queue count statistics. We do this by adding a new maintenance service which like other maintenance services, runs only on the leader, so we only have one client performing counts at any given time. Furthermore, in order to not introduce a potential operational problem without opt-in from River users, the counts only run if a `HookQueueStateCount` hook/middleware has been added to the client. The reason we do all this to to implement a feature requested by one of users: for `otelriver` in contrib to be able to emit queue count metrics, which seems like a pretty reasonable ask for the package to be able to do, and something that every River user would likely want access to in their ops charts. A slight oddity, but which I think is _probably_ okay, is that the new hook ideally stays a hook, but the existing `otelriver` middleware is a middleware. It'd be nice not to have to put `otelriver.Middleware` into both a client's `Hooks` and `Middleware` configuration, so we modify client to allow for hooks that middleware and middleware which are hooks. This lets `otelriver.Middleware` continue doing what it was already doing, but also to start producing new counts as a hook.
b7694fa to
3d3c21a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Here, add a new hook called
HookQueueStateCountwhich gets invoked toproduce job queue count statistics. We do this by adding a new
maintenance service which like other maintenance services, runs only on
the leader, so we only have one client performing counts at any given
time. Furthermore, in order to not introduce a potential operational
problem without opt-in from River users, the counts only run if a
HookQueueStateCounthook/middleware has been added to the client.The reason we do all this to to implement a feature requested by one of
users: for
otelriverin contrib to be able to emit queue countmetrics, which seems like a pretty reasonable ask for the package to be
able to do, and something that every River user would likely want access
to in their ops charts.
A slight oddity, but which I think is probably okay, is that the new
hook ideally stays a hook, but the existing
otelrivermiddleware is amiddleware. It'd be nice not to have to put
otelriver.Middlewareintoboth a client's
HooksandMiddlewareconfiguration, so we modifyclient to allow for hooks that middleware and middleware which are
hooks. This lets
otelriver.Middlewarecontinue doing what it wasalready doing, but also to start producing new counts as a hook.