chore(metrics): restructure crates (#2850)

This commit is contained in:
Roman Krasiuk
2023-05-26 15:21:48 +03:00
committed by GitHub
parent 966b31c191
commit 10b577096b
34 changed files with 110 additions and 119 deletions

33
Cargo.lock generated
View File

@ -4586,7 +4586,6 @@ dependencies = [
"human_bytes",
"hyper",
"jemallocator",
"metrics",
"metrics-exporter-prometheus",
"metrics-util",
"pin-project",
@ -4600,6 +4599,7 @@ dependencies = [
"reth-discv4",
"reth-downloaders",
"reth-interfaces",
"reth-metrics",
"reth-net-nat",
"reth-network",
"reth-network-api",
@ -4653,8 +4653,7 @@ version = "0.1.0"
dependencies = [
"futures-core",
"futures-util",
"metrics",
"reth-metrics-derive",
"reth-metrics",
"reth-payload-builder",
"reth-primitives",
"reth-provider",
@ -4673,12 +4672,11 @@ version = "0.1.0"
dependencies = [
"assert_matches",
"futures",
"metrics",
"reth-blockchain-tree",
"reth-consensus-common",
"reth-db",
"reth-interfaces",
"reth-metrics-derive",
"reth-metrics",
"reth-payload-builder",
"reth-primitives",
"reth-provider",
@ -4747,7 +4745,6 @@ dependencies = [
"futures",
"heapless",
"iai",
"metrics",
"modular-bitfield",
"page_size",
"parity-scale-codec",
@ -4762,6 +4759,7 @@ dependencies = [
"reth-db",
"reth-interfaces",
"reth-libmdbx",
"reth-metrics",
"reth-primitives",
"secp256k1",
"serde",
@ -4828,12 +4826,11 @@ dependencies = [
"futures",
"futures-util",
"itertools",
"metrics",
"pin-project",
"rayon",
"reth-db",
"reth-interfaces",
"reth-metrics-derive",
"reth-metrics",
"reth-primitives",
"reth-rlp",
"reth-tasks",
@ -4888,13 +4885,13 @@ dependencies = [
"futures",
"hex",
"hex-literal 0.3.4",
"metrics",
"pin-project",
"proptest",
"proptest-derive",
"rand 0.8.5",
"reth-codecs",
"reth-ecies",
"reth-metrics",
"reth-primitives",
"reth-rlp",
"reth-tracing",
@ -4987,7 +4984,7 @@ dependencies = [
]
[[package]]
name = "reth-metrics-common"
name = "reth-metrics"
version = "0.1.0"
dependencies = [
"metrics",
@ -5050,7 +5047,6 @@ dependencies = [
"humantime-serde",
"linked-hash-map",
"linked_hash_set",
"metrics",
"parking_lot 0.12.1",
"pin-project",
"rand 0.8.5",
@ -5059,8 +5055,7 @@ dependencies = [
"reth-ecies",
"reth-eth-wire",
"reth-interfaces",
"reth-metrics-common",
"reth-metrics-derive",
"reth-metrics",
"reth-net-common",
"reth-network",
"reth-network-api",
@ -5103,9 +5098,8 @@ version = "0.1.0"
dependencies = [
"futures-util",
"hashbrown 0.13.2",
"metrics",
"reth-interfaces",
"reth-metrics-derive",
"reth-metrics",
"reth-primitives",
"reth-revm-primitives",
"reth-rlp",
@ -5412,7 +5406,6 @@ dependencies = [
"criterion",
"futures-util",
"itertools",
"metrics",
"num-traits",
"paste",
"pin-project",
@ -5425,7 +5418,7 @@ dependencies = [
"reth-downloaders",
"reth-eth-wire",
"reth-interfaces",
"reth-metrics-derive",
"reth-metrics",
"reth-primitives",
"reth-provider",
"reth-revm",
@ -5443,8 +5436,7 @@ version = "0.1.0"
dependencies = [
"dyn-clone",
"futures-util",
"metrics",
"reth-metrics-derive",
"reth-metrics",
"thiserror",
"tokio",
"tracing",
@ -5471,12 +5463,11 @@ dependencies = [
"bitflags",
"fnv",
"futures-util",
"metrics",
"parking_lot 0.12.1",
"paste",
"rand 0.8.5",
"reth-interfaces",
"reth-metrics-derive",
"reth-metrics",
"reth-primitives",
"reth-provider",
"reth-rlp",

View File

@ -7,8 +7,8 @@ members = [
"crates/blockchain-tree",
"crates/interfaces",
"crates/payload/builder",
"crates/metrics",
"crates/metrics/metrics-derive",
"crates/metrics/common",
"crates/net/common",
"crates/net/ecies",
"crates/net/eth-wire",

View File

@ -35,6 +35,7 @@ reth-net-nat = { path = "../../crates/net/nat" }
reth-payload-builder = { path = "../../crates/payload/builder" }
reth-basic-payload-builder = { path = "../../crates/payload/basic" }
reth-discv4 = { path = "../../crates/net/discv4" }
reth-metrics = { path = "../../crates/metrics" }
jemallocator = { version = "0.5.0", optional = true }
# crypto
@ -57,7 +58,6 @@ confy = "0.5"
toml = {version = "0.7", features = ["display"]}
# metrics
metrics = "0.20.1"
metrics-exporter-prometheus = "0.11.0"
metrics-util = "0.14.0"

View File

@ -4,7 +4,6 @@ use hyper::{
service::{make_service_fn, service_fn},
Body, Request, Response, Server,
};
use metrics::Unit;
use metrics_exporter_prometheus::{PrometheusBuilder, PrometheusHandle};
use metrics_util::layers::{PrefixLayer, Stack};
use reth_db::{
@ -12,6 +11,7 @@ use reth_db::{
mdbx::{Env, WriteMap},
tables,
};
use reth_metrics::metrics::{self, absolute_counter, describe_counter, Unit};
use std::{convert::Infallible, net::SocketAddr, sync::Arc};
/// Installs Prometheus as the metrics recorder and serves it over HTTP with a hook.
@ -89,10 +89,10 @@ pub(crate) async fn initialize_with_db_metrics(
let num_pages = leaf_pages + branch_pages + overflow_pages;
let table_size = page_size * num_pages;
metrics::absolute_counter!("db.table_size", table_size as u64, "table" => *table);
metrics::absolute_counter!("db.table_pages", leaf_pages as u64, "table" => *table, "type" => "leaf");
metrics::absolute_counter!("db.table_pages", branch_pages as u64, "table" => *table, "type" => "branch");
metrics::absolute_counter!("db.table_pages", overflow_pages as u64, "table" => *table, "type" => "overflow");
absolute_counter!("db.table_size", table_size as u64, "table" => *table);
absolute_counter!("db.table_pages", leaf_pages as u64, "table" => *table, "type" => "leaf");
absolute_counter!("db.table_pages", branch_pages as u64, "table" => *table, "type" => "branch");
absolute_counter!("db.table_pages", overflow_pages as u64, "table" => *table, "type" => "overflow");
}
Ok::<(), eyre::Report>(())
@ -103,12 +103,8 @@ pub(crate) async fn initialize_with_db_metrics(
// We describe the metrics after the recorder is installed, otherwise this information is not
// registered
metrics::describe_counter!(
"db.table_size",
Unit::Bytes,
"The size of a database table (in bytes)"
);
metrics::describe_counter!("db.table_pages", "The number of database pages for a table");
describe_counter!("db.table_size", Unit::Bytes, "The size of a database table (in bytes)");
describe_counter!("db.table_pages", "The number of database pages for a table");
Ok(())
}

View File

@ -17,7 +17,7 @@ reth-provider = { path = "../../storage/provider" }
reth-rpc-types = { path = "../../rpc/rpc-types" }
reth-tasks = { path = "../../tasks" }
reth-payload-builder = { path = "../../payload/builder" }
reth-metrics-derive = { path = "../../metrics/metrics-derive" }
reth-metrics = { path = "../../metrics" }
# async
tokio = { version = "1.21.2", features = ["sync"] }
@ -27,7 +27,6 @@ futures = "0.3"
# misc
tracing = { workspace = true }
thiserror = "1.0"
metrics = "0.20.1"
schnellru = "0.2"
[dev-dependencies]

View File

@ -1,5 +1,7 @@
use metrics::Counter;
use reth_metrics_derive::Metrics;
use reth_metrics::{
metrics::{self, Counter},
Metrics,
};
/// Beacon consensus engine metrics.
#[derive(Metrics)]

20
crates/metrics/Cargo.toml Normal file
View File

@ -0,0 +1,20 @@
[package]
name = "reth-metrics"
version = "0.1.0"
edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/paradigmxyz/reth"
description = "reth metrics utilities"
[dependencies]
# reth
reth-metrics-derive = { path = "./metrics-derive" }
# metrics
metrics = "0.20.1"
# async
tokio = { version = "1.21.2", features = ["full"], optional = true }
[features]
common = ["tokio"]

View File

@ -1,19 +0,0 @@
[package]
name = "reth-metrics-common"
version = "0.1.0"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/paradigmxyz/reth"
description = """
Common metric types across the Reth codebase
"""
[dependencies]
# reth
reth-metrics-derive = { path = "../../metrics/metrics-derive" }
# async
tokio = { version = "1.21.2", features = ["full"] }
# metrics
metrics = "0.20.1"

View File

@ -1,10 +0,0 @@
#![warn(missing_docs, unreachable_pub)]
#![deny(unused_must_use, rust_2018_idioms)]
#![doc(test(
no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
))]
//! Common metric types that can be used across the Reth codebase
pub mod metered_sender;

View File

@ -0,0 +1 @@
pub mod metered_sender;

18
crates/metrics/src/lib.rs Normal file
View File

@ -0,0 +1,18 @@
#![warn(missing_docs, unreachable_pub, unused_crate_dependencies)]
#![deny(unused_must_use, rust_2018_idioms)]
#![doc(test(
no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
))]
//! Collection of metrics utilities.
/// Metrics derive macro.
pub use reth_metrics_derive::Metrics;
/// Implementation of common metric utilities.
#[cfg(feature = "common")]
pub mod common;
/// Re-export core metrics crate.
pub use metrics;

View File

@ -13,7 +13,7 @@ reth-interfaces = { path = "../../interfaces" }
reth-primitives = { path = "../../primitives" }
reth-db = { path = "../../storage/db" }
reth-tasks = { path = "../../tasks" }
reth-metrics-derive = { path = "../../metrics/metrics-derive" }
reth-metrics = { path = "../../metrics" }
# async
futures = "0.3"
@ -25,7 +25,6 @@ tokio-util = { version = "0.7", features = ["codec"] }
# misc
tracing = { workspace = true }
metrics = "0.20.1"
rayon = "1.6.0"
# optional deps for the test-utils feature

View File

@ -1,6 +1,8 @@
use metrics::{Counter, Gauge};
use reth_interfaces::p2p::error::DownloadError;
use reth_metrics_derive::Metrics;
use reth_metrics::{
metrics::{self, Counter, Gauge},
Metrics,
};
/// Common downloader metrics.
///

View File

@ -17,6 +17,7 @@ reth-codecs = { path = "../../storage/codecs" }
reth-primitives = { path = "../../primitives" }
reth-ecies = { path = "../ecies" }
reth-rlp = { path = "../../rlp", features = ["alloc", "derive", "std", "ethereum-types", "smol_str"] }
reth-metrics = { path = "../../metrics" }
# used for Chain and builders
ethers-core = { version = "2.0.4", default-features = false}
@ -29,7 +30,6 @@ pin-project = "1.0"
tracing = { workspace = true }
snap = "1.0.5"
smol_str = "0.1"
metrics = "0.20.1"
async-trait = "0.1"
# arbitrary utils

View File

@ -7,9 +7,9 @@ use crate::{
DisconnectReason, HelloMessage,
};
use futures::{Sink, SinkExt, StreamExt};
use metrics::counter;
use pin_project::pin_project;
use reth_codecs::derive_arbitrary;
use reth_metrics::metrics::{self, counter};
use reth_primitives::{
bytes::{Buf, BufMut, Bytes, BytesMut},
hex,

View File

@ -30,7 +30,7 @@ reth-rlp-derive = { path = "../../rlp/rlp-derive" }
reth-tasks = { path = "../../tasks" }
reth-transaction-pool = { path = "../../transaction-pool" }
reth-provider = { path = "../../storage/provider"}
reth-metrics-common = { path = "../../metrics/common" }
reth-metrics = { path = "../../metrics", features = ["common"] }
reth-rpc-types = { path = "../../rpc/rpc-types" }
# async/futures
@ -45,10 +45,6 @@ serde = { version = "1.0", optional = true }
humantime-serde = { version = "1.1", optional = true }
serde_json = { version = "1.0", optional = true }
# metrics
metrics = "0.20.1"
reth-metrics-derive = { path = "../../metrics/metrics-derive" }
# misc
auto_impl = "1"
aquamarine = "0.3.0"

View File

@ -1,6 +1,8 @@
use metrics::{Counter, Gauge};
use reth_eth_wire::DisconnectReason;
use reth_metrics_derive::Metrics;
use reth_metrics::{
metrics::{self, Counter, Gauge},
Metrics,
};
/// Metrics for the entire network, handled by NetworkManager
#[derive(Metrics)]

View File

@ -19,7 +19,7 @@ use reth_eth_wire::{
DisconnectReason, EthMessage, EthStream, P2PStream,
};
use reth_interfaces::p2p::error::RequestError;
use reth_metrics_common::metered_sender::MeteredSender;
use reth_metrics::common::metered_sender::MeteredSender;
use reth_net_common::bandwidth_meter::MeteredStream;
use reth_primitives::PeerId;
use std::{

View File

@ -19,7 +19,7 @@ use reth_eth_wire::{
errors::EthStreamError,
DisconnectReason, EthVersion, HelloMessage, Status, UnauthedEthStream, UnauthedP2PStream,
};
use reth_metrics_common::metered_sender::MeteredSender;
use reth_metrics::common::metered_sender::MeteredSender;
use reth_net_common::{
bandwidth_meter::{BandwidthMeter, MeteredStream},
stream::HasRemoteAddr,

View File

@ -16,14 +16,11 @@ reth-rlp = { path = "../../rlp" }
reth-provider = { path = "../../storage/provider" }
reth-payload-builder = { path = "../builder" }
reth-tasks = { path = "../../tasks" }
reth-metrics = { path = "../../metrics" }
## ethereum
revm = { version = "3" }
# metrics
metrics = "0.20.1"
reth-metrics-derive = { path = "../../metrics/metrics-derive" }
## async
tokio = { version = "1", features = ["sync", "time"] }
futures-core = "0.3"

View File

@ -1,7 +1,9 @@
//! Metrics for the payload builder impl
use metrics::Counter;
use reth_metrics_derive::Metrics;
use reth_metrics::{
metrics::{self, Counter},
Metrics,
};
/// Transaction pool metrics
#[derive(Metrics)]

View File

@ -14,14 +14,11 @@ reth-rpc-types = { path = "../../rpc/rpc-types" }
reth-rlp = { path = "../../rlp" }
reth-interfaces = { path = "../../interfaces" }
reth-revm-primitives = { path = "../../revm/revm-primitives" }
reth-metrics = { path = "../../metrics" }
## ethereum
revm-primitives = "1.1"
# metrics
metrics = "0.20.1"
reth-metrics-derive = { path = "../../metrics/metrics-derive" }
## async
tokio = { version = "1", features = ["sync"] }
tokio-stream = "0.1"

View File

@ -1,7 +1,9 @@
//! Payload builder service metrics.
use metrics::{Counter, Gauge};
use reth_metrics_derive::Metrics;
use reth_metrics::{
metrics::{self, Counter, Gauge},
Metrics,
};
/// Payload builder service metrics
#[derive(Metrics)]

View File

@ -20,7 +20,7 @@ reth-interfaces = { path = "../interfaces" }
reth-db = { path = "../storage/db" }
reth-codecs = { path = "../storage/codecs" }
reth-provider = { path = "../storage/provider" }
reth-metrics-derive = { path = "../metrics/metrics-derive" }
reth-metrics = { path = "../metrics" }
reth-trie = { path = "../trie" }
# async
@ -32,7 +32,6 @@ pin-project = "1.0.12"
# observability
tracing = { workspace = true }
metrics = "0.20.1"
# misc
thiserror = "1.0.37"

View File

@ -75,7 +75,3 @@ pub use error::*;
pub use id::*;
pub use pipeline::*;
pub use stage::*;
// NOTE: Needed so the link in the module-level rustdoc works.
#[allow(unused_extern_crates)]
extern crate metrics as metrics_core;

View File

@ -1,6 +1,8 @@
use crate::StageId;
use metrics::Gauge;
use reth_metrics_derive::Metrics;
use reth_metrics::{
metrics::{self, Gauge},
Metrics,
};
use reth_primitives::{BlockNumber, EntitiesCheckpoint, StageCheckpoint, StageUnitCheckpoint};
use std::collections::HashMap;

View File

@ -1,5 +1,4 @@
use crate::{ExecInput, ExecOutput, Stage, StageError, StageId, UnwindInput, UnwindOutput};
use metrics_core::Gauge;
use reth_db::{
cursor::{DbCursorRO, DbCursorRW, DbDupCursorRO},
database::Database,
@ -7,7 +6,10 @@ use reth_db::{
tables,
transaction::{DbTx, DbTxMut},
};
use reth_metrics_derive::Metrics;
use reth_metrics::{
metrics::{self, Gauge},
Metrics,
};
use reth_primitives::{
constants::MGAS_TO_GAS, Block, BlockNumber, BlockWithSenders, StageCheckpoint,
TransactionSigned, U256,

View File

@ -13,6 +13,7 @@ reth-primitives = { path = "../../primitives" }
reth-interfaces = { path = "../../interfaces" }
reth-codecs = { path = "../codecs" }
reth-libmdbx = { path = "../libmdbx-rs", optional = true , features = ["return-borrowed"] }
reth-metrics = { path = "../../metrics" }
# codecs
serde = { version = "1.0.*", default-features = false }
@ -29,9 +30,6 @@ secp256k1 = { version = "0.27.0", default-features = false, features = [
], optional = true }
modular-bitfield = "0.11.2"
# metrics
metrics = "0.20.1"
# misc
bytes = "1.4"
page_size = "0.4.2"

View File

@ -7,9 +7,9 @@ use crate::{
transaction::{DbTx, DbTxGAT, DbTxMut, DbTxMutGAT},
DatabaseError,
};
use metrics::histogram;
use parking_lot::RwLock;
use reth_libmdbx::{EnvironmentKind, Transaction, TransactionKind, WriteFlags, DBI, RW};
use reth_metrics::metrics::{self, histogram};
use std::{marker::PhantomData, sync::Arc, time::Instant};
/// Wrapper for the libmdbx transaction.

View File

@ -20,8 +20,7 @@ thiserror = "1.0"
dyn-clone = "1.0"
## rpc/metrics
metrics = "0.20.1"
reth-metrics-derive = { path = "../metrics/metrics-derive" }
reth-metrics = { path = "../metrics" }
[dev-dependencies]
tokio = { version = "1", features = ["sync", "rt", "rt-multi-thread", "time", "macros"] }

View File

@ -1,6 +1,8 @@
//! Task Executor Metrics
use metrics::Counter;
use reth_metrics_derive::Metrics;
use reth_metrics::{
metrics::{self, Counter},
Metrics,
};
/// Task Executor Metrics
#[derive(Metrics, Clone)]

View File

@ -16,12 +16,12 @@ normal = [
]
[dependencies]
# reth
reth-primitives = { path = "../primitives" }
reth-provider = { path = "../storage/provider" }
reth-interfaces = { path = "../interfaces" }
reth-rlp = { path = "../rlp" }
reth-metrics = { path = "../metrics" }
# async/futures
async-trait = "0.1"
@ -29,10 +29,6 @@ futures-util = "0.3"
parking_lot = "0.12"
tokio = { version = "1", default-features = false, features = ["sync"] }
# rpc/metrics
metrics = "0.20.1"
reth-metrics-derive = { path = "../metrics/metrics-derive" }
# misc
aquamarine = "0.3.0"
thiserror = "1.0"

View File

@ -1,7 +1,9 @@
//! Transaction pool metrics.
use metrics::{Counter, Gauge};
use reth_metrics_derive::Metrics;
use reth_metrics::{
metrics::{self, Counter, Gauge},
Metrics,
};
/// Transaction pool metrics
#[derive(Metrics)]