Skip to content

Commit 1a33f6e

Browse files
committed
Thanks Code Rabbit
Signed-off-by: Graham King <[email protected]>
1 parent 89e1281 commit 1a33f6e

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

lib/llm/src/grpc/service/kserve.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ impl State {
5757
}
5858
}
5959

60-
pub fn new_with_etcd(manager: Arc<ModelManager>, etcd_client: Option<etcd::Client>) -> Self {
60+
pub fn new_with_etcd(manager: Arc<ModelManager>, etcd_client: etcd::Client) -> Self {
6161
Self {
6262
manager,
6363
metrics: Arc::new(Metrics::default()),
64-
etcd_client,
64+
etcd_client: Some(etcd_client),
6565
}
6666
}
6767

@@ -155,7 +155,10 @@ impl KserveServiceConfigBuilder {
155155
let config: KserveServiceConfig = self.build_internal()?;
156156

157157
let model_manager = Arc::new(ModelManager::new());
158-
let state = Arc::new(State::new_with_etcd(model_manager, config.etcd_client));
158+
let state = match config.etcd_client {
159+
Some(etcd_client) => Arc::new(State::new_with_etcd(model_manager, etcd_client)),
160+
None => Arc::new(State::new(model_manager)),
161+
};
159162

160163
// enable prometheus metrics
161164
let registry = metrics::Registry::new();

lib/llm/src/http/service/service_v2.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,10 @@ impl HttpServiceConfigBuilder {
303303
let config: HttpServiceConfig = self.build_internal()?;
304304

305305
let model_manager = Arc::new(ModelManager::new());
306-
let Some(etcd_client) = config.etcd_client else {
307-
anyhow::bail!("Missing etcd_client in config, building HttpServiceConfig");
306+
let state = match config.etcd_client {
307+
Some(etcd_client) => Arc::new(State::new_with_etcd(model_manager, etcd_client)),
308+
None => Arc::new(State::new(model_manager)),
308309
};
309-
let state = Arc::new(State::new_with_etcd(model_manager, etcd_client));
310-
311310
state
312311
.flags
313312
.set(&EndpointType::Chat, config.enable_chat_endpoints);

lib/runtime/src/component.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
//!
3030
//! TODO: Top-level Overview of Endpoints/Functions
3131
32+
use std::fmt;
33+
3234
use crate::{
3335
config::HealthStatus,
3436
discovery::Lease,
@@ -91,7 +93,7 @@ pub struct Registry {
9193
inner: Arc<tokio::sync::Mutex<RegistryInner>>,
9294
}
9395

94-
#[derive(Debug, Clone, Serialize, Deserialize)]
96+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
9597
pub struct Instance {
9698
pub component: String,
9799
pub endpoint: String,
@@ -113,6 +115,30 @@ impl Instance {
113115
}
114116
}
115117

118+
impl fmt::Display for Instance {
119+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
120+
write!(
121+
f,
122+
"{}/{}/{}/{}",
123+
self.namespace, self.component, self.endpoint, self.instance_id
124+
)
125+
}
126+
}
127+
128+
/// Sort by string name
129+
impl std::cmp::Ord for Instance {
130+
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
131+
self.to_string().cmp(&other.to_string())
132+
}
133+
}
134+
135+
impl PartialOrd for Instance {
136+
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
137+
// Since Ord is fully implemented, the comparison is always total.
138+
Some(self.cmp(other))
139+
}
140+
}
141+
116142
/// A [Component] a discoverable entity in the distributed runtime.
117143
/// You can host [Endpoint] on a [Component] by first creating
118144
/// a [Service] then adding one or more [Endpoint] to the [Service].
@@ -255,6 +281,7 @@ impl Component {
255281
};
256282
instances.push(val);
257283
}
284+
instances.sort();
258285
Ok(instances)
259286
}
260287

lib/runtime/src/instances.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub async fn list_all_instances(client: Arc<dyn KeyValueStore>) -> anyhow::Resul
2828
}
2929
}
3030
}
31+
instances.sort();
3132

3233
Ok(instances)
3334
}

0 commit comments

Comments
 (0)