Skip to content

Commit

Permalink
Reduce spammed Web3 client logs
Browse files Browse the repository at this point in the history
  • Loading branch information
slowli committed Sep 4, 2024
1 parent 463254a commit 4951d54
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
26 changes: 19 additions & 7 deletions core/lib/web3_decl/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ pub struct ClientBuilder<Net, C = HttpClient> {
client: C,
url: SensitiveUrl,
rate_limit: (usize, Duration),
report_config: bool,
network: Net,
}

Expand All @@ -328,6 +329,7 @@ impl<Net: fmt::Debug, C: 'static> fmt::Debug for ClientBuilder<Net, C> {
.field("client", &any::type_name::<C>())
.field("url", &self.url)
.field("rate_limit", &self.rate_limit)
.field("report_config", &self.report_config)
.field("network", &self.network)
.finish_non_exhaustive()
}
Expand All @@ -340,6 +342,7 @@ impl<Net: Network, C: ClientBase> ClientBuilder<Net, C> {
client,
url,
rate_limit: (1, Duration::ZERO),
report_config: true,
network: Net::default(),
}
}
Expand All @@ -366,16 +369,25 @@ impl<Net: Network, C: ClientBase> ClientBuilder<Net, C> {
self
}

/// Allows switching off config reporting for this client in logs and metrics. This is useful if a client is a short-living one
/// and is not injected as a dependency.
pub fn report_config(mut self, report: bool) -> Self {
self.report_config = report;
self
}

/// Builds the client.
pub fn build(self) -> Client<Net, C> {
tracing::info!(
"Creating JSON-RPC client for network {:?} with inner client: {:?} and rate limit: {:?}",
self.network,
self.client,
self.rate_limit
);
let rate_limit = SharedRateLimit::new(self.rate_limit.0, self.rate_limit.1);
METRICS.observe_config(self.network.metric_label(), &rate_limit);
if self.report_config {
tracing::info!(
"Creating JSON-RPC client for network {:?} with inner client: {:?} and rate limit: {:?}",
self.network,
self.client,
self.rate_limit
);
METRICS.observe_config(self.network.metric_label(), &rate_limit);
}

Client {
inner: self.client,
Expand Down
2 changes: 2 additions & 0 deletions core/tests/loadnext/src/account_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ impl AccountPool {
.context("invalid L2 RPC URL")?,
)?
.for_network(l2_chain_id.into())
.report_config(false)
.build();

// Perform a health check: check whether ZKsync server is alive.
let mut server_alive = false;
for _ in 0usize..3 {
Expand Down
1 change: 1 addition & 0 deletions core/tests/loadnext/src/sdk/ethereum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ impl<S: EthereumSigner> EthereumProvider<S> {
let query_client = Client::http(eth_web3_url)
.map_err(|err| ClientError::NetworkError(err.to_string()))?
.for_network(sl_chain_id.into())
.report_config(false)
.build();
let query_client: Box<DynClient<L1>> = Box::new(query_client);
let eth_client = SigningClient::new(
Expand Down
1 change: 1 addition & 0 deletions core/tests/loadnext/src/sdk/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ where
let client = Client::http(rpc_address)
.map_err(|err| ClientError::NetworkError(err.to_string()))?
.for_network(signer.chain_id.into())
.report_config(false)
.build();

Ok(Wallet {
Expand Down

0 comments on commit 4951d54

Please sign in to comment.