Skip to content

Commit

Permalink
Disable prometheus in test specs.
Browse files Browse the repository at this point in the history
See Ptrskay3/axum-prometheus#59
See Ptrskay3/axum-prometheus#65

The actual error I was seeing is:

thread '<unnamed>' panicked at /Users/muji/.cargo/registry/src/index.crates.io-6f17d22bba15001f/axum-prometheus-0.7.0/src/lib.rs:850:14:
Failed to build metrics recorder: FailedToCreateHTTPListener("Address already in use (os error 48)")
  • Loading branch information
tmpfs committed Nov 3, 2024
1 parent 0642b14 commit 0ec7503
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion crates/integration_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ secrecy.workspace = true
http.workspace = true

sos-ipc = { path = "../ipc", features = ["tcp"] }
sos-server = { path = "../server" }
sos-server = { path = "../server", default-features = false, features = ["listen", "audit", "pairing"] }
sos-test-utils = { path = "../test_utils" }

copy_dir = "0.1"
Expand Down
2 changes: 1 addition & 1 deletion crates/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["listen", "audit", "pairing", "acme", "prometheus"]
default = ["listen", "audit", "pairing", "acme"]
prometheus = ["axum-prometheus"]
acme = ["dep:tokio-rustls-acme"]
listen = ["sos-protocol/listen"]
Expand Down
20 changes: 10 additions & 10 deletions crates/server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,18 +355,19 @@ impl Server {
v1 = v1.layer(Extension(file_operations));
}

#[cfg(feature = "prometheus")]
let (prometheus_layer, metric_handle) =
axum_prometheus::PrometheusMetricLayerBuilder::new()
.with_default_metrics()
.enable_response_body_size(true)
.build_pair();

let mut app = Router::new();
app = app.route("/", get(home));
#[allow(unused_mut)]
let mut app = Router::new()
.route("/", get(home))
.nest_service("/api/v1", v1);

#[cfg(feature = "prometheus")]
{
let (prometheus_layer, metric_handle) =
axum_prometheus::PrometheusMetricLayerBuilder::new()
.with_default_metrics()
.enable_response_body_size(true)
.build_pair();

app = app
.route(
"/metrics",
Expand All @@ -375,7 +376,6 @@ impl Server {
.layer(prometheus_layer);
}

app = app.nest_service("/api/v1", v1);
Ok(app)
}
}
Expand Down

0 comments on commit 0ec7503

Please sign in to comment.