Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 915964e

Browse files
authored
disable metrics for tests (#769)
1 parent 8d878f8 commit 915964e

File tree

6 files changed

+25
-7
lines changed

6 files changed

+25
-7
lines changed

sqld/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ impl<A> UserApiConfig<A> {
109109
pub struct AdminApiConfig<A = AddrIncoming, C = HttpsConnector<HttpConnector>> {
110110
pub acceptor: A,
111111
pub connector: C,
112+
pub disable_metrics: bool,
112113
}
113114

114115
#[derive(Clone)]

sqld/src/http/admin/mod.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,25 @@ type UserHttpServer<M> =
2727

2828
#[derive(Clone)]
2929
struct Metrics {
30-
handle: PrometheusHandle,
30+
handle: Option<PrometheusHandle>,
31+
}
32+
33+
impl Metrics {
34+
fn render(&self) -> String {
35+
self.handle.as_ref().map(|h| h.render()).unwrap_or_default()
36+
}
3137
}
3238

3339
struct AppState<M: MakeNamespace, C> {
3440
namespaces: NamespaceStore<M>,
3541
user_http_server: UserHttpServer<M>,
3642
connector: C,
37-
metrics: PrometheusHandle,
43+
metrics: Metrics,
3844
}
3945

4046
impl<M: MakeNamespace, C> FromRef<Arc<AppState<M, C>>> for Metrics {
4147
fn from_ref(input: &Arc<AppState<M, C>>) -> Self {
42-
Metrics {
43-
handle: input.metrics.clone(),
44-
}
48+
input.metrics.clone()
4549
}
4650
}
4751

@@ -50,13 +54,20 @@ pub async fn run<M, A, C>(
5054
user_http_server: UserHttpServer<M>,
5155
namespaces: NamespaceStore<M>,
5256
connector: C,
57+
disable_metrics: bool,
5358
) -> anyhow::Result<()>
5459
where
5560
A: crate::net::Accept,
5661
M: MakeNamespace,
5762
C: Connector,
5863
{
5964
use axum::routing::{get, post};
65+
let metrics = Metrics {
66+
handle: (!disable_metrics)
67+
.then(|| PrometheusBuilder::new().install_recorder())
68+
.transpose()
69+
.unwrap(),
70+
};
6071
let router = axum::Router::new()
6172
.route("/", get(handle_get_index))
6273
.route(
@@ -79,7 +90,7 @@ where
7990
namespaces,
8091
connector,
8192
user_http_server,
82-
metrics: PrometheusBuilder::new().install_recorder().unwrap(),
93+
metrics,
8394
}));
8495

8596
hyper::server::Server::builder(acceptor)
@@ -94,7 +105,7 @@ async fn handle_get_index() -> &'static str {
94105
}
95106

96107
async fn handle_metrics(State(metrics): State<Metrics>) -> String {
97-
metrics.handle.render()
108+
metrics.render()
98109
}
99110

100111
async fn handle_get_config<M: MakeNamespace, C: Connector>(

sqld/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,15 @@ where
161161
if let Some(AdminApiConfig {
162162
acceptor,
163163
connector,
164+
disable_metrics,
164165
}) = self.admin_api_config
165166
{
166167
join_set.spawn(http::admin::run(
167168
acceptor,
168169
user_http_service,
169170
self.namespaces,
170171
connector,
172+
disable_metrics,
171173
));
172174
}
173175
}

sqld/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ async fn make_admin_api_config(config: &Cli) -> anyhow::Result<Option<AdminApiCo
360360
Ok(Some(AdminApiConfig {
361361
acceptor,
362362
connector,
363+
disable_metrics: false,
363364
}))
364365
}
365366
None => Ok(None),

sqld/tests/cluster/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ fn make_cluster(sim: &mut Sim, num_replica: usize, disable_namespaces: bool) {
2929
admin_api_config: Some(AdminApiConfig {
3030
acceptor: TurmoilAcceptor::bind(([0, 0, 0, 0], 9090)).await?,
3131
connector: TurmoilConnector,
32+
disable_metrics: true,
3233
}),
3334
rpc_server_config: Some(RpcServerConfig {
3435
acceptor: TurmoilAcceptor::bind(([0, 0, 0, 0], 4567)).await?,
@@ -59,6 +60,7 @@ fn make_cluster(sim: &mut Sim, num_replica: usize, disable_namespaces: bool) {
5960
admin_api_config: Some(AdminApiConfig {
6061
acceptor: TurmoilAcceptor::bind(([0, 0, 0, 0], 9090)).await?,
6162
connector: TurmoilConnector,
63+
disable_metrics: true,
6264
}),
6365
rpc_client_config: Some(RpcClientConfig {
6466
remote_url: "http://primary:4567".into(),

sqld/tests/namespaces/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fn make_primary(sim: &mut Sim, path: PathBuf) {
2424
admin_api_config: Some(AdminApiConfig {
2525
acceptor: TurmoilAcceptor::bind(([0, 0, 0, 0], 9090)).await?,
2626
connector: TurmoilConnector,
27+
disable_metrics: true,
2728
}),
2829
rpc_server_config: Some(RpcServerConfig {
2930
acceptor: TurmoilAcceptor::bind(([0, 0, 0, 0], 4567)).await?,

0 commit comments

Comments
 (0)