Skip to content

Commit

Permalink
add env
Browse files Browse the repository at this point in the history
  • Loading branch information
bragov4ik committed Dec 13, 2024
1 parent f6525ba commit f3ca312
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
1 change: 1 addition & 0 deletions stats/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion stats/stats-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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,
Expand Down
40 changes: 37 additions & 3 deletions stats/stats-server/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<bool>, // None = no update
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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;
}
};
Expand All @@ -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<AllChartSettings>,
) {
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)]
Expand Down

0 comments on commit f3ca312

Please sign in to comment.