Skip to content

Commit

Permalink
gateway: ensure there is only one copy of JsonRpcMetrics
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed May 27, 2022
1 parent b7166c7 commit 5c46649
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions crates/sui-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ tokio = { version = "1.18.2", features = ["full"] }
futures = "0.3.21"
ed25519-dalek = { version = "1.0.1", features = ["batch", "serde"] }
prometheus_exporter = "0.8.4"
once_cell = "1.11.0"

sui-core = { path = "../sui-core" }
sui-config = { path = "../sui-config" }
Expand Down
16 changes: 8 additions & 8 deletions crates/sui-gateway/src/json_rpc.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use std::{env, net::SocketAddr, time::Instant};

use crate::api::SuiRpcModule;
use anyhow::Result;
use jsonrpsee::{
http_server::{AccessControlBuilder, HttpServerBuilder, HttpServerHandle},
RpcModule,
};
use jsonrpsee_core::middleware::Middleware;
use once_cell::sync::Lazy;
use prometheus_exporter::prometheus::{
register_histogram_vec, register_int_counter_vec, HistogramVec, IntCounterVec,
};
use tracing::info;

use std::{env, net::SocketAddr, time::Instant};
use sui_open_rpc::Project;

use crate::api::SuiRpcModule;
use tracing::info;

pub struct JsonRpcServerBuilder {
module: RpcModule<()>,
Expand Down Expand Up @@ -96,7 +94,7 @@ struct JsonRpcMetrics {

impl JsonRpcMetrics {
pub fn new() -> Self {
Self {
static METRICS: Lazy<JsonRpcMetrics> = Lazy::new(|| JsonRpcMetrics {
requests_by_route: register_int_counter_vec!(
"rpc_requests_by_route",
"Number of requests by route",
Expand All @@ -115,7 +113,9 @@ impl JsonRpcMetrics {
&["route"]
)
.unwrap(),
}
});

Lazy::force(&METRICS).clone()
}
}

Expand Down

0 comments on commit 5c46649

Please sign in to comment.