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
09b26bf6
Unverified
Commit
09b26bf6
authored
Nov 08, 2025
by
mohammedabdulwahhab
Committed by
GitHub
Nov 08, 2025
Browse files
fix: refactor to use service discovery (#4092)
Signed-off-by:
mohammedabdulwahhab
<
furkhan324@berkeley.edu
>
parent
04f7579b
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
28 deletions
+26
-28
lib/runtime/src/distributed.rs
lib/runtime/src/distributed.rs
+10
-9
lib/runtime/src/instances.rs
lib/runtime/src/instances.rs
+14
-17
lib/runtime/src/lib.rs
lib/runtime/src/lib.rs
+2
-2
No files found.
lib/runtime/src/distributed.rs
View file @
09b26bf6
...
@@ -10,7 +10,7 @@ use crate::transports::nats::DRTNatsClientPrometheusMetrics;
...
@@ -10,7 +10,7 @@ use crate::transports::nats::DRTNatsClientPrometheusMetrics;
use
crate
::{
use
crate
::{
ErrorContext
,
ErrorContext
,
component
::{
self
,
ComponentBuilder
,
Endpoint
,
InstanceSource
,
Namespace
},
component
::{
self
,
ComponentBuilder
,
Endpoint
,
InstanceSource
,
Namespace
},
discovery
::
Discovery
Client
,
discovery
::
Discovery
,
metrics
::
PrometheusUpdateCallback
,
metrics
::
PrometheusUpdateCallback
,
metrics
::{
MetricsHierarchy
,
MetricsRegistry
},
metrics
::{
MetricsHierarchy
,
MetricsRegistry
},
service
::
ServiceClient
,
service
::
ServiceClient
,
...
@@ -92,12 +92,13 @@ impl DistributedRuntime {
...
@@ -92,12 +92,13 @@ impl DistributedRuntime {
let
nats_client_for_metrics
=
nats_client
.clone
();
let
nats_client_for_metrics
=
nats_client
.clone
();
// Initialize discovery client with mock implementation
// Initialize discovery backed by KV store
// TODO: Replace MockDiscoveryClient with KeyValueStoreDiscoveryClient or KubeDiscoveryClient
let
discovery_client
=
{
let
discovery_client
=
{
use
crate
::
discovery
::{
MockDiscoveryClient
,
SharedMockRegistry
};
use
crate
::
discovery
::
KVStoreDiscovery
;
let
registry
=
SharedMockRegistry
::
new
();
Arc
::
new
(
KVStoreDiscovery
::
new
(
Arc
::
new
(
MockDiscoveryClient
::
new
(
None
,
registry
))
as
Arc
<
dyn
DiscoveryClient
>
store
.clone
(),
runtime
.primary_token
(),
))
as
Arc
<
dyn
Discovery
>
};
};
let
distributed_runtime
=
Self
{
let
distributed_runtime
=
Self
{
...
@@ -242,9 +243,9 @@ impl DistributedRuntime {
...
@@ -242,9 +243,9 @@ impl DistributedRuntime {
Namespace
::
new
(
self
.clone
(),
name
.into
(),
self
.is_static
)
Namespace
::
new
(
self
.clone
(),
name
.into
(),
self
.is_static
)
}
}
///
TODO:
Return discovery
client when KeyValueDiscoveryClient or KubeDiscoveryClient is implemented
/// Return
s the
discovery
interface for service registration and discovery
pub
fn
discovery
_client
(
&
self
)
->
Result
<
Arc
<
dyn
Discovery
Client
>
>
{
pub
fn
discovery
(
&
self
)
->
Arc
<
dyn
Discovery
>
{
Err
(
error!
(
"D
iscovery
client
not implemented!"
)
)
self
.d
iscovery
_
client
.clone
(
)
}
}
pub
(
crate
)
fn
service_client
(
&
self
)
->
Option
<
ServiceClient
>
{
pub
(
crate
)
fn
service_client
(
&
self
)
->
Option
<
ServiceClient
>
{
...
...
lib/runtime/src/instances.rs
View file @
09b26bf6
...
@@ -9,25 +9,22 @@
...
@@ -9,25 +9,22 @@
use
std
::
sync
::
Arc
;
use
std
::
sync
::
Arc
;
use
crate
::
component
::{
INSTANCE_ROOT_PATH
,
Instance
};
use
crate
::
component
::
Instance
;
use
crate
::
storage
::
key_value_store
::{
KeyValueStore
,
KeyValueStoreManager
};
use
crate
::
discovery
::{
Discovery
,
DiscoveryQuery
};
use
crate
::
transports
::
etcd
::
Client
as
EtcdClient
;
pub
async
fn
list_all_instances
(
client
:
&
KeyValueStoreManager
)
->
anyhow
::
Result
<
Vec
<
Instance
>>
{
pub
async
fn
list_all_instances
(
let
Some
(
bucket
)
=
client
.get_bucket
(
INSTANCE_ROOT_PATH
)
.await
?
else
{
discovery_client
:
Arc
<
dyn
Discovery
>
,
return
Ok
(
vec!
[]);
)
->
anyhow
::
Result
<
Vec
<
Instance
>>
{
};
let
discovery_instances
=
discovery_client
.list
(
DiscoveryQuery
::
AllEndpoints
)
.await
?
;
let
mut
instances
:
Vec
<
Instance
>
=
discovery_instances
.into_iter
()
.filter_map
(|
di
|
match
di
{
crate
::
discovery
::
DiscoveryInstance
::
Endpoint
(
instance
)
=>
Some
(
instance
),
_
=>
None
,
// Ignore all other variants (ModelCard, etc.)
})
.collect
();
let
entries
=
bucket
.entries
()
.await
?
;
let
mut
instances
=
Vec
::
with_capacity
(
entries
.len
());
for
(
name
,
bytes
)
in
entries
.into_iter
()
{
match
serde_json
::
from_slice
::
<
Instance
>
(
&
bytes
)
{
Ok
(
instance
)
=>
instances
.push
(
instance
),
Err
(
err
)
=>
{
tracing
::
warn!
(
%
err
,
key
=
name
,
"Failed to parse instance from storage"
);
}
}
}
instances
.sort
();
instances
.sort
();
Ok
(
instances
)
Ok
(
instances
)
...
...
lib/runtime/src/lib.rs
View file @
09b26bf6
...
@@ -96,8 +96,8 @@ pub struct DistributedRuntime {
...
@@ -96,8 +96,8 @@ pub struct DistributedRuntime {
tcp_server
:
Arc
<
OnceCell
<
Arc
<
transports
::
tcp
::
server
::
TcpStreamServer
>>>
,
tcp_server
:
Arc
<
OnceCell
<
Arc
<
transports
::
tcp
::
server
::
TcpStreamServer
>>>
,
system_status_server
:
Arc
<
OnceLock
<
Arc
<
system_status_server
::
SystemStatusServerInfo
>>>
,
system_status_server
:
Arc
<
OnceLock
<
Arc
<
system_status_server
::
SystemStatusServerInfo
>>>
,
// Service discovery
client
// Service discovery
interface
discovery_client
:
Arc
<
dyn
discovery
::
Discovery
Client
>
,
discovery_client
:
Arc
<
dyn
discovery
::
Discovery
>
,
// local registry for components
// local registry for components
// the registry allows us to use share runtime resources across instances of the same component object.
// the registry allows us to use share runtime resources across instances of the same component object.
...
...
Prev
1
2
Next
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