Skip to content

Commit acbdabc

Browse files
authored
feat(metrics): add NATS client metrics to prometheus_metrics_fmt (#2292)
Co-authored-by: Keiven Chang <keivenchang@users.noreply.github.com>
1 parent 591f4d5 commit acbdabc

File tree

20 files changed

+1636
-510
lines changed

20 files changed

+1636
-510
lines changed

components/metrics/src/main.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use dynamo_llm::kv_router::scheduler::KVHitRateEvent;
3131
use dynamo_llm::kv_router::KV_HIT_RATE_SUBJECT;
3232
use dynamo_runtime::{
3333
error, logging,
34-
metrics::MetricsRegistry,
3534
traits::events::{EventPublisher, EventSubscriber},
3635
utils::{Duration, Instant},
3736
DistributedRuntime, ErrorContext, Result, Runtime, Worker,
@@ -137,14 +136,7 @@ async fn app(runtime: Runtime) -> Result<()> {
137136
.await
138137
.context("Unable to create unique instance of Count; possibly one already exists")?;
139138

140-
let target_component = {
141-
let c = namespace.component(&config.component_name)?;
142-
if let Some(ref model) = config.model_name {
143-
c.add_labels(&[("model", model.as_str())])?
144-
} else {
145-
c
146-
}
147-
};
139+
let target_component = namespace.component(&config.component_name)?;
148140
let target_endpoint = target_component.endpoint(&config.endpoint_name);
149141

150142
let service_path = target_endpoint.path();

lib/bindings/python/rust/lib.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -485,21 +485,6 @@ impl Component {
485485
Ok(())
486486
})
487487
}
488-
489-
/// Add constant labels to this component (for metrics). Returns a new Component with labels.
490-
/// labels: list of (key, value) tuples.
491-
fn add_labels(&self, labels: Vec<(String, String)>) -> PyResult<Component> {
492-
use rs::metrics::MetricsRegistry as _;
493-
let pairs: Vec<(&str, &str)> = labels
494-
.iter()
495-
.map(|(k, v)| (k.as_str(), v.as_str()))
496-
.collect();
497-
let inner = self.inner.clone().add_labels(&pairs).map_err(to_pyerr)?;
498-
Ok(Component {
499-
inner,
500-
event_loop: self.event_loop.clone(),
501-
})
502-
}
503488
}
504489

505490
#[pymethods]

lib/llm/src/discovery/watcher.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use anyhow::Context as _;
77
use tokio::sync::{mpsc::Receiver, Notify};
88

99
use dynamo_runtime::{
10-
metrics::MetricsRegistry,
1110
pipeline::{
1211
network::egress::push_router::PushRouter, ManyOut, Operator, RouterMode, SegmentSource,
1312
ServiceBackend, SingleIn, Source,
@@ -170,8 +169,7 @@ impl ModelWatcher {
170169
let component = self
171170
.drt
172171
.namespace(&endpoint_id.namespace)?
173-
.component(&endpoint_id.component)
174-
.and_then(|c| c.add_labels(&[("model", &model_entry.name)]))?;
172+
.component(&endpoint_id.component)?;
175173
let client = component.endpoint(&endpoint_id.name).client().await?;
176174

177175
let Some(etcd_client) = self.drt.etcd_client() else {

lib/llm/src/entrypoint/input/common.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use dynamo_runtime::{
2727
component::Client,
2828
distributed::DistributedConfig,
2929
engine::{AsyncEngineStream, Data},
30-
metrics::MetricsRegistry,
3130
pipeline::{
3231
Context, ManyOut, Operator, PushRouter, RouterMode, SegmentSource, ServiceBackend,
3332
ServiceEngine, ServiceFrontend, SingleIn, Source,
@@ -111,8 +110,7 @@ pub async fn prepare_engine(
111110
let endpoint_id = local_model.endpoint_id();
112111
let component = distributed_runtime
113112
.namespace(&endpoint_id.namespace)?
114-
.component(&endpoint_id.component)
115-
.and_then(|c| c.add_labels(&[("model", card.slug().to_string().as_str())]))?;
113+
.component(&endpoint_id.component)?;
116114

117115
let client = component.endpoint(&endpoint_id.name).client().await?;
118116

lib/llm/src/entrypoint/input/endpoint.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use crate::{
1717
};
1818

1919
use dynamo_runtime::engine::AsyncEngineStream;
20-
use dynamo_runtime::metrics::MetricsRegistry;
2120
use dynamo_runtime::pipeline::{
2221
network::Ingress, Context, ManyOut, Operator, SegmentSource, ServiceBackend, SingleIn, Source,
2322
};
@@ -33,25 +32,9 @@ pub async fn run(
3332
let cancel_token = distributed_runtime.primary_token().clone();
3433
let endpoint_id: EndpointId = path.parse()?;
3534

36-
let model_name = match &engine_config {
37-
EngineConfig::StaticFull { model, .. } | EngineConfig::StaticCore { model, .. } => {
38-
Some(model.service_name().to_string())
39-
}
40-
EngineConfig::StaticRemote(model) | EngineConfig::Dynamic(model) => {
41-
Some(model.service_name().to_string())
42-
}
43-
};
44-
4535
let component = distributed_runtime
4636
.namespace(&endpoint_id.namespace)?
47-
.component(&endpoint_id.component)
48-
.and_then(|c| {
49-
if let Some(ref name) = model_name {
50-
c.add_labels(&[("model", name.as_str())])
51-
} else {
52-
Ok(c)
53-
}
54-
})?;
37+
.component(&endpoint_id.component)?;
5538
let endpoint = component
5639
.service_builder()
5740
.create()

lib/runtime/examples/hello_world/src/bin/client.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
// limitations under the License.
1515

1616
use dynamo_runtime::{
17-
logging, metrics::MetricsRegistry, pipeline::PushRouter, protocols::annotated::Annotated,
18-
stream::StreamExt, DistributedRuntime, Result, Runtime, Worker,
17+
logging, pipeline::PushRouter, protocols::annotated::Annotated, stream::StreamExt,
18+
DistributedRuntime, Result, Runtime, Worker,
1919
};
2020
use hello_world::DEFAULT_NAMESPACE;
2121

@@ -31,7 +31,6 @@ async fn app(runtime: Runtime) -> Result<()> {
3131
let client = distributed
3232
.namespace(DEFAULT_NAMESPACE)?
3333
.component("backend")?
34-
.add_labels(&[("model", "hello_world_model")])?
3534
.endpoint("generate")
3635
.client()
3736
.await?;

lib/runtime/examples/hello_world/src/bin/server.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
use dynamo_runtime::{
1717
logging,
18-
metrics::MetricsRegistry,
1918
pipeline::{
2019
async_trait, network::Ingress, AsyncEngine, AsyncEngineContextProvider, Error, ManyOut,
2120
ResponseStream, SingleIn,
@@ -70,7 +69,6 @@ async fn backend(runtime: DistributedRuntime) -> Result<()> {
7069
runtime
7170
.namespace(DEFAULT_NAMESPACE)?
7271
.component("backend")?
73-
.add_labels(&[("model", "hello_world_model")])?
7472
.service_builder()
7573
.create()
7674
.await?

lib/runtime/examples/service_metrics/src/bin/service_client.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use futures::StreamExt;
1717
use service_metrics::DEFAULT_NAMESPACE;
1818

1919
use dynamo_runtime::{
20-
logging, metrics::MetricsRegistry, pipeline::PushRouter, protocols::annotated::Annotated,
21-
utils::Duration, DistributedRuntime, Result, Runtime, Worker,
20+
logging, pipeline::PushRouter, protocols::annotated::Annotated, utils::Duration,
21+
DistributedRuntime, Result, Runtime, Worker,
2222
};
2323

2424
fn main() -> Result<()> {
@@ -31,9 +31,7 @@ async fn app(runtime: Runtime) -> Result<()> {
3131
let distributed = DistributedRuntime::from_settings(runtime.clone()).await?;
3232

3333
let namespace = distributed.namespace(DEFAULT_NAMESPACE)?;
34-
let component = namespace
35-
.component("backend")?
36-
.add_labels(&[("model", "service_metrics_model")])?;
34+
let component = namespace.component("backend")?;
3735

3836
let client = component.endpoint("generate").client().await?;
3937

lib/runtime/examples/service_metrics/src/bin/service_server.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use service_metrics::{MyStats, DEFAULT_NAMESPACE};
1717

1818
use dynamo_runtime::{
1919
logging,
20-
metrics::MetricsRegistry,
2120
pipeline::{
2221
async_trait, network::Ingress, AsyncEngine, AsyncEngineContextProvider, Error, ManyOut,
2322
ResponseStream, SingleIn,
@@ -72,7 +71,6 @@ async fn backend(runtime: DistributedRuntime) -> Result<()> {
7271
runtime
7372
.namespace(DEFAULT_NAMESPACE)?
7473
.component("backend")?
75-
.add_labels(&[("model", "service_metrics_model")])?
7674
.service_builder()
7775
.create()
7876
.await?

lib/runtime/examples/system_metrics/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ pub async fn backend(drt: DistributedRuntime, endpoint_name: Option<&str>) -> Re
9191
let endpoint = drt
9292
.namespace(DEFAULT_NAMESPACE)?
9393
.component(DEFAULT_COMPONENT)?
94-
.add_labels(&[("model", DEFAULT_MODEL_NAME)])?
9594
.service_builder()
9695
.create()
9796
.await?

0 commit comments

Comments
 (0)