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

chore(bridge-withdrawer): change batch value metric to a histogram #2016

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions crates/astria-bridge-withdrawer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Histogram metric `batch_settled_value` [#2016](https://github.com/astriaorg/astria/pull/2016).

### Changed

- Update `idna` dependency to resolve cargo audit warning [#1869](https://github.com/astriaorg/astria/pull/1869).

### Removed

- Gauage metric `batch_total_settled_value` [#2016](https://github.com/astriaorg/astria/pull/2016).

## [1.0.1] - 2024-11-01

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl Submitter {
} = self;

if actions.is_empty() {
metrics.set_batch_total_settled_value(0);
metrics.record_batch_settled_value(0);

return Ok(());
}
Expand Down Expand Up @@ -213,7 +213,7 @@ impl Submitter {
batch.value = total_value,
"withdraw batch successfully executed."
);
metrics.set_batch_total_settled_value(total_value);
metrics.record_batch_settled_value(total_value);
state.set_last_rollup_height_submitted(rollup_height);
state.set_last_sequencer_height(tx_response.height.value());
state.set_last_sequencer_tx_hash(tx_response.hash);
Expand Down
2 changes: 1 addition & 1 deletion crates/astria-bridge-withdrawer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async fn main() -> ExitCode {
}

let (metrics, _telemetry_guard) = match telemetry_conf
.try_init(&())
.try_init(&cfg)
.wrap_err("failed to setup telemetry")
{
Err(e) => {
Expand Down
27 changes: 14 additions & 13 deletions crates/astria-bridge-withdrawer/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct Metrics {
nonce_fetch_latency: Histogram,
sequencer_submission_failure_count: Counter,
sequencer_submission_latency: Histogram,
batch_total_settled_value: Gauge,
batch_settled_value: Histogram,
}

impl Metrics {
Expand Down Expand Up @@ -46,17 +46,17 @@ impl Metrics {
self.sequencer_submission_failure_count.increment(1);
}

pub(crate) fn set_batch_total_settled_value(&self, value: u128) {
self.batch_total_settled_value.set(value);
pub(crate) fn record_batch_settled_value(&self, value: u128) {
self.batch_settled_value.record(value);
}
}

impl metrics::Metrics for Metrics {
type Config = ();
type Config = crate::Config;

fn register(
builder: &mut RegisteringBuilder,
_config: &Self::Config,
config: &Self::Config,
) -> Result<Self, metrics::Error> {
let current_nonce = builder
.new_gauge_factory(CURRENT_NONCE, "The current nonce")?
Expand Down Expand Up @@ -97,12 +97,13 @@ impl metrics::Metrics for Metrics {
)?
.register()?;

let batch_total_settled_value = builder
.new_gauge_factory(
BATCH_TOTAL_SETTLED_VALUE,
let denom_name = format!("{}", config.rollup_asset_denomination);
let batch_settled_value = builder
.new_histogram_factory(
BATCH_SETTLED_VALUE,
"Total value of withdrawals settled in a given sequencer block",
)?
.register()?;
.register_with_labels(&[("denom", denom_name)])?;

Ok(Self {
current_nonce,
Expand All @@ -111,7 +112,7 @@ impl metrics::Metrics for Metrics {
nonce_fetch_latency,
sequencer_submission_failure_count,
sequencer_submission_latency,
batch_total_settled_value,
batch_settled_value,
})
}
}
Expand All @@ -123,13 +124,13 @@ metric_names!(const METRICS_NAMES:
CURRENT_NONCE,
SEQUENCER_SUBMISSION_FAILURE_COUNT,
SEQUENCER_SUBMISSION_LATENCY,
BATCH_TOTAL_SETTLED_VALUE,
BATCH_SETTLED_VALUE,
);

#[cfg(test)]
mod tests {
use super::{
BATCH_TOTAL_SETTLED_VALUE,
BATCH_SETTLED_VALUE,
CURRENT_NONCE,
NONCE_FETCH_COUNT,
NONCE_FETCH_FAILURE_COUNT,
Expand Down Expand Up @@ -157,6 +158,6 @@ mod tests {
"sequencer_submission_failure_count",
);
assert_const(SEQUENCER_SUBMISSION_LATENCY, "sequencer_submission_latency");
assert_const(BATCH_TOTAL_SETTLED_VALUE, "batch_total_settled_value");
assert_const(BATCH_SETTLED_VALUE, "batch_settled_value");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,40 @@ pub(crate) const SEQUENCER_CHAIN_ID: &str = "test-sequencer";
const ASTRIA_ADDRESS_PREFIX: &str = "astria";

static TELEMETRY: LazyLock<()> = LazyLock::new(|| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this removed? The change seems to have nothing to do with this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't pass the config into the function here.

I can strip out the new functionality of having the label off the config to roll this back.

let config = Config {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this and the config padded to the "test bridge withdrawer" to a free standing fn config() -> Config so they share the same definition?

sequencer_cometbft_endpoint: String::new(),
sequencer_grpc_endpoint: String::new(),
sequencer_chain_id: SEQUENCER_CHAIN_ID.into(),
sequencer_key_path: String::new(),
fee_asset_denomination: default_native_asset(),
rollup_asset_denomination: default_native_asset().as_trace_prefixed().unwrap().clone(),
sequencer_bridge_address: default_bridge_address().to_string(),
use_compat_address: false,
ethereum_contract_address: String::new(),
ethereum_rpc_endpoint: String::new(),
sequencer_address_prefix: ASTRIA_ADDRESS_PREFIX.into(),
api_addr: String::new(),
log: String::new(),
force_stdout: false,
no_otel: false,
no_metrics: false,
metrics_http_listener_addr: String::new(),
pretty_print: true,
};
if std::env::var_os("TEST_LOG").is_some() {
let filter_directives = std::env::var("RUST_LOG").unwrap_or_else(|_| "info".into());
telemetry::configure()
.set_no_otel(true)
.set_stdout_writer(std::io::stdout)
.set_pretty_print(true)
.set_filter_directives(&filter_directives)
.try_init::<Metrics>(&())
.try_init::<Metrics>(&config)
.unwrap();
} else {
telemetry::configure()
.set_no_otel(true)
.set_stdout_writer(std::io::sink)
.try_init::<Metrics>(&())
.try_init::<Metrics>(&config)
.unwrap();
}
});
Expand Down Expand Up @@ -283,7 +303,7 @@ impl TestBridgeWithdrawerConfig {
log: String::new(),
force_stdout: false,
no_otel: false,
no_metrics: false,
no_metrics: true,
metrics_http_listener_addr: String::new(),
pretty_print: true,
};
Expand All @@ -292,7 +312,7 @@ impl TestBridgeWithdrawerConfig {

let (metrics, metrics_handle) = metrics::ConfigBuilder::new()
.set_global_recorder(false)
.build(&())
.build(&config)
.unwrap();
let metrics = Box::leak(Box::new(metrics));

Expand Down
Loading