Skip to content

Commit

Permalink
[feat] Add More Details to GetInfo (#94)
Browse files Browse the repository at this point in the history
* add active sources and monitoring enabled to get info

* fixed typo
  • Loading branch information
warittornc authored Nov 1, 2024
1 parent cd747e7 commit c32760b
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 90 deletions.
158 changes: 91 additions & 67 deletions bothan-api/client/go-client/proto/bothan/v1/bothan.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions bothan-api/server/src/api/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ impl BothanService for BothanServer {
bothan_version: info.bothan_version,
registry_ipfs_hash: info.registry_hash,
registry_version_requirement: info.registry_version_requirement,
active_sources: info.active_sources,
monitoring_enabled: info.monitoring_enabled,
});

Ok(response)
Expand Down
8 changes: 7 additions & 1 deletion bothan-api/server/src/proto/bothan.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct GetInfoRequest {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetInfoResponse {
/// The bothan version
/// The Bothan version
#[prost(string, tag="1")]
pub bothan_version: ::prost::alloc::string::String,
/// The IPFS hash pointing to the registry data.
Expand All @@ -18,6 +18,12 @@ pub struct GetInfoResponse {
/// The version requirements for the registry.
#[prost(string, tag="3")]
pub registry_version_requirement: ::prost::alloc::string::String,
/// The active sources the Bothan instance is using
#[prost(string, repeated, tag="4")]
pub active_sources: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// Whether or not the Bothan instance has monitoring enabled
#[prost(bool, tag="5")]
pub monitoring_enabled: bool,
}
/// UpdateRegistryRequest defines the request message for the UpdateRegistry RPC method.
#[allow(clippy::derive_partial_eq_without_eq)]
Expand Down
16 changes: 5 additions & 11 deletions bothan-core/src/manager/crypto_asset_info/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,14 @@ impl<'a> CryptoAssetInfoManager<'a> {
.await?
.unwrap_or(String::new()); // If value doesn't exist, return an empty string
let registry_version_requirement = self.registry_version_requirement.to_string();
let active_sources = self.workers.keys().cloned().collect();

Ok(CryptoAssetManagerInfo::new(
bothan_version,
registry_hash,
registry_version_requirement,
active_sources,
self.monitoring_client.is_some(),
))
}

Expand All @@ -82,7 +85,7 @@ impl<'a> CryptoAssetInfoManager<'a> {

let uuid = create_uuid();

let supported_sources = self.current_worker_set().await;
let active_sources = self.workers.keys().cloned().collect();
let bothan_version = self.bothan_version.clone();
let registry_hash = self
.store
Expand All @@ -92,22 +95,13 @@ impl<'a> CryptoAssetInfoManager<'a> {
.unwrap_or_else(|| "".to_string());

client
.post_heartbeat(
uuid.clone(),
supported_sources,
bothan_version,
registry_hash,
)
.post_heartbeat(uuid.clone(), active_sources, bothan_version, registry_hash)
.await?
.error_for_status()?;

Ok(uuid)
}

pub async fn current_worker_set(&self) -> Vec<String> {
self.workers.keys().cloned().collect()
}

/// Gets the `Price` of the given signal ids.
pub async fn get_prices(
&self,
Expand Down
6 changes: 6 additions & 0 deletions bothan-core/src/manager/crypto_asset_info/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,24 @@ pub struct CryptoAssetManagerInfo {
pub bothan_version: String,
pub registry_hash: String,
pub registry_version_requirement: String,
pub active_sources: Vec<String>,
pub monitoring_enabled: bool,
}

impl CryptoAssetManagerInfo {
pub fn new(
bothan_version: String,
registry_hash: String,
registry_version_requirement: String,
active_sources: Vec<String>,
monitoring_enabled: bool,
) -> Self {
CryptoAssetManagerInfo {
bothan_version,
registry_hash,
registry_version_requirement,
active_sources,
monitoring_enabled,
}
}
}
4 changes: 2 additions & 2 deletions bothan-core/src/monitoring/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ impl Client {
pub async fn post_heartbeat(
&self,
uuid: String,
supported_sources: Vec<String>,
active_sources: Vec<String>,
bothan_version: Version,
registry_hash: String,
) -> Result<Response, Error> {
let bothan_info = BothanInfo::new(supported_sources, bothan_version, registry_hash);
let bothan_info = BothanInfo::new(active_sources, bothan_version, registry_hash);

self.post(uuid, Topic::Heartbeat, bothan_info).await
}
Expand Down
12 changes: 4 additions & 8 deletions bothan-core/src/monitoring/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@ pub enum Topic {
}

pub struct BothanInfo {
pub supported_sources: Vec<String>,
pub active_sources: Vec<String>,
pub version: Version,
pub registry_hash: String,
}

impl BothanInfo {
pub fn new(
supported_sources: Vec<String>,
version: Version,
registry_hash: String,
) -> BothanInfo {
pub fn new(active_sources: Vec<String>, version: Version, registry_hash: String) -> BothanInfo {
BothanInfo {
supported_sources,
active_sources,
version,
registry_hash,
}
Expand All @@ -38,7 +34,7 @@ impl Serialize for BothanInfo {
S: serde::Serializer,
{
let mut state = serializer.serialize_struct("BothanInfo", 4)?;
state.serialize_field("supported_sources", &self.supported_sources)?;
state.serialize_field("active_sources", &self.active_sources)?;
state.serialize_field("version", &self.version.to_string())?;
state.serialize_field("registry_hash", &self.registry_hash)?;
state.end()
Expand Down
6 changes: 5 additions & 1 deletion proto/bothan/v1/bothan.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ message GetInfoRequest {}

// GetInfoResponse defines the response message for the GetInfo RPC method.
message GetInfoResponse {
// The bothan version
// The Bothan version
string bothan_version = 1;
// The IPFS hash pointing to the registry data.
string registry_ipfs_hash = 2;
// The version requirements for the registry.
string registry_version_requirement = 3;
// The active sources the Bothan instance is using
repeated string active_sources = 4;
// Whether or not the Bothan instance has monitoring enabled
bool monitoring_enabled = 5;
}

// UpdateRegistryRequest defines the request message for the UpdateRegistry RPC method.
Expand Down

0 comments on commit c32760b

Please sign in to comment.