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

feat: forester: enable optional metrics reporting via CLI flag #1164

Merged
merged 1 commit into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions forester/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use clap::{Parser, Subcommand};
#[derive(Parser)]
#[clap(author, version, about, long_about=None)]
pub struct Cli {
#[arg(long, default_value_t = false, global = true)]
pub enable_metrics: bool,

#[command(subcommand)]
pub command: Option<Commands>,
}
Expand Down
2 changes: 2 additions & 0 deletions forester/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub struct ForesterConfig {
pub slot_update_interval_seconds: u64,
pub address_tree_data: Vec<TreeAccounts>,
pub state_tree_data: Vec<TreeAccounts>,
pub enable_metrics: bool,
}

impl Clone for ForesterConfig {
Expand All @@ -68,6 +69,7 @@ impl Clone for ForesterConfig {
state_tree_data: self.state_tree_data.clone(),
address_tree_data: self.address_tree_data.clone(),
slot_update_interval_seconds: self.slot_update_interval_seconds,
enable_metrics: self.enable_metrics,
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions forester/src/epoch_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,19 +664,21 @@ impl<R: RpcConnection, I: Indexer<R>> EpochManager<R, I> {
let num_tx_sent = num_tx_sent.await?;
// Prometheus metrics
let chunk_duration = start_time.elapsed();
queue_metric_update(epoch_info.epoch, num_tx_sent, chunk_duration).await;

if self.config.enable_metrics {
queue_metric_update(epoch_info.epoch, num_tx_sent, chunk_duration).await;
}
// TODO: consider do we really need WorkReport
self.increment_processed_items_count(epoch_info.epoch, num_tx_sent)
.await;
} else {
// The forester is not eligible for any more slots in the current epoch
break;
}

process_queued_metrics().await;
if let Err(e) = push_metrics(&self.config.external_services.pushgateway_url).await {
error!("Failed to push metrics: {:?}", e);
if self.config.enable_metrics {
process_queued_metrics().await;
if let Err(e) = push_metrics(&self.config.external_services.pushgateway_url).await {
error!("Failed to push metrics: {:?}", e);
}
}

estimated_slot = self.slot_tracker.estimated_current_slot();
Expand Down
17 changes: 11 additions & 6 deletions forester/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ use tracing::{debug, warn};
#[tokio::main]
async fn main() -> Result<(), ForesterError> {
setup_telemetry();
register_metrics();

let config = match init_config() {
let cli = Cli::parse();

if cli.enable_metrics {
register_metrics();
}

let config = match init_config(cli.enable_metrics) {
Ok(config) => Arc::new(config),
Err(e) => {
panic!("Failed to initialize config: {}", e);
}
};

let cli = Cli::parse();

match &cli.command {
Some(Commands::Start) => {
let (shutdown_sender, shutdown_receiver) = oneshot::channel();
Expand Down Expand Up @@ -65,8 +68,10 @@ async fn main() -> Result<(), ForesterError> {
run_queue_info(config.clone(), trees.clone(), TreeType::State).await;
run_queue_info(config.clone(), trees.clone(), TreeType::Address).await;

if let Err(e) = push_metrics(&config.external_services.pushgateway_url).await {
warn!("Failed to push metrics: {:?}", e);
if cli.enable_metrics {
if let Err(e) = push_metrics(&config.external_services.pushgateway_url).await {
warn!("Failed to push metrics: {:?}", e);
}
}
}
None => {}
Expand Down
3 changes: 2 additions & 1 deletion forester/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn build_config() -> Result<Config, ForesterError> {
.map_err(|e| ForesterError::ConfigError(e.to_string()))
}

pub fn init_config() -> Result<ForesterConfig, ForesterError> {
pub fn init_config(enable_metrics: bool) -> Result<ForesterConfig, ForesterError> {
let settings = build_config()?;
let registry_pubkey = light_registry::program::LightRegistry::id().to_string();

Expand Down Expand Up @@ -135,6 +135,7 @@ pub fn init_config() -> Result<ForesterConfig, ForesterError> {
as u64,
address_tree_data: vec![],
state_tree_data: vec![],
enable_metrics,
};

debug!("Config: {:?}", config);
Expand Down
1 change: 1 addition & 0 deletions forester/tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub fn forester_config() -> ForesterConfig {
slot_update_interval_seconds: 10,
address_tree_data: vec![],
state_tree_data: vec![],
enable_metrics: false,
}
}

Expand Down