Skip to content

Commit

Permalink
fix(metrics): removed influx and added l2_state_size data (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
antiyro authored Jul 18, 2024
1 parent f8ca2f2 commit 3582291
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- fix(metrics): removed influx and added l2_state_size data
- fix: command to start the Madara client
- refactor: database error unification
- feat: raise file-descriptor limit
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/client/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]

# Deoxys
dc-metrics = { workspace = true }
dp-block = { workspace = true }
dp-class = { workspace = true }
dp-convert = { workspace = true }
Expand Down
15 changes: 15 additions & 0 deletions crates/client/db/src/db_metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use dc_metrics::{IntGaugeVec, MetricsRegistry, Opts, PrometheusError};

#[derive(Clone, Debug)]
pub struct DbMetrics {
pub column_sizes: IntGaugeVec,
}

impl DbMetrics {
pub fn register(registry: &MetricsRegistry) -> Result<Self, PrometheusError> {
Ok(Self {
column_sizes: registry
.register(IntGaugeVec::new(Opts::new("column_sizes", "Sizes of RocksDB columns"), &["column"])?)?,
})
}
}
17 changes: 17 additions & 0 deletions crates/client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use block_db::ChainInfo;
use bonsai_db::{BonsaiDb, DatabaseKeyMapping};
use bonsai_trie::id::BasicId;
use bonsai_trie::{BonsaiStorage, BonsaiStorageConfig};
use db_metrics::DbMetrics;
use rocksdb::backup::{BackupEngine, BackupEngineOptions};

pub mod block_db;
Expand All @@ -23,6 +24,7 @@ pub mod bonsai_db;
pub mod class_db;
pub mod contract_db;
pub mod db_block_id;
pub mod db_metrics;
pub mod storage_updates;

pub use error::{DeoxysStorageError, TrieType};
Expand Down Expand Up @@ -447,6 +449,21 @@ impl DeoxysBackend {
log: Column::BonsaiClassesLog,
})
}

pub fn get_storage_size(&self, db_metrics: &DbMetrics) -> u64 {
let mut storage_size = 0;

for &column in Column::ALL.iter() {
let cf_handle = self.db.get_column(column);
let cf_metadata = self.db.get_column_family_metadata_cf(&cf_handle);
let column_size = cf_metadata.size;
storage_size += column_size;

db_metrics.column_sizes.with_label_values(&[column.rocksdb_name()]).set(column_size as i64);
}

storage_size
}
}

pub mod bonsai_identifier {
Expand Down
2 changes: 1 addition & 1 deletion crates/client/metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use prometheus::{
AtomicF64 as F64, AtomicI64 as I64, AtomicU64 as U64, GenericCounter as Counter,
GenericCounterVec as CounterVec, GenericGauge as Gauge, GenericGaugeVec as GaugeVec,
},
exponential_buckets, Error as PrometheusError, Histogram, HistogramOpts, HistogramVec, Opts, Registry,
exponential_buckets, Error as PrometheusError, Histogram, HistogramOpts, HistogramVec, IntGaugeVec, Opts, Registry,
};

#[derive(Clone, Debug)]
Expand Down
24 changes: 23 additions & 1 deletion crates/client/sync/src/l2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::sync::{Arc, Mutex};
use std::time::Instant;

use anyhow::{bail, Context};
use dc_db::db_metrics::DbMetrics;
use dc_db::DeoxysBackend;
use dc_db::DeoxysStorageError;
use dc_telemetry::{TelemetryHandle, VerbosityLevel};
Expand Down Expand Up @@ -59,6 +60,7 @@ async fn l2_verify_and_apply_task(
verify: bool,
backup_every_n_blocks: Option<u64>,
block_metrics: BlockMetrics,
db_metrics: DbMetrics,
starting_block: u64,
sync_timer: Arc<Mutex<Option<Instant>>>,
telemetry: TelemetryHandle,
Expand Down Expand Up @@ -118,7 +120,16 @@ async fn l2_verify_and_apply_task(
})
.await?;

update_sync_metrics(block_n, &block_header, starting_block, &block_metrics, sync_timer.clone()).await?;
update_sync_metrics(
block_n,
&block_header,
starting_block,
&block_metrics,
&db_metrics,
sync_timer.clone(),
&backend,
)
.await?;

let sw = PerfStopwatch::new();
if backend.maybe_flush(false)? {
Expand Down Expand Up @@ -287,11 +298,13 @@ pub struct L2SyncConfig {
}

/// Spawns workers to fetch blocks and state updates from the feeder.
#[allow(clippy::too_many_arguments)]
pub async fn sync(
backend: &Arc<DeoxysBackend>,
provider: SequencerGatewayProvider,
config: L2SyncConfig,
block_metrics: BlockMetrics,
db_metrics: DbMetrics,
starting_block: u64,
chain_id: Felt,
telemetry: TelemetryHandle,
Expand Down Expand Up @@ -329,6 +342,7 @@ pub async fn sync(
config.verify,
config.backup_every_n_blocks,
block_metrics,
db_metrics,
starting_block,
Arc::clone(&sync_timer),
telemetry,
Expand All @@ -353,7 +367,9 @@ async fn update_sync_metrics(
block_header: &Header,
starting_block: u64,
block_metrics: &BlockMetrics,
db_metrics: &DbMetrics,
sync_timer: Arc<Mutex<Option<Instant>>>,
backend: &DeoxysBackend,
) -> anyhow::Result<()> {
// Update Block sync time metrics
let elapsed_time;
Expand Down Expand Up @@ -381,6 +397,12 @@ async fn update_sync_metrics(
block_metrics.l1_gas_price_wei.set(f64::from_u128(block_header.l1_gas_price.eth_l1_gas_price).unwrap_or(0f64));
block_metrics.l1_gas_price_strk.set(f64::from_u128(block_header.l1_gas_price.strk_l1_gas_price).unwrap_or(0f64));

if block_number % 200 == 0 {
let storage_size = backend.get_storage_size(db_metrics);
let size_gb = storage_size as f64 / (1024 * 1024 * 1024) as f64;
block_metrics.l2_state_size.set(size_gb);
}

Ok(())
}

Expand Down
4 changes: 3 additions & 1 deletion crates/client/sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub mod starknet_sync_worker {
use std::{sync::Arc, time::Duration};

use anyhow::Context;
use dc_db::DeoxysBackend;
use dc_db::{db_metrics::DbMetrics, DeoxysBackend};
use dc_telemetry::TelemetryHandle;
use reqwest::Url;
use starknet_providers::SequencerGatewayProvider;
Expand All @@ -38,6 +38,7 @@ pub mod starknet_sync_worker {
starting_block: Option<u64>,
backup_every_n_blocks: Option<u64>,
block_metrics: BlockMetrics,
db_metrics: DbMetrics,
chain_id: Felt,
telemetry: TelemetryHandle,
pending_block_poll_interval: Duration,
Expand Down Expand Up @@ -89,6 +90,7 @@ pub mod starknet_sync_worker {
pending_block_poll_interval,
},
block_metrics,
db_metrics,
starting_block,
chain_id,
telemetry,
Expand Down
3 changes: 3 additions & 0 deletions crates/client/sync/src/metrics/block_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct BlockMetrics {
pub l2_sync_time: Gauge<F64>,
pub l2_avg_sync_time: Gauge<F64>,
pub l2_latest_sync_time: Gauge<F64>,
pub l2_state_size: Gauge<F64>,
pub transaction_count: Gauge<F64>,
pub event_count: Gauge<F64>,
// L1 network metrics
Expand All @@ -25,6 +26,8 @@ impl BlockMetrics {
.register(Gauge::new("deoxys_l2_avg_sync_time", "Gauge for deoxys L2 average sync time")?)?,
l2_latest_sync_time: registry
.register(Gauge::new("deoxys_l2_latest_sync_time", "Gauge for deoxys L2 latest sync time")?)?,
l2_state_size: registry
.register(Gauge::new("deoxys_l2_state_size", "Gauge for node storage usage in GB")?)?,
l1_block_number: registry
.register(Gauge::new("deoxys_l1_block_number", "Gauge for deoxys L1 block number")?)?,
transaction_count: registry
Expand Down
6 changes: 6 additions & 0 deletions crates/node/src/service/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::sync::Arc;
use std::time::Duration;

use anyhow::Context;
use dc_db::db_metrics::DbMetrics;
use dc_db::{DatabaseService, DeoxysBackend};
use dc_metrics::MetricsRegistry;
use dc_sync::fetch::fetchers::FetchConfig;
Expand All @@ -24,6 +25,7 @@ pub struct SyncService {
l1_core_address: H160,
starting_block: Option<u64>,
block_metrics: BlockMetrics,
db_metrics: DbMetrics,
chain_id: Felt,
start_params: Option<TelemetryHandle>,
disabled: bool,
Expand All @@ -38,6 +40,7 @@ impl SyncService {
telemetry: TelemetryHandle,
) -> anyhow::Result<Self> {
let block_metrics = BlockMetrics::register(&metrics_handle)?;
let db_metrics = DbMetrics::register(&metrics_handle)?;
let fetch_config = config.block_fetch_config();

let l1_endpoint = if !config.sync_l1_disabled {
Expand All @@ -59,6 +62,7 @@ impl SyncService {
starting_block: config.starting_block,
backup_every_n_blocks: config.backup_every_n_blocks,
block_metrics,
db_metrics,
chain_id: config.network.chain_id(),
start_params: Some(telemetry),
disabled: config.sync_disabled,
Expand All @@ -76,6 +80,7 @@ impl SyncService {
l1_core_address,
starting_block,
block_metrics,
db_metrics,
chain_id,
pending_block_poll_interval,
..
Expand All @@ -92,6 +97,7 @@ impl SyncService {
starting_block,
backup_every_n_blocks,
block_metrics,
db_metrics,
chain_id,
telemetry,
pending_block_poll_interval,
Expand Down
30 changes: 0 additions & 30 deletions infra/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,36 +93,6 @@ services:
- ./grafana/dashboards:/var/lib/grafana/dashboards
- ./grafana/datasources/datasource.yml:/etc/grafana/provisioning/datasources/main.yml

influxdb:
container_name: influxdb
image: influxdb:latest
restart: unless-stopped
ports:
- "8086:8086"
volumes:
- ./influxdb:/var/lib/influxdb
environment:
- INFLUXDB_DB=mydb
- INFLUXDB_HTTP_AUTH_ENABLED=true
- INFLUXDB_ADMIN_USER=admin
- INFLUXDB_ADMIN_PASSWORD=adminpassword
- INFLUXDB_USER=user
- INFLUXDB_USER_PASSWORD=userpassword

telegraf:
container_name: telegraf
image: telegraf:latest
restart: unless-stopped
volumes:
- ./telegraf/etc/telegraf.conf:/etc/telegraf/telegraf.conf:ro
- /var/lib/deoxys:/var/lib/deoxys
depends_on:
- influxdb
links:
- influxdb
ports:
- "8125:8125"

networks:
loki-net:
external: true

0 comments on commit 3582291

Please sign in to comment.