Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metrics to gas price service #2635

Merged
merged 9 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added
- [2635](https://github.com/FuelLabs/fuel-core/pull/2635): Add metrics to gas price service

### Changed
- [2387](https://github.com/FuelLabs/fuel-core/pull/2387): Update description `tx-max-depth` flag.
- [2630](https://github.com/FuelLabs/fuel-core/pull/2630): Removed some noisy `tracing::info!` logs
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.

3 changes: 3 additions & 0 deletions bin/fuel-core/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,8 @@ impl Command {
disabled_metrics.is_enabled(Module::Importer),
);

let gas_price_metrics = disabled_metrics.is_enabled(Module::GasPrice);

let da_compression = match da_compression {
Some(retention) => {
DaCompressionConfig::Enabled(fuel_core_compression::Config {
Expand Down Expand Up @@ -710,6 +712,7 @@ impl Command {
max_da_gas_price_change_percent: gas_price_change_percent,
da_gas_price_p_component,
da_gas_price_d_component,
gas_price_metrics,
activity_normal_range_size: 100,
activity_capped_range_size: 0,
activity_decrease_range_size: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl From<Config> for V1AlgorithmConfig {
starting_recorded_height: value
.starting_recorded_height
.map(BlockHeight::from),
record_metrics: value.gas_price_metrics,
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/fuel-core/src/service/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub struct Config {
pub max_da_gas_price_change_percent: u16,
pub da_gas_price_p_component: i64,
pub da_gas_price_d_component: i64,
pub gas_price_metrics: bool,
pub activity_normal_range_size: u16,
pub activity_capped_range_size: u16,
pub activity_decrease_range_size: u16,
Expand Down Expand Up @@ -148,6 +149,7 @@ impl Config {
let gas_price_change_percent = 0;
let min_gas_price = 0;
let gas_price_threshold_percent = 50;
let gas_price_metrics = false;

Self {
graphql_config: GraphQLConfig {
Expand Down Expand Up @@ -214,6 +216,7 @@ impl Config {
max_da_gas_price_change_percent: 0,
da_gas_price_p_component: 0,
da_gas_price_d_component: 0,
gas_price_metrics,
activity_normal_range_size: 0,
activity_capped_range_size: 0,
activity_decrease_range_size: 0,
Expand Down
1 change: 1 addition & 0 deletions crates/metrics/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub enum Module {
Producer,
TxPool,
GraphQL, // TODO[RC]: Not used... yet.
GasPrice,
}

/// Configuration for disabling metrics.
Expand Down
98 changes: 98 additions & 0 deletions crates/metrics/src/gas_price_metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
use crate::global_registry;
use prometheus_client::metrics::gauge::Gauge;
use std::sync::OnceLock;

#[derive(Debug)]
pub struct GasPriceMetrics {
pub real_gas_price: Gauge,
pub exec_gas_price: Gauge,
pub da_gas_price: Gauge,
pub total_reward: Gauge,
pub total_known_costs: Gauge,
pub predicted_profit: Gauge,
pub unrecorded_bytes: Gauge,
pub latest_cost_per_byte: Gauge,
pub recorded_height: Gauge,
}

impl Default for GasPriceMetrics {
fn default() -> Self {
let real_gas_price = Gauge::default();
let exec_gas_price = Gauge::default();
let da_gas_price = Gauge::default();
let total_reward = Gauge::default();
let total_known_costs = Gauge::default();
let predicted_profit = Gauge::default();
let unrecorded_bytes = Gauge::default();
let latest_cost_per_byte = Gauge::default();
let recorded_height = Gauge::default();

let metrics = GasPriceMetrics {
real_gas_price,
exec_gas_price,
da_gas_price,
total_reward,
total_known_costs,
predicted_profit,
unrecorded_bytes,
latest_cost_per_byte,
recorded_height,
};

let mut registry = global_registry().registry.lock();
registry.register(
"gas_price_service_real_gas_price",
"The real gas price used on the most recent block",
metrics.real_gas_price.clone(),
);
registry.register(
"gas_price_service_exec_gas_price",
"The requested execution gas price for the next block",
metrics.exec_gas_price.clone(),
);
registry.register(
"gas_price_service_da_gas_price",
"The requested data availability gas price for the next block",
metrics.da_gas_price.clone(),
);
registry.register(
"gas_price_service_total_reward",
"The total reward received from DA gas price fees",
metrics.total_reward.clone(),
);
registry.register(
"gas_price_service_total_known_costs",
"The total known costs for committing L2 blocks to DA",
metrics.total_known_costs.clone(),
);
registry.register(
"gas_price_service_predicted_profit",
"The predicted profit based on the rewards, known costs, and predicted costs from price per byte",
metrics.predicted_profit.clone(),
);
registry.register(
"gas_price_service_unrecorded_bytes",
"The total bytes of all L2 blocks waiting to be recorded on DA",
metrics.unrecorded_bytes.clone(),
);
registry.register(
"gas_price_service_latest_cost_per_byte",
"The latest cost per byte to record L2 blocks on DA",
metrics.latest_cost_per_byte.clone(),
);

registry.register(
"gas_price_service_recorded_height",
"The height of the latest L2 block recorded on DA",
metrics.recorded_height.clone(),
);

metrics
}
}

static GAS_PRICE_METRICS: OnceLock<GasPriceMetrics> = OnceLock::new();

pub fn gas_price_metrics() -> &'static GasPriceMetrics {
GAS_PRICE_METRICS.get_or_init(GasPriceMetrics::default)
}
1 change: 1 addition & 0 deletions crates/metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mod buckets;
pub mod config;
pub mod core_metrics;
pub mod futures;
pub mod gas_price_metrics;
pub mod graphql_metrics;
pub mod importer;
pub mod p2p_metrics;
Expand Down
1 change: 1 addition & 0 deletions crates/services/gas_price_service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repository = { workspace = true }
anyhow = { workspace = true }
async-trait = { workspace = true }
enum-iterator = { workspace = true }
fuel-core-metrics = { workspace = true }
fuel-core-services = { workspace = true }
fuel-core-storage = { workspace = true, features = ["std"] }
fuel-core-types = { workspace = true, features = ["std"] }
Expand Down
13 changes: 13 additions & 0 deletions crates/services/gas_price_service/src/v1/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ impl V1Metadata {
};
Ok(metadata)
}

pub fn new_exec_gas_price(&self) -> u64 {
self.new_scaled_exec_price
.checked_div(self.gas_price_factor.get())
.unwrap_or(0)
}

pub fn new_da_gas_price(&self) -> u64 {
self.new_scaled_da_gas_price
.checked_div(self.gas_price_factor.get())
.unwrap_or(0)
}
}

#[derive(Debug, Clone, PartialEq)]
Expand All @@ -82,6 +94,7 @@ pub struct V1AlgorithmConfig {
/// The interval at which the `DaSourceService` polls for new data
pub da_poll_interval: Option<Duration>,
pub starting_recorded_height: Option<BlockHeight>,
pub record_metrics: bool,
}

pub fn updater_from_config(
Expand Down
Loading
Loading