Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
dynamo
Commits
c5e8c4c2
Unverified
Commit
c5e8c4c2
authored
Dec 03, 2025
by
Yan Ru Pei
Committed by
GitHub
Dec 03, 2025
Browse files
chore: Arc wrap prometheus_registry in MetricsRegistry (#4677)
Signed-off-by:
PeaBrane
<
yanrpei@gmail.com
>
parent
991d8c72
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
18 deletions
+9
-18
lib/runtime/src/metrics.rs
lib/runtime/src/metrics.rs
+9
-18
No files found.
lib/runtime/src/metrics.rs
View file @
c5e8c4c2
...
@@ -646,10 +646,15 @@ pub type PrometheusUpdateCallback = Arc<dyn Fn() -> anyhow::Result<()> + Send +
...
@@ -646,10 +646,15 @@ pub type PrometheusUpdateCallback = Arc<dyn Fn() -> anyhow::Result<()> + Send +
pub
type
PrometheusExpositionFormatCallback
=
pub
type
PrometheusExpositionFormatCallback
=
Arc
<
dyn
Fn
()
->
anyhow
::
Result
<
String
>
+
Send
+
Sync
+
'static
>
;
Arc
<
dyn
Fn
()
->
anyhow
::
Result
<
String
>
+
Send
+
Sync
+
'static
>
;
/// Structure to hold Prometheus registries and associated callbacks for a given hierarchy
/// Structure to hold Prometheus registries and associated callbacks for a given hierarchy.
///
/// All fields are Arc-wrapped, so cloning shares state. This ensures metrics registered
/// on cloned instances (e.g., cloned Client/Endpoint) are visible to the original.
#[derive(Clone)]
pub
struct
MetricsRegistry
{
pub
struct
MetricsRegistry
{
/// The Prometheus registry for this hierarchy (with interior mutability for thread-safe access)
/// The Prometheus registry for this hierarchy.
pub
prometheus_registry
:
std
::
sync
::
RwLock
<
prometheus
::
Registry
>
,
/// Arc-wrapped so clones share the same registry (metrics registered on clones are visible everywhere).
pub
prometheus_registry
:
Arc
<
std
::
sync
::
RwLock
<
prometheus
::
Registry
>>
,
/// Update callbacks invoked before metrics are scraped.
/// Update callbacks invoked before metrics are scraped.
/// Wrapped in Arc to preserve callbacks across clones (prevents callback loss when MetricsRegistry is cloned).
/// Wrapped in Arc to preserve callbacks across clones (prevents callback loss when MetricsRegistry is cloned).
...
@@ -683,25 +688,11 @@ impl std::fmt::Debug for MetricsRegistry {
...
@@ -683,25 +688,11 @@ impl std::fmt::Debug for MetricsRegistry {
}
}
}
}
impl
Clone
for
MetricsRegistry
{
fn
clone
(
&
self
)
->
Self
{
Self
{
prometheus_registry
:
std
::
sync
::
RwLock
::
new
(
self
.prometheus_registry
.read
()
.unwrap
()
.clone
(),
),
// Clone the Arc to share callbacks across all clones (prevents callback loss).
// Previously used Vec::new() here, which caused vllm: metrics to disappear.
prometheus_update_callbacks
:
Arc
::
clone
(
&
self
.prometheus_update_callbacks
),
prometheus_expfmt_callbacks
:
Arc
::
clone
(
&
self
.prometheus_expfmt_callbacks
),
}
}
}
impl
MetricsRegistry
{
impl
MetricsRegistry
{
/// Create a new metrics registry with an empty Prometheus registry and callback lists
/// Create a new metrics registry with an empty Prometheus registry and callback lists
pub
fn
new
()
->
Self
{
pub
fn
new
()
->
Self
{
Self
{
Self
{
prometheus_registry
:
std
::
sync
::
RwLock
::
new
(
prometheus
::
Registry
::
new
()),
prometheus_registry
:
Arc
::
new
(
std
::
sync
::
RwLock
::
new
(
prometheus
::
Registry
::
new
())
)
,
prometheus_update_callbacks
:
Arc
::
new
(
std
::
sync
::
RwLock
::
new
(
Vec
::
new
())),
prometheus_update_callbacks
:
Arc
::
new
(
std
::
sync
::
RwLock
::
new
(
Vec
::
new
())),
prometheus_expfmt_callbacks
:
Arc
::
new
(
std
::
sync
::
RwLock
::
new
(
Vec
::
new
())),
prometheus_expfmt_callbacks
:
Arc
::
new
(
std
::
sync
::
RwLock
::
new
(
Vec
::
new
())),
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment