From f3ca312551b6d38ee70a7de330bb78944e02efc0 Mon Sep 17 00:00:00 2001 From: Kirill Ivanov Date: Sat, 14 Dec 2024 00:41:54 +0900 Subject: [PATCH] add env --- stats/README.md | 1 + stats/stats-server/src/server.rs | 3 ++- stats/stats-server/src/settings.rs | 40 +++++++++++++++++++++++++++--- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/stats/README.md b/stats/README.md index ca41c1695..9249a4562 100644 --- a/stats/README.md +++ b/stats/README.md @@ -92,6 +92,7 @@ by enabling word wrapping | `STATS__CONDITIONAL_​START__INTERNAL_​TRANSACTIONS_RATIO__​THRESHOLD` | | Value for `internal_​transactions_​ratio` threshold | `0.98` | | `STATS__IGNORE_​BLOCKSCOUT_API_ABSENCE` | | Disable requirement for blockscout api url setting. Turns off corresponding features if the api setting is not set | `false` | | `STATS__DISABLE_​INTERNAL_TRANSACTIONS` | | Disable functionality that utilizes internal transactions. In particular, disable internal transactions ratio check for starting the service and related charts (`newContracts`, `lastNewContracts`, and `contractsGrowth`). It has a higher priority than config files and respective envs. | `false` | +| `STATS__ENABLE_​ALL_ARBITRUM` | | Enable Arbitrum-specific charts. Variable for convenience only, the same can be done manually in configs. | `false` | [anchor]: <> (anchors.envs.end.service) diff --git a/stats/stats-server/src/server.rs b/stats/stats-server/src/server.rs index 16f62db3d..b03c17e18 100644 --- a/stats/stats-server/src/server.rs +++ b/stats/stats-server/src/server.rs @@ -6,7 +6,7 @@ use crate::{ health::HealthService, read_service::ReadService, runtime_setup::RuntimeSetup, - settings::{handle_disable_internal_transactions, Settings}, + settings::{handle_disable_internal_transactions, handle_enable_all_arbitrum, Settings}, update_service::UpdateService, }; @@ -66,6 +66,7 @@ pub async fn stats(mut settings: Settings) -> Result<(), anyhow::Error> { let mut charts_config = read_charts_config(&settings.charts_config)?; let layout_config = read_layout_config(&settings.layout_config)?; let update_groups_config = read_update_groups_config(&settings.update_groups_config)?; + handle_enable_all_arbitrum(settings.enable_all_arbitrum, &mut charts_config); handle_disable_internal_transactions( settings.disable_internal_transactions, &mut settings.conditional_start, diff --git a/stats/stats-server/src/settings.rs b/stats/stats-server/src/settings.rs index 3cd9ffb7a..ef5af96ad 100644 --- a/stats/stats-server/src/settings.rs +++ b/stats/stats-server/src/settings.rs @@ -8,8 +8,8 @@ use cron::Schedule; use serde::{Deserialize, Serialize}; use serde_with::{serde_as, DisplayFromStr}; use stats::{ - counters::LastNewContracts, - lines::{ContractsGrowth, NewContracts}, + counters::{LastNewContracts, TotalOperationalTxns}, + lines::{ContractsGrowth, NewContracts, NewOperationalTxns, OperationalTxnsGrowth}, ChartProperties, }; use std::{net::SocketAddr, path::PathBuf, str::FromStr}; @@ -37,6 +37,8 @@ pub struct Settings { /// /// It has a higher priority than config files and respective envs. pub disable_internal_transactions: bool, + /// Enable arbitrum-specific charts + pub enable_all_arbitrum: bool, #[serde_as(as = "DisplayFromStr")] pub default_schedule: Schedule, pub force_update_on_start: Option, // None = no update @@ -84,6 +86,7 @@ impl Default for Settings { blockscout_api_url: None, ignore_blockscout_api_absence: false, disable_internal_transactions: false, + enable_all_arbitrum: false, create_database: Default::default(), run_migrations: Default::default(), metrics: Default::default(), @@ -115,7 +118,8 @@ pub fn handle_disable_internal_transactions( warn!( "Could not disable internal transactions related chart {}: chart not found in settings. \ This should not be a problem for running the service.", - disable_key); + disable_key + ); continue; } }; @@ -124,6 +128,36 @@ pub fn handle_disable_internal_transactions( } } +pub fn handle_enable_all_arbitrum( + enable_all_arbitrum: bool, + charts: &mut config::charts::Config, +) { + if enable_all_arbitrum { + for enable_key in [ + NewOperationalTxns::key().name(), + OperationalTxnsGrowth::key().name(), + TotalOperationalTxns::key().name(), + ] { + let settings = match ( + charts.lines.get_mut(enable_key), + charts.counters.get_mut(enable_key), + ) { + (Some(settings), _) => settings, + (_, Some(settings)) => settings, + _ => { + warn!( + "Could not enable arbitrum-specific chart {}: chart not found in settings. \ + This should not be a problem for running the service.", + enable_key + ); + continue; + } + }; + settings.enabled = true; + } + } +} + /// Various limits like rate limiting and restrictions on input. #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(default, deny_unknown_fields)]