Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused storage from block-time tracker #565

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions block-time/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ use crossterm::{
};
use log::{debug, info, warn};
use polkadot_introspector_essentials::{
api::ApiService,
api::subxt_wrapper::RequestExecutor,
chain_head_subscription::ChainHeadSubscription,
chain_subscription::ChainSubscriptionEvent,
constants::MAX_MSG_QUEUE_SIZE,
consumer::{EventConsumerInit, EventStream},
init,
storage::RecordsStorageConfig,
types::H256,
utils,
init, utils,
};
use polkadot_introspector_priority_channel::{channel, Receiver, Sender};
use prometheus_endpoint::{HistogramVec, Registry};
Expand Down Expand Up @@ -97,14 +94,13 @@ struct BlockTimeMonitor {
opts: BlockTimeOptions,
block_time_metric: Option<HistogramVec>,
endpoints: Vec<String>,
api_service: ApiService<H256>,
executor: RequestExecutor,
active_endpoints: usize,
}

impl BlockTimeMonitor {
pub fn new(opts: BlockTimeOptions) -> color_eyre::Result<Self> {
// This starts the both the storage and subxt APIs.
let api_service = ApiService::new_with_storage(RecordsStorageConfig { max_blocks: 1000 }, opts.retry.clone());
let executor = RequestExecutor::new(opts.retry.clone());
let endpoints = opts.nodes.clone();
let active_endpoints = endpoints.len();

Expand All @@ -117,10 +113,10 @@ impl BlockTimeMonitor {
socket_addr_str.to_socket_addrs()?.for_each(|addr| {
tokio::spawn(prometheus_endpoint::init_prometheus(addr, prometheus_registry.clone()));
});
Ok(BlockTimeMonitor { opts, block_time_metric, endpoints, api_service, active_endpoints })
Ok(BlockTimeMonitor { opts, block_time_metric, endpoints, executor, active_endpoints })
},
BlockTimeMode::Cli(_) =>
Ok(BlockTimeMonitor { opts, block_time_metric: None, endpoints, api_service, active_endpoints }),
Ok(BlockTimeMonitor { opts, block_time_metric: None, endpoints, executor, active_endpoints }),
}
}

Expand All @@ -142,7 +138,7 @@ impl BlockTimeMonitor {
endpoint,
self.block_time_metric.clone(),
update_channel,
self.api_service.clone(),
self.executor.clone(),
message_tx.clone(),
))
})
Expand Down Expand Up @@ -251,18 +247,17 @@ impl BlockTimeMonitor {
metric: Option<prometheus_endpoint::HistogramVec>,
// TODO: make this a struct.
consumer_config: Receiver<ChainSubscriptionEvent>,
api_service: ApiService<H256>,
mut executor: RequestExecutor,
mut message_tx: Sender<BlockTimeMessage>,
) {
// Make static string out of uri so we can use it as Prometheus label.
let url = leak_static_str(url);
match opts.clone().mode {
BlockTimeMode::Prometheus(_) => {},
BlockTimeMode::Cli(cli_opts) => {
populate_view(url, cli_opts, message_tx.clone(), api_service.clone()).await;
populate_view(url, cli_opts, message_tx.clone(), executor.clone()).await;
},
}
let mut executor = api_service.subxt();

let mut prev_ts = 0;
let mut prev_block = 0u32;
Expand Down Expand Up @@ -335,11 +330,10 @@ async fn populate_view(
url: &str,
cli_opts: BlockTimeCliOptions,
mut message_tx: Sender<BlockTimeMessage>,
api_service: ApiService<H256>,
mut executor: RequestExecutor,
) {
let mut prev_ts = 0u64;
let blocks_to_fetch = cli_opts.chart_width;
let mut executor = api_service.subxt();
let mut block_times: Vec<u64> = Vec::with_capacity(blocks_to_fetch);

let mut parent_hash = None;
Expand Down