Skip to content

Commit

Permalink
warn if some charts are unused
Browse files Browse the repository at this point in the history
  • Loading branch information
bragov4ik committed Dec 26, 2024
1 parent 15254b5 commit c08dd6e
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 3 deletions.
54 changes: 54 additions & 0 deletions stats/stats-server/src/read_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,60 @@ fn get_counter_query_handle(name: &str, counter: &EnabledChartEntry) -> Option<C
.into_counter_handle()
}

impl ReadService {
pub fn main_page_charts() -> Vec<String> {
// ensure that changes to api are reflected here
proto_v1::MainPageStats {
average_block_time: None,
total_addresses: None,
total_blocks: None,
total_txns: None,
yesterday_txns: None,
transactions: None,
};
vec![
AverageBlockTime::name(),
TotalAddresses::name(),
TotalBlocks::name(),
TotalTxns::name(),
YesterdayTxns::name(),
NewTxnsWindow::name(),
]
}

pub fn contracts_page_charts() -> Vec<String> {
// ensure that changes to api are reflected here
proto_v1::ContractsPageStats {
total_contracts: None,
new_contracts_24h: None,
total_verified_contracts: None,
new_verified_contracts_24h: None,
};
vec![
TotalContracts::name(),
NewContracts24h::name(),
TotalVerifiedContracts::name(),
NewVerifiedContracts24h::name(),
]
}

pub fn transactions_page_charts() -> Vec<String> {
// ensure that changes to api are reflected here
proto_v1::TransactionsPageStats {
pending_txns: None,
txns_fee_24h: None,
average_txn_fee_24h: None,
total_txns: None,
};
vec![
PendingTxns::name(),
TxnsFee24h::name(),
AverageTxnFee24h::name(),
TotalTxns::name(),
]
}
}

impl ReadService {
async fn query_with_handle<Data: Send>(
&self,
Expand Down
51 changes: 48 additions & 3 deletions stats/stats-server/src/runtime_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
//! new charts to integration tests (`tests` folder).
//!
use crate::config::{
self,
types::{AllChartSettings, EnabledChartSettings, LineChartCategory},
use crate::{
config::{
self,
types::{AllChartSettings, EnabledChartSettings, LineChartCategory},
},
ReadService,
};
use cron::Schedule;
use itertools::Itertools;
Expand Down Expand Up @@ -137,6 +140,7 @@ impl RuntimeSetup {
update_groups: config::update_groups::Config,
) -> anyhow::Result<Self> {
let charts_info = Self::build_charts_info(charts)?;
Self::check_all_enabled_charts_have_endpoints(charts_info.keys().collect(), &layout);
let update_groups = Self::init_update_groups(update_groups, &charts_info)?;
Ok(Self {
lines_layout: layout.line_chart_categories,
Expand Down Expand Up @@ -250,6 +254,47 @@ impl RuntimeSetup {
.map_err(|duplicate_name| anyhow::anyhow!("duplicate chart name: {duplicate_name:?}",))
}

/// Warns charts that are both enabled and will be updated,
/// but which are not returned by any endpoint (making the updates
/// very likely useless).
///
/// In other words, any enabled chart should be accessible from
/// the outside.
fn check_all_enabled_charts_have_endpoints<'a>(
mut enabled_names: HashSet<&'a String>,
layout: &'a config::layout::Config,
) {
// general stats handles
for counter in &layout.counters_order {
enabled_names.remove(&counter);
}
for line_chart in layout
.line_chart_categories
.iter()
.flat_map(|cat| cat.charts_order.iter())
{
enabled_names.remove(&line_chart);
}
// pages
let charts_in_pages = [
ReadService::main_page_charts(),
ReadService::contracts_page_charts(),
ReadService::transactions_page_charts(),
]
.concat();
for chart in charts_in_pages {
enabled_names.remove(&chart);
}

if !enabled_names.is_empty() {
tracing::warn!(
endpointless_charts =? enabled_names,
"Some charts are updated but not returned \
by any endpoint. This is likely a bug, please report it."
);
}
}

fn all_update_groups() -> Vec<ArcUpdateGroup> {
use stats::update_groups::*;

Expand Down

0 comments on commit c08dd6e

Please sign in to comment.