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 3 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 etric `batch_settled_value` now a histogram [#2016](https://github.com/astriaorg/astria/pull/2016).
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Histogram etric `batch_settled_value` now a histogram [#2016](https://github.com/astriaorg/astria/pull/2016).
- Metric `batch_settled_value` now a histogram [#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

- Metric `batch_total_settled_value` removed in favor of `batch_settled_value` [#2016](https://github.com/astriaorg/astria/pull/2016).
Copy link
Member

Choose a reason for hiding this comment

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

Instead of adding & removed, should we put this under "changed"?

Copy link
Member Author

Choose a reason for hiding this comment

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

In the past I did that and we decided to do an add and remove.


## [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 @@ -2,7 +2,6 @@ use std::{
io::Write as _,
mem,
net::SocketAddr,
sync::LazyLock,
time::Duration,
};

Expand Down Expand Up @@ -74,25 +73,6 @@ pub(crate) const DEFAULT_IBC_DENOM: &str = "transfer/channel-0/utia";
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.

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>(&())
.unwrap();
} else {
telemetry::configure()
.set_no_otel(true)
.set_stdout_writer(std::io::sink)
.try_init::<Metrics>(&())
.unwrap();
}
});

pub struct TestBridgeWithdrawer {
/// The address of the public API server (health, ready).
pub api_address: SocketAddr,
Expand Down Expand Up @@ -251,7 +231,6 @@ impl TestBridgeWithdrawerConfig {
ethereum_config,
asset_denom,
} = self;
LazyLock::force(&TELEMETRY);

// sequencer signer key
let keyfile = NamedTempFile::new().unwrap();
Expand Down Expand Up @@ -287,12 +266,28 @@ impl TestBridgeWithdrawerConfig {
metrics_http_listener_addr: String::new(),
pretty_print: true,
};
if std::env::var_os("TEST_LOG").is_some() {
Copy link
Member

Choose a reason for hiding this comment

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

This is bad, we cannot do that.

The reason why we had a lazylock is that the tracing subscriber sits at a global static mwmory location.

The present change can cause tests to fail/panic.

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>(&config)
.unwrap();
} else {
telemetry::configure()
.set_no_otel(true)
.set_stdout_writer(std::io::sink)
.try_init::<Metrics>(&config)
.unwrap();
}

info!(config = serde_json::to_string(&config).unwrap());

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