Improve metrics hooks setup (fixes #12672) #12684
Open
+102
−44
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.
This pull request fixes #12672.
It adds the type
HooksBuilder
, responsible for creating new custom instances of theHooks
collection.Changes
HooksBuilder
type.Hooks::builder
method to create a newHooksBuilder
.Hooks::new
byHooks::builder
.Hooks::new
.Considerations
HooksBuilder
to ease its usage a bit.HooksBuilder::with_database_metrics
HooksBuilder::with_static_file_provider
HooksBuilder::with_default_collector
I made that choice because moving the cloning logic to the caller of
Hooks::new
requires us to write a bit of boilerplate due to having to move resources into the static hook closure:Replaced by:
I'm not sure whether this was a good idea. It is a bit faster to write, but maybe it makes the logic a bit harder to reason about. If someone reads that, they might assume that
with_database_metrics
is setting a specific "database_metrics" field in the builder, when it is not.I can remove those convenience methods if needed.
Other
I had to fix a compilation error here (there was a comparaison between
i32
andu32
:reth/crates/storage/libmdbx-rs/src/environment.rs
Lines 431 to 444 in 7c7baca
I changed a
format!
to aformat_args!
in theDebug
implementation ofHooks
to save on an allocation.