Skip to content

Commit

Permalink
refactor metrics and introduce a dedicated peer monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Nov 18, 2023
1 parent d147999 commit 9a49472
Show file tree
Hide file tree
Showing 15 changed files with 332 additions and 161 deletions.
5 changes: 2 additions & 3 deletions core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,9 +780,8 @@ impl Core {
// let metrics = self.interop.kaspa_service().metrics();
let peers = self
.interop
.kaspa_service()
.metrics()
.connected_peer_info()
.peer_monitor_service()
.peer_info()
.map(|peers| peers.len());
let tps = self.metrics.as_ref().map(|metrics| metrics.tps);
ui.horizontal(|ui| {
Expand Down
8 changes: 5 additions & 3 deletions core/src/egui/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ pub struct Theme {
pub graph_frame_color: Color32,
pub performance_graph_color: Color32,
pub storage_graph_color: Color32,
pub node_graph_color: Color32,
pub network_graph_color: Color32,
pub blockdag_graph_color: Color32,
pub node_log_font_size: f32,
// pub panel_icon_size : f32,
// pub panel_icon_padding : f32,
}
Expand Down Expand Up @@ -58,8 +59,9 @@ impl Default for Theme {
graph_frame_color: Color32::GRAY,
performance_graph_color: Color32::from_rgb(186, 238, 255),
storage_graph_color: Color32::from_rgb(255, 231, 186),
node_graph_color: Color32::from_rgb(241, 255, 186),
network_graph_color: Color32::from_rgb(186, 255, 241),
network_graph_color: Color32::from_rgb(241, 255, 186),
blockdag_graph_color: Color32::from_rgb(186, 255, 241),
node_log_font_size: 15_f32,
// network_graph_color: Color32::from_rgb(58, 221, 190),
// graph_color: Color32::from_rgb(21, 82, 71),
// panel_icon_size : IconSize::new(Vec2::splat(26.),Vec2::new(36.,26.)),
Expand Down
8 changes: 7 additions & 1 deletion core/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub use cfg_if::cfg_if;
pub use downcast_rs::{impl_downcast, Downcast, DowncastSync};
pub use kaspa_consensus_core::constants::SOMPI_PER_KASPA;
pub use kaspa_consensus_core::network::{NetworkId, NetworkType};
pub use kaspa_rpc_core::api::rpc::RpcApi;
pub use kaspa_utils::hex::{FromHex, ToHex};
pub use kaspa_utils::{hashmap::GroupExtension, networking::ContextualNetAddress};
pub use kaspa_wallet_core::api;
Expand All @@ -17,18 +18,21 @@ pub use kaspa_wallet_core::storage::{
pub use kaspa_wallet_core::utils::*;
pub use kaspa_wallet_core::Address;
pub use kaspa_wrpc_client::{KaspaRpcClient, WrpcEncoding};

// pub use egui::Ui;
// pub use futures_util::future::BoxFuture;
pub use async_trait::async_trait;
pub use futures::{future::FutureExt, select, Future};
pub use futures::{pin_mut, select, FutureExt, StreamExt};
pub use futures_util::future::{join_all, try_join_all};
pub use separator::*;
pub use serde::{Deserialize, Serialize};
pub use std::any::{Any, TypeId};
pub use std::cell::{Ref, RefCell, RefMut};
pub use std::collections::HashMap;
pub use std::collections::VecDeque;
pub use std::future::Future;
pub use std::path::{Path, PathBuf};
pub use std::pin::Pin;
pub use std::rc::Rc;
pub use std::str::FromStr;
pub use std::sync::{
Expand All @@ -37,8 +41,10 @@ pub use std::sync::{
};
pub use std::sync::{Arc, Mutex, MutexGuard};
pub use std::time::Duration;

pub use workflow_core::channel::{oneshot, Channel, Receiver, Sender};
pub use workflow_core::extensions::is_not_empty::*;
pub use workflow_core::task::interval;
pub use workflow_core::time::unixtime_as_millis_f64;
pub use workflow_i18n::*;
pub use workflow_log::*;
Expand Down
25 changes: 23 additions & 2 deletions core/src/interop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ pub mod runtime;
pub mod services;

use runtime::Runtime;
use services::KaspaService;
use services::*;

pub mod payload;
pub use payload::Payload;

pub struct Inner {
application_events: ApplicationEventsChannel,
kaspa: Arc<KaspaService>,
peer_monitor: Arc<PeerMonitorService>,
metrics_service: Arc<MetricsService>,
runtime: Runtime,
egui_ctx: egui::Context,
is_running: Arc<AtomicBool>,
Expand All @@ -39,12 +41,19 @@ impl Interop {
pub fn new(egui_ctx: &egui::Context, settings: &Settings) -> Self {
let application_events = ApplicationEventsChannel::unbounded(Some(egui_ctx.clone()));
let kaspa = Arc::new(KaspaService::new(application_events.clone(), settings));
let runtime = Runtime::new(&[kaspa.clone()]);
let peer_monitor = Arc::new(PeerMonitorService::new(
application_events.clone(),
settings,
));
let metrics_service = Arc::new(MetricsService::new(application_events.clone(), settings));
let runtime = Runtime::new(&[kaspa.clone(), peer_monitor.clone(), metrics_service.clone()]);

let interop = Self {
inner: Arc::new(Inner {
application_events,
kaspa,
peer_monitor,
metrics_service,
runtime,
egui_ctx: egui_ctx.clone(),
is_running: Arc::new(AtomicBool::new(false)),
Expand All @@ -66,6 +75,10 @@ impl Interop {
&self.inner.runtime
}

pub fn services(&self) -> Vec<Arc<dyn runtime::Service + Send + Sync + 'static>> {
self.inner.runtime.services()
}

/// Start the interop runtime.
pub fn start(&self) {
self.inner.is_running.store(true, Ordering::SeqCst);
Expand All @@ -92,6 +105,14 @@ impl Interop {
&self.inner.kaspa
}

pub fn peer_monitor_service(&self) -> &Arc<PeerMonitorService> {
&self.inner.peer_monitor
}

pub fn metrics_service(&self) -> &Arc<MetricsService> {
&self.inner.metrics_service
}

/// Returns the reference to the application events channel.
pub fn application_events(&self) -> &ApplicationEventsChannel {
&self.inner.application_events
Expand Down
7 changes: 7 additions & 0 deletions core/src/interop/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ pub trait Service: Sync + Send {
async fn spawn(self: Arc<Self>) -> Result<()>;
async fn join(self: Arc<Self>) -> Result<()>;
fn terminate(self: Arc<Self>);
// --
async fn attach_rpc(self: Arc<Self>, _rpc_api: Arc<dyn RpcApi>) -> Result<()> {
Ok(())
}
async fn detach_rpc(self: Arc<Self>) -> Result<()> {
Ok(())
}
}

pub struct Inner {
Expand Down
4 changes: 2 additions & 2 deletions core/src/interop/services/kaspa/logs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use egui::RichText;
use crate::imports::*;

pub enum Log {
Debug(String),
Expand Down Expand Up @@ -49,6 +49,6 @@ impl From<&Log> for RichText {
Log::Processed(text) => RichText::from(text).color(egui::Color32::LIGHT_GREEN),
};

text.monospace()
text.font(FontId::monospace(theme().node_log_font_size))
}
}
Loading

0 comments on commit 9a49472

Please sign in to comment.