Initialize Prometheus middleware metrics on worker_boot too - #891
Open
afonsojanu wants to merge 1 commit into
Open
Initialize Prometheus middleware metrics on worker_boot too#891afonsojanu wants to merge 1 commit into
afonsojanu wants to merge 1 commit into
Conversation
The Worker class emits worker_boot itself, not process_boot, so a broker driven directly through the Worker API rather than the dramatiq CLI's forked processes (which emit process_boot before ever constructing a Worker) never reached after_process_boot, and every metric attribute the middleware records against stayed unset. Added after_worker_boot as a thin call into the existing after_process_boot setup. Under the CLI, both events still fire in the same process, so the metrics just get set up twice in a row before any message is processed, which is harmless. Added a test constructing the middleware directly and calling after_worker_boot on its own, confirming the metrics attributes are set afterward.
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.
Fixes #703
dramatiq.worker.Workeremitsworker_bootitself, callingafter_worker_booton every middleware, but thePrometheusmiddleware only definedafter_process_boot, which thedramatiqCLI's forked worker processes emit separately before ever constructing aWorker. A broker driven directly through theWorkerAPI instead of the CLI never reaches that hook, somessage_durations,inprogress_messages, and the rest of the metrics attributes stay unset, and every other hook that reads them raisesAttributeErrorthe moment a message comes in.Added
after_worker_bootas a thin call into the existingafter_process_bootsetup. Under the CLI, both events still land in the same process one after the other before any message is processed, so the metrics just get built twice in a row, which is harmless.Added a test that constructs the middleware directly and calls
after_worker_booton its own, confirming the metrics attributes are actually set afterward. Ran the fulltests/middleware/suite (54 passed) plusflake8,isort, andmypyon the changed files, all clean.