Skip to content

Commit

Permalink
gateway: register GatewayMetrics with provided Registry
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed Jun 22, 2022
1 parent 195818d commit b4e5791
Show file tree
Hide file tree
Showing 27 changed files with 170 additions and 137 deletions.
58 changes: 3 additions & 55 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/sui-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ schemars = {version = "0.8.10", features = ["either"]}
either = "1.6.1"
multiaddr = "0.14.0"
mysten-network = { git = "https://github.com/MystenLabs/mysten-infra", rev = "ff5c1d69057fe93be658377462ca2875a57a0223" }
prometheus_exporter = "0.8.4"
prometheus = "0.13.1"
once_cell = "1.11.0"
colored = "2.0.0"
Expand Down
1 change: 0 additions & 1 deletion crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use move_core_types::{
use move_vm_runtime::{move_vm::MoveVM, native_functions::NativeFunctionTable};
use narwhal_executor::ExecutionStateError;
use narwhal_executor::{ExecutionIndices, ExecutionState};
use once_cell::sync::Lazy;
use parking_lot::Mutex;
use prometheus::{
register_histogram_with_registry, register_int_counter_with_registry, Histogram, IntCounter,
Expand Down
15 changes: 13 additions & 2 deletions crates/sui-core/src/authority_active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use tracing::error;

use crate::{
authority::AuthorityState, authority_aggregator::AuthorityAggregator,
authority_client::AuthorityAPI,
authority_client::AuthorityAPI, gateway_state::GatewayMetrics,
};
use tokio::time::Instant;

Expand Down Expand Up @@ -110,13 +110,15 @@ pub struct ActiveAuthority<A> {
pub net: ArcSwap<AuthorityAggregator<A>>,
// Network health
pub health: Arc<Mutex<HashMap<AuthorityName, AuthorityHealth>>>,
pub gateway_metrics: GatewayMetrics,
}

impl<A> ActiveAuthority<A> {
pub fn new(
authority: Arc<AuthorityState>,
follower_store: Arc<FollowerStore>,
authority_clients: BTreeMap<AuthorityName, A>,
gateway_metrics: GatewayMetrics,
) -> SuiResult<Self> {
let committee = authority.clone_committee();

Expand All @@ -133,17 +135,25 @@ impl<A> ActiveAuthority<A> {
net: ArcSwap::from(Arc::new(AuthorityAggregator::new(
committee,
authority_clients,
gateway_metrics.clone(),
))),
gateway_metrics,
})
}

pub fn new_with_ephemeral_follower_store(
authority: Arc<AuthorityState>,
authority_clients: BTreeMap<AuthorityName, A>,
gateway_metrics: GatewayMetrics,
) -> SuiResult<Self> {
let working_dir = tempfile::tempdir().unwrap();
let follower_store = Arc::new(FollowerStore::open(&working_dir).expect("cannot open db"));
Self::new(authority, follower_store, authority_clients)
Self::new(
authority,
follower_store,
authority_clients,
gateway_metrics,
)
}

/// Returns the amount of time we should wait to be able to contact at least
Expand Down Expand Up @@ -199,6 +209,7 @@ impl<A> Clone for ActiveAuthority<A> {
follower_store: self.follower_store.clone(),
net: ArcSwap::from(self.net.load().clone()),
health: self.health.clone(),
gateway_metrics: self.gateway_metrics.clone(),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
authority_active::{checkpoint_driver::CheckpointProcessControl, ActiveAuthority},
authority_client::LocalAuthorityClient,
checkpoints::checkpoint_tests::TestSetup,
gateway_state::GatewayMetrics,
safe_client::SafeClient,
};

Expand Down Expand Up @@ -35,6 +36,7 @@ async fn checkpoint_active_flow_happy_path() {
ActiveAuthority::new_with_ephemeral_follower_store(
inner_state.authority.clone(),
clients,
GatewayMetrics::new_for_tests(),
)
.unwrap(),
);
Expand Down Expand Up @@ -112,6 +114,7 @@ async fn checkpoint_active_flow_crash_client_with_gossip() {
ActiveAuthority::new_with_ephemeral_follower_store(
inner_state.authority.clone(),
clients,
GatewayMetrics::new_for_tests(),
)
.unwrap(),
);
Expand Down Expand Up @@ -202,6 +205,7 @@ async fn checkpoint_active_flow_crash_client_no_gossip() {
ActiveAuthority::new_with_ephemeral_follower_store(
inner_state.authority.clone(),
clients,
GatewayMetrics::new_for_tests(),
)
.unwrap(),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use crate::gateway_state::GatewayMetrics;
use crate::{authority_active::ActiveAuthority, checkpoints::checkpoint_tests::TestSetup};

use std::sync::Arc;
Expand Down Expand Up @@ -33,6 +34,7 @@ async fn pending_exec_storage_notify() {
ActiveAuthority::new_with_ephemeral_follower_store(
inner_state.authority.clone(),
clients,
GatewayMetrics::new_for_tests(),
)
.unwrap(),
);
Expand Down Expand Up @@ -113,6 +115,7 @@ async fn pending_exec_full() {
ActiveAuthority::new_with_ephemeral_follower_store(
inner_state.authority.clone(),
clients,
GatewayMetrics::new_for_tests(),
)
.unwrap(),
);
Expand Down
17 changes: 13 additions & 4 deletions crates/sui-core/src/authority_active/gossip/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::authority_active::gossip::configurable_batch_action_client::{
init_configurable_authorities, BatchAction,
};
use crate::authority_active::MAX_RETRY_DELAY_MS;
use crate::gateway_state::GatewayMetrics;
use std::time::Duration;

#[tokio::test(flavor = "current_thread", start_paused = true)]
Expand All @@ -26,8 +27,12 @@ pub async fn test_gossip_plain() {

let handle = tokio::task::spawn(async move {
let active_state = Arc::new(
ActiveAuthority::new_with_ephemeral_follower_store(inner_state, inner_clients)
.unwrap(),
ActiveAuthority::new_with_ephemeral_follower_store(
inner_state,
inner_clients,
GatewayMetrics::new_for_tests(),
)
.unwrap(),
);
active_state.spawn_gossip_process(3).await;
});
Expand Down Expand Up @@ -69,8 +74,12 @@ pub async fn test_gossip_error() {

let handle = tokio::task::spawn(async move {
let active_state = Arc::new(
ActiveAuthority::new_with_ephemeral_follower_store(inner_state, inner_clients)
.unwrap(),
ActiveAuthority::new_with_ephemeral_follower_store(
inner_state,
inner_clients,
GatewayMetrics::new_for_tests(),
)
.unwrap(),
);
active_state.spawn_gossip_process(3).await;
});
Expand Down
15 changes: 10 additions & 5 deletions crates/sui-core/src/authority_aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

use crate::authority_client::AuthorityAPI;
use crate::gateway_state::{GatewayMetrics, METRICS};
use crate::gateway_state::GatewayMetrics;
use crate::safe_client::SafeClient;
use async_trait::async_trait;

Expand Down Expand Up @@ -59,18 +59,23 @@ pub struct AuthorityAggregator<A> {
/// How to talk to this committee.
pub authority_clients: BTreeMap<AuthorityName, SafeClient<A>>,
// Metrics
pub metrics: &'static GatewayMetrics,
pub metrics: GatewayMetrics,
pub timeouts: TimeoutConfig,
}

impl<A> AuthorityAggregator<A> {
pub fn new(committee: Committee, authority_clients: BTreeMap<AuthorityName, A>) -> Self {
Self::new_with_timeouts(committee, authority_clients, Default::default())
pub fn new(
committee: Committee,
authority_clients: BTreeMap<AuthorityName, A>,
metrics: GatewayMetrics,
) -> Self {
Self::new_with_timeouts(committee, authority_clients, metrics, Default::default())
}

pub fn new_with_timeouts(
committee: Committee,
authority_clients: BTreeMap<AuthorityName, A>,
metrics: GatewayMetrics,
timeouts: TimeoutConfig,
) -> Self {
Self {
Expand All @@ -79,7 +84,7 @@ impl<A> AuthorityAggregator<A> {
.into_iter()
.map(|(name, api)| (name, SafeClient::new(api, committee.clone(), name)))
.collect(),
metrics: &METRICS,
metrics,
timeouts,
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/sui-core/src/checkpoints/tests/checkpoint_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
},
authority_batch::batch_tests::init_state_parameters_from_rng,
authority_client::LocalAuthorityClient,
gateway_state::GatewayMetrics,
};
use rand::prelude::StdRng;
use rand::SeedableRng;
Expand Down Expand Up @@ -1471,6 +1472,7 @@ pub async fn checkpoint_tests_setup(num_objects: usize, batch_interval: Duration
)
})
.collect(),
GatewayMetrics::new_for_tests(),
);

TestSetup {
Expand Down
Loading

0 comments on commit b4e5791

Please sign in to comment.