feat(metrics): Enhance Family's flexibility #230
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 PR introduces two new interfaces to
Family
:get
andwith_metrics
. These additions cater to the following use cases:get_or_create
interface is used to create metric M1. In crate B, which depends on crate A, there's a need to check if metric A exists (with dynamic labels that may not have been created yet, eg., noset_kv
happened yet). If it exists, additional business-specific labels from crate B can be added to this metric. For example:Family
's definition allows for custom constructors, there are instances where constructor parameters are required. The standardget_or_create
implementation andMetricConstructor
falls short in such scenarios. The newwith_metrics
interface enables users to implement aCustomFamily
that wrapsFamily
as an inner field. By implementingDeref
andDerefMut
,CustomFamily
can reuse most ofFamily
's interfaces while defining its own constructor trait andget_or_create
implementation. This significantly enhances Family's flexibility. For example: