Skip to content

Commit

Permalink
Remove tower_governor layer from axum
Browse files Browse the repository at this point in the history
  • Loading branch information
wangeguo committed Oct 19, 2023
1 parent b361b07 commit 91ea589
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 160 deletions.
141 changes: 8 additions & 133 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
1 change: 0 additions & 1 deletion apiserver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
26 changes: 2 additions & 24 deletions apiserver/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Context>) {
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));
Expand Down
2 changes: 1 addition & 1 deletion crdgen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "amp-crdgen"
version = "0.2.0"
version.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
Expand Down

0 comments on commit 91ea589

Please sign in to comment.