Skip to content

Commit 049147c

Browse files
authored
metrics: fix metrics server dying (#176)
we cloned it a few places, but killed the shared task when any clone was dropped. now it's unclonable and we pass it around as an Arc everywhere
2 parents 793f07c + ad986f0 commit 049147c

File tree

7 files changed

+12
-10
lines changed

7 files changed

+12
-10
lines changed

architectures/centralized/client/src/app.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use psyche_network::{
1414
use psyche_tui::logging::LoggerWidget;
1515
use psyche_tui::{CustomWidget, TabbedWidget};
1616
use psyche_watcher::{Backend as WatcherBackend, CoordinatorTui, OpportunisticData};
17+
use std::sync::Arc;
1718
use std::{path::PathBuf, time::Duration};
1819
use tokio::sync::mpsc::Sender;
1920
use tokio::time::interval;
@@ -80,7 +81,7 @@ pub struct App {
8081
coordinator_state: Coordinator<ClientId>,
8182
server_conn: TcpClient<ClientId, ClientToServerMessage, ServerToClientMessage>,
8283

83-
metrics: ClientMetrics,
84+
metrics: Arc<ClientMetrics>,
8485
}
8586

8687
pub struct AppBuilder(AppParams);
@@ -127,7 +128,7 @@ impl AppBuilder {
127128
)> {
128129
let p = self.0;
129130

130-
let metrics = ClientMetrics::new(p.metrics_local_port);
131+
let metrics = Arc::new(ClientMetrics::new(p.metrics_local_port));
131132
let server_conn =
132133
TcpClient::<ClientId, ClientToServerMessage, ServerToClientMessage>::connect(
133134
&p.server_addr,

architectures/decentralized/solana-client/src/app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub struct App {
5050
update_tui_interval: Interval,
5151
tx_tui_state: Option<Sender<TabsData>>,
5252
authorizer: Option<Pubkey>,
53-
metrics: ClientMetrics,
53+
metrics: Arc<ClientMetrics>,
5454
allowlist: allowlist::AllowDynamic,
5555
p2p: NC,
5656
state_options: RunInitConfig<psyche_solana_coordinator::ClientId, NetworkIdentity>,
@@ -99,7 +99,7 @@ impl AppBuilder {
9999
*p.identity_secret_key.public().as_bytes(),
100100
);
101101

102-
let metrics = ClientMetrics::new(p.metrics_local_port);
102+
let metrics = Arc::new(ClientMetrics::new(p.metrics_local_port));
103103

104104
let allowlist = allowlist::AllowDynamic::new();
105105

shared/client/src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<T: NodeIdentity, A: AuthenticatableIdentity + 'static, B: Backend<T> + 'sta
6060
allowlist: allowlist::AllowDynamic,
6161
mut p2p: NC,
6262
init_config: RunInitConfig<T, A>,
63-
metrics: ClientMetrics,
63+
metrics: Arc<ClientMetrics>,
6464
) -> Self {
6565
let cancel = CancellationToken::new();
6666
let (tx_tui, rx_tui) = watch::channel::<TUIStates>(Default::default());

shared/metrics/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub use iroh::{IrohMetricsCollector, create_iroh_registry};
2020
pub use iroh_metrics::Registry as IrohMetricsRegistry;
2121
use tracing::{debug, info, warn};
2222

23-
#[derive(Clone, Debug)]
23+
#[derive(Debug)]
2424
/// metrics collector for Psyche clients
2525
pub struct ClientMetrics {
2626
// opentelemtery instruments

shared/network/examples/bandwidth_test.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use psyche_tui::{
1919
};
2020
use rand::Rng;
2121
use serde::{Deserialize, Serialize};
22+
use std::sync::Arc;
2223
use std::{
2324
collections::HashMap,
2425
str::FromStr,
@@ -292,7 +293,7 @@ async fn main() -> Result<()> {
292293
secret_key,
293294
allowlist::AllowAll,
294295
4,
295-
ClientMetrics::new(None),
296+
Arc::new(ClientMetrics::new(None)),
296297
)
297298
.await?;
298299

shared/network/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ where
122122
_broadcast_message: PhantomData<BroadcastMessage>,
123123
_download: PhantomData<Download>,
124124
update_stats_interval: Interval,
125-
metrics: ClientMetrics,
125+
metrics: Arc<ClientMetrics>,
126126
_iroh_metrics: IrohMetricsCollector,
127127
}
128128

@@ -160,7 +160,7 @@ where
160160
secret_key: Option<SecretKey>,
161161
allowlist: A,
162162
max_concurrent_downloads: usize,
163-
metrics: ClientMetrics,
163+
metrics: Arc<ClientMetrics>,
164164
) -> Result<Self> {
165165
let secret_key = match secret_key {
166166
None => SecretKey::generate(&mut rand::rngs::OsRng),

shared/network/src/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ async fn spawn_new_node(
202202
None,
203203
allowlist::AllowAll,
204204
20,
205-
ClientMetrics::new(None),
205+
Arc::new(ClientMetrics::new(None)),
206206
)
207207
.await?;
208208

0 commit comments

Comments
 (0)