-
Notifications
You must be signed in to change notification settings - Fork 85
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(metrics/family): 🍫 add Family::get_or_create_clone()
#244
base: master
Are you sure you want to change the base?
Conversation
13dbb03
to
fb14089
Compare
fixes prometheus#231. this introduces a new method to `Family<S, M, C>` to help alleviate the risk of deadlocks when accessing multiple series within a given metrics family. this returns a plain `M`, rather than the `MappedRwLockReadGuard<M>` RAII guard returned by `get_or_create()`. a test case is introduced in this commit to demonstrate that structures accessing multiple series within a single expression will not accidentally create a deadlock. Signed-off-by: katelyn martin <[email protected]>
fb14089
to
708c1ec
Compare
i've rebased this commit to address merge conflicts, and added information to the changelog. let me know if there is anything else that needs to be done. i am keen on a release that addresses the deadlocks reported in #231. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this.
@@ -225,6 +259,10 @@ impl<S: Clone + std::hash::Hash + Eq, M, C: MetricConstructor<M>> Family<S, M, C | |||
/// // calls. | |||
/// family.get_or_create(&vec![("method".to_owned(), "GET".to_owned())]).inc(); | |||
/// ``` | |||
/// | |||
/// NB: This method can cause deadlocks if multiple metrics within this family are read at | |||
/// once. Use [`Family::get_or_create()`] if you would like to avoid this by cloning the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// once. Use [`Family::get_or_create()`] if you would like to avoid this by cloning the | |
/// once. Use [`Family::get_or_create_clone()`] if you would like to avoid this by cloning the |
/// | ||
/// Callers wishing to avoid a clone of the metric `M` can call [`Family::get_or_create()`] to | ||
/// return a reference to the metric instead. | ||
pub fn get_or_create_clone(&self, label_set: &S) -> M { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn get_or_create_clone(&self, label_set: &S) -> M { | |
pub fn get_or_create_owned(&self, label_set: &S) -> M { |
Would this be more intuitive? I am undecided.
fixes #231.
this introduces a new method to
Family<S, M, C>
to help alleviate the risk of deadlocks when accessing multiple series within a given metrics family.this returns a plain
M
, rather than theMappedRwLockReadGuard<M>
RAII guard returned byget_or_create()
.a test case is introduced in this commit to demonstrate that structures accessing multiple series within a single expression will not accidentally create a deadlock.