From 91ea589de04ae2188e8e5d1386d8b295748c9f9f Mon Sep 17 00:00:00 2001 From: Eguo Wang Date: Thu, 19 Oct 2023 22:12:59 +0800 Subject: [PATCH] Remove tower_governor layer from axum --- Cargo.lock | 141 +++---------------------------------------- Cargo.toml | 2 +- apiserver/Cargo.toml | 1 - apiserver/src/app.rs | 26 +------- crdgen/Cargo.toml | 2 +- 5 files changed, 12 insertions(+), 160 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 780b7fc..712c617 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,7 +61,7 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" [[package]] name = "amp-apiserver" -version = "0.5.12" +version = "0.6.0" dependencies = [ "amp-common", "amp-resources", @@ -83,7 +83,6 @@ dependencies = [ "tokio-stream", "tower", "tower-http", - "tower_governor", "tracing", "tracing-subscriber", "url", @@ -122,7 +121,7 @@ dependencies = [ [[package]] name = "amp-controllers" -version = "0.5.12" +version = "0.6.0" dependencies = [ "amp-common", "amp-resolver", @@ -147,7 +146,7 @@ dependencies = [ [[package]] name = "amp-crdgen" -version = "0.2.0" +version = "0.6.0" dependencies = [ "amp-common", "clap", @@ -159,7 +158,7 @@ dependencies = [ [[package]] name = "amp-resolver" -version = "0.5.12" +version = "0.6.0" dependencies = [ "amp-common", "amp-resources", @@ -173,7 +172,7 @@ dependencies = [ [[package]] name = "amp-resources" -version = "0.5.12" +version = "0.6.0" dependencies = [ "amp-common", "k8s-metrics", @@ -192,7 +191,7 @@ dependencies = [ [[package]] name = "amp-syncer" -version = "0.5.12" +version = "0.6.0" dependencies = [ "amp-common", "async-nats", @@ -735,19 +734,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown 0.14.1", - "lock_api", - "once_cell", - "parking_lot_core", -] - [[package]] name = "data-encoding" version = "2.4.0" @@ -959,16 +945,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "forwarded-header-value" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8835f84f38484cc86f110a805655697908257fb9a7af005234060891557198e9" -dependencies = [ - "nonempty", - "thiserror", -] - [[package]] name = "fsevent-sys" version = "4.1.0" @@ -1049,12 +1025,6 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" -[[package]] -name = "futures-timer" -version = "3.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" - [[package]] name = "futures-util" version = "0.3.28" @@ -1091,7 +1061,7 @@ checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ "cfg-if", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", ] [[package]] @@ -1106,24 +1076,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "558b88954871f5e5b2af0e62e2e176c8bde7a6c2c4ed41b13d138d96da2e2cbd" -[[package]] -name = "governor" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c390a940a5d157878dd057c78680a33ce3415bcd05b4799509ea44210914b4d5" -dependencies = [ - "cfg-if", - "dashmap", - "futures", - "futures-timer", - "no-std-compat", - "nonzero_ext", - "parking_lot", - "quanta", - "rand", - "smallvec", -] - [[package]] name = "h2" version = "0.3.21" @@ -1690,15 +1642,6 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" -[[package]] -name = "mach" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" -dependencies = [ - "libc", -] - [[package]] name = "matchers" version = "0.1.0" @@ -1753,7 +1696,7 @@ checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", "log", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "windows-sys", ] @@ -1773,24 +1716,6 @@ dependencies = [ "signatory", ] -[[package]] -name = "no-std-compat" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b93853da6d84c2e3c7d730d6473e8817692dd89be387eb01b94d7f108ecb5b8c" - -[[package]] -name = "nonempty" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9e591e719385e6ebaeb5ce5d3887f7d5676fceca6411d1925ccc95745f3d6f7" - -[[package]] -name = "nonzero_ext" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38bf9645c8b145698bb0b18a4637dcacbc421ea49bef2317e4fd8065a387cf21" - [[package]] name = "notify" version = "6.1.1" @@ -2067,22 +1992,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "quanta" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20afe714292d5e879d8b12740aa223c6a88f118af41870e8b6196e39a02238a8" -dependencies = [ - "crossbeam-utils", - "libc", - "mach", - "once_cell", - "raw-cpuid", - "wasi 0.10.2+wasi-snapshot-preview1", - "web-sys", - "winapi", -] - [[package]] name = "quote" version = "1.0.33" @@ -2122,15 +2031,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "raw-cpuid" -version = "10.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c297679cb867470fa8c9f67dbba74a78d78e3e98d7cf2b08d6d71540f797332" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "redox_syscall" version = "0.2.16" @@ -3066,25 +2966,6 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" -[[package]] -name = "tower_governor" -version = "0.0.3" -source = "git+https://github.com/benwis/tower-governor?rev=01e1a107#01e1a1077dbcb7a61eff612a8f8362a318c21668" -dependencies = [ - "axum", - "forwarded-header-value", - "futures", - "futures-core", - "governor", - "http", - "pin-project", - "thiserror", - "tokio", - "tower", - "tower-layer", - "tracing", -] - [[package]] name = "tracing" version = "0.1.39" @@ -3389,12 +3270,6 @@ dependencies = [ "try-lock", ] -[[package]] -name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index ed577b1..6431e76 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace.package] -version = "0.5.12" +version = "0.6.0" edition = "2021" license = "Apache-2.0" repository = "https://github.com/amphitheatre-app/amphitheatre" diff --git a/apiserver/Cargo.toml b/apiserver/Cargo.toml index 1dc2028..d5e33a5 100644 --- a/apiserver/Cargo.toml +++ b/apiserver/Cargo.toml @@ -32,7 +32,6 @@ tokio = { workspace = true, optional = false } tokio-stream = "0.1" tower = { version = "0.4.13", features = ["full"] } tower-http = { version = "0.4.4", features = ["full"] } -tower_governor = { git = "https://github.com/benwis/tower-governor", rev="01e1a107" } tracing = { workspace = true, optional = false } tracing-subscriber = { workspace = true, optional = false } utoipa = { version = "3", features = ["axum_extras", "uuid", "chrono"] } diff --git a/apiserver/src/app.rs b/apiserver/src/app.rs index eabfdd5..55cd608 100644 --- a/apiserver/src/app.rs +++ b/apiserver/src/app.rs @@ -15,37 +15,15 @@ use std::net::SocketAddr; use std::sync::Arc; -use axum::error_handling::HandleErrorLayer; -use axum::{BoxError, Server}; -use tower::ServiceBuilder; -use tower_governor::errors::display_error; -use tower_governor::governor::GovernorConfigBuilder; -use tower_governor::GovernorLayer; +use axum::Server; use crate::context::Context; use crate::{routes, swagger}; pub async fn run(ctx: Arc) { let port = ctx.config.port; - let governor_conf = Box::new( - GovernorConfigBuilder::default() - .per_second(1024) - .burst_size(1024) - .use_headers() - .finish() - .unwrap(), - ); - let app = routes::build() - .merge(swagger::build()) - .layer( - ServiceBuilder::new() - .layer(HandleErrorLayer::new(|e: BoxError| async move { display_error(e) })) - .layer(GovernorLayer { - config: Box::leak(governor_conf), - }), - ) - .with_state(ctx); + let app = routes::build().merge(swagger::build()).with_state(ctx); // run it let addr = SocketAddr::from(([0, 0, 0, 0], port)); diff --git a/crdgen/Cargo.toml b/crdgen/Cargo.toml index 03fa1c8..9f83b13 100644 --- a/crdgen/Cargo.toml +++ b/crdgen/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "amp-crdgen" -version = "0.2.0" +version.workspace = true edition.workspace = true license.workspace = true repository.workspace = true