diff --git a/backend/Cargo.lock b/backend/Cargo.lock index f6ea991a99..8648912ae3 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -76,12 +76,6 @@ dependencies = [ "password-hash", ] -[[package]] -name = "ascii" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16" - [[package]] name = "ascii-canvas" version = "3.0.0" @@ -388,9 +382,9 @@ checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" [[package]] name = "cc" -version = "1.0.73" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +checksum = "581f5dba903aac52ea3feb5ec4810848460ee833876f1f9b0fdeab1f19091574" [[package]] name = "cfg-if" @@ -414,12 +408,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "chunked_transfer" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e" - [[package]] name = "cipher" version = "0.3.0" @@ -2590,7 +2578,7 @@ dependencies = [ [[package]] name = "rustpython-ast" version = "0.1.0" -source = "git+https://github.com/RustPython/RustPython#835771b7ea2903bf641f00db1cc3c88b74e2a08f" +source = "git+https://github.com/RustPython/RustPython#77b821a1941019fe34f73ce17cea013ae1b98fd0" dependencies = [ "num-bigint", "rustpython-compiler-core", @@ -2599,7 +2587,7 @@ dependencies = [ [[package]] name = "rustpython-compiler-core" version = "0.1.2" -source = "git+https://github.com/RustPython/RustPython#835771b7ea2903bf641f00db1cc3c88b74e2a08f" +source = "git+https://github.com/RustPython/RustPython#77b821a1941019fe34f73ce17cea013ae1b98fd0" dependencies = [ "bincode", "bitflags", @@ -2616,7 +2604,7 @@ dependencies = [ [[package]] name = "rustpython-parser" version = "0.1.2" -source = "git+https://github.com/RustPython/RustPython#835771b7ea2903bf641f00db1cc3c88b74e2a08f" +source = "git+https://github.com/RustPython/RustPython#77b821a1941019fe34f73ce17cea013ae1b98fd0" dependencies = [ "ahash", "anyhow", @@ -3447,18 +3435,6 @@ dependencies = [ "crunchy", ] -[[package]] -name = "tiny_http" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "389915df6413a2e74fb181895f933386023c71110878cd0825588928e64cdc82" -dependencies = [ - "ascii", - "chunked_transfer", - "httpdate", - "log", -] - [[package]] name = "tinyvec" version = "1.6.0" @@ -4383,7 +4359,6 @@ dependencies = [ "sha2 0.10.6", "sqlx", "thiserror", - "tiny_http", "tokio", "tracing", "tracing-subscriber", diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 3c6b4508e0..81387c7ad0 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -59,7 +59,6 @@ windmill-parser = { path = "./parsers/windmill-parser" } windmill-parser-ts = { path = "./parsers/windmill-parser-ts" } windmill-parser-py = { path = "./parsers/windmill-parser-py" } windmill-parser-go = { path = "./parsers/windmill-parser-go" } -tiny_http = "0.12.0" axum = { version = "^0", features = ["headers"] } headers = "^0" hyper = { version = "^0", features = ["full"] } diff --git a/backend/windmill-common/Cargo.toml b/backend/windmill-common/Cargo.toml index 3a5440270b..c9d91c251e 100644 --- a/backend/windmill-common/Cargo.toml +++ b/backend/windmill-common/Cargo.toml @@ -11,7 +11,7 @@ hyper = ["dep:hyper"] tokio = ["dep:tokio"] axum = ["dep:axum", "dep:tracing"] reqwest = ["dep:reqwest"] -prometheus = ["dep:tiny_http", "dep:prometheus"] +prometheus = ["dep:prometheus"] tracing_init = [ "dep:console-subscriber", "dep:tracing", @@ -35,7 +35,6 @@ hex.workspace = true rand.workspace = true sqlx = { workspace = true, optional = true, features = ["postgres"] } uuid.workspace = true -tiny_http = { workspace = true, optional = true } prometheus = { workspace = true, optional = true } tracing = { workspace = true, optional = true } axum = { workspace = true, optional = true } diff --git a/backend/windmill-common/src/lib.rs b/backend/windmill-common/src/lib.rs index 7411c16024..9318acfc31 100644 --- a/backend/windmill-common/src/lib.rs +++ b/backend/windmill-common/src/lib.rs @@ -8,6 +8,8 @@ use std::net::SocketAddr; +use error::Error; + pub mod error; pub mod external_ip; pub mod flows; @@ -51,24 +53,23 @@ pub async fn shutdown_signal(tx: tokio::sync::broadcast::Sender<()>) -> anyhow:: #[cfg(feature = "prometheus")] pub async fn serve_metrics( addr: SocketAddr, - rx: tokio::sync::broadcast::Receiver<()>, -) -> Result<(), anyhow::Error> { - use tokio::task::yield_now; - - let server = tiny_http::Server::http(addr).map_err(|e| anyhow::anyhow!(e.to_string()))?; - for request in server.incoming_requests() { - yield_now().await; - if !rx.is_empty() { - break; - } - let response = tiny_http::Response::from_string(metrics().await?); - let _ = request.respond(response); - } - Ok(()) + mut rx: tokio::sync::broadcast::Receiver<()>, +) -> Result<(), hyper::Error> { + use axum::{routing::get, Router}; + axum::Server::bind(&addr) + .serve( + Router::new() + .route("/metrics", get(metrics)) + .into_make_service(), + ) + .with_graceful_shutdown(async { + rx.recv().await.ok(); + println!("Graceful shutdown of metrics"); + }) + .await } -#[cfg(feature = "prometheus")] -async fn metrics() -> Result { +async fn metrics() -> Result { let metric_families = prometheus::gather(); Ok(prometheus::TextEncoder::new() .encode_to_string(&metric_families) @@ -78,7 +79,6 @@ async fn metrics() -> Result { #[cfg(feature = "sqlx")] pub async fn connect_db() -> anyhow::Result> { use anyhow::Context; - use error::Error; let database_url = std::env::var("DATABASE_URL") .map_err(|_| Error::BadConfig("DATABASE_URL env var is missing".to_string()))?; @@ -98,8 +98,6 @@ pub async fn connect( ) -> Result, error::Error> { use std::time::Duration; - use crate::error::Error; - sqlx::postgres::PgPoolOptions::new() .max_connections(max_connections) .max_lifetime(Duration::from_secs(30 * 60)) // 30 mins