Skip to content

Commit

Permalink
Introduce txpool and p2p metrics (#717)
Browse files Browse the repository at this point in the history
* Upgrade tokio dependency to 1.21

* init stuff

* progress?

* issues

* issues

* progress

* progress

* reworked how txpool metrics are structured

* added txpool metrics

* fmt + cleanup

* added some p2p metrics

* updated test

* updated test

* fmt

* clippy

* clippy tricked me

* merge issues

* fmt

* updated

* Update metrics.rs

* reworked to be better

* fixed test, still a little left todo

* fixed test, still a little left todo

* all green?

* fixed some review comments

* more review comments

* fixed unwrap

* fixed

* fixed p2p args

* prod

Co-authored-by: Hannes Karppila <hannes.karppila@gmail.com>
  • Loading branch information
ControlCplusControlV and Dentosal authored Nov 9, 2022
1 parent 22b8dd4 commit b502450
Show file tree
Hide file tree
Showing 22 changed files with 446 additions and 169 deletions.
159 changes: 137 additions & 22 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion fuel-block-executor/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pub struct Config {
/// Print execution backtraces if transaction execution reverts.
pub backtrace: bool,

/// Enables prometheus metrics for this fuel-service
pub metrics: bool,
}
2 changes: 1 addition & 1 deletion fuel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ debug = ["fuel-core-interfaces/debug"]
relayer = ["dep:fuel-relayer"]
p2p = ["dep:fuel-p2p"]
# features to enable in production, but increase build times
production = ["rocksdb?/jemalloc", "relayer"]
production = ["rocksdb?/jemalloc", "metrics", "relayer"]
12 changes: 7 additions & 5 deletions fuel-core/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,13 @@ impl Command {
let addr = net::SocketAddr::new(ip, port);

#[cfg(feature = "p2p")]
let p2p = {
match p2p_args.into() {
let p2p_cfg = {
let mut p2p = match p2p_args.into() {
Ok(value) => value,
Err(e) => return Err(e),
}
};
p2p.metrics = metrics;
p2p
};

let chain_conf: ChainConfig = chain_config.as_str().parse()?;
Expand Down Expand Up @@ -191,14 +193,14 @@ impl Command {
block_producer: fuel_block_producer::Config {
utxo_validation,
coinbase_recipient,
metrics: false,
metrics,
},
block_executor: Default::default(),
#[cfg(feature = "relayer")]
relayer: relayer_args.into(),
sync: Default::default(),
#[cfg(feature = "p2p")]
p2p,
p2p: p2p_cfg,
consensus_key,
})
}
Expand Down
4 changes: 2 additions & 2 deletions fuel-core/src/service/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use axum::{
response::IntoResponse,
};
#[cfg(feature = "metrics")]
use fuel_metrics::core_metrics::encode_metrics_response;
use fuel_metrics::service::encode_metrics_response;

pub async fn metrics(_req: Request<Body>) -> impl IntoResponse {
#[cfg(feature = "metrics")]
Expand All @@ -14,6 +14,6 @@ pub async fn metrics(_req: Request<Body>) -> impl IntoResponse {
#[cfg(not(feature = "metrics"))]
{
use axum::http::StatusCode;
(StatusCode::NOT_FOUND, "metrics collection disabled")
(StatusCode::NOT_FOUND, "Metrics collection disabled")
}
}
1 change: 1 addition & 0 deletions fuel-core/src/service/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ pub async fn start_modules(config: &Config, database: &Database) -> Result<Modul
block_event_sender,
)
};

#[cfg(not(feature = "p2p"))]
{
let keep_alive = Box::new(incoming_tx_sender);
Expand Down
16 changes: 7 additions & 9 deletions fuel-core/src/state/rocks_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ impl KeyValueStore for RocksDb {
if value.is_ok() && value.as_ref().unwrap().is_some() {
let value_as_vec = value.as_ref().cloned().unwrap().unwrap();
DATABASE_METRICS
.bytes_read_meter
.inc_by(value_as_vec.len() as u64);
.bytes_read
.observe(value_as_vec.len() as f64);
}
}
value
Expand All @@ -156,9 +156,7 @@ impl KeyValueStore for RocksDb {
#[cfg(feature = "metrics")]
{
DATABASE_METRICS.write_meter.inc();
DATABASE_METRICS
.bytes_written_meter
.inc_by(value.len() as u64);
DATABASE_METRICS.bytes_written.observe(value.len() as f64);
}
let prev = self.get(key, column)?;
self.db
Expand Down Expand Up @@ -233,8 +231,8 @@ impl KeyValueStore for RocksDb {
{
DATABASE_METRICS.read_meter.inc();
DATABASE_METRICS
.bytes_read_meter
.inc_by(key_as_vec.len() as u64 + value_as_vec.len() as u64);
.bytes_read
.observe((key_as_vec.len() + value_as_vec.len()) as f64);
}
(key_as_vec, value_as_vec)
})
Expand Down Expand Up @@ -278,8 +276,8 @@ impl BatchOperations for RocksDb {
{
DATABASE_METRICS.write_meter.inc();
DATABASE_METRICS
.bytes_written_meter
.inc_by(batch.size_in_bytes() as u64);
.bytes_written
.observe(batch.size_in_bytes() as f64);
}
self.db
.write(batch)
Expand Down
Loading

0 comments on commit b502450

Please sign in to comment.