update dependencies
This commit is contained in:
parent
d24a574405
commit
a82982bf09
@ -7,19 +7,19 @@ edition = "2018"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
clap = "3.0.0-beta.1"
|
||||
httparse = "1.3"
|
||||
http = "0.2"
|
||||
log = "0.4"
|
||||
env_logger = "0.7"
|
||||
clap = { version = "4.1.8", features = ["derive"] }
|
||||
httparse = "1.8"
|
||||
http = "0.2.9"
|
||||
log = "0.4.17"
|
||||
env_logger = "0.10.0"
|
||||
pretty_env_logger = "0.4"
|
||||
threadpool = "1.8"
|
||||
tokio = { version = "0.2", features = ["full"] }
|
||||
rand = "0.7"
|
||||
parking_lot = "0.10"
|
||||
threadpool = "1.8.1"
|
||||
tokio = { version = "1.26", features = ["full"] }
|
||||
rand = "0.8.5"
|
||||
parking_lot = "0.12.1"
|
||||
|
||||
[dev-dependencies]
|
||||
nix = "0.17"
|
||||
hyper = "0.13"
|
||||
reqwest = "0.10"
|
||||
async-trait = "0.1"
|
||||
nix = "0.26.2"
|
||||
hyper = "0.14.24"
|
||||
reqwest = "0.11.14"
|
||||
async-trait = "0.1.66"
|
||||
|
||||
@ -1,41 +1,33 @@
|
||||
mod request;
|
||||
mod response;
|
||||
|
||||
use clap::Clap;
|
||||
use clap::Parser;
|
||||
use rand::{Rng, SeedableRng};
|
||||
use std::net::{TcpListener, TcpStream};
|
||||
|
||||
/// Contains information parsed from the command-line invocation of balancebeam. The Clap macros
|
||||
/// provide a fancy way to automatically construct a command-line argument parser.
|
||||
#[derive(Clap, Debug)]
|
||||
#[clap(about = "Fun with load balancing")]
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(about = "Fun with load balancing")]
|
||||
struct CmdOptions {
|
||||
#[clap(
|
||||
short,
|
||||
long,
|
||||
about = "IP/port to bind to",
|
||||
default_value = "0.0.0.0:1100"
|
||||
)]
|
||||
/// "IP/port to bind to"
|
||||
#[arg(short, long, default_value = "0.0.0.0:1100")]
|
||||
bind: String,
|
||||
#[clap(short, long, about = "Upstream host to forward requests to")]
|
||||
|
||||
/// "Upstream host to forward requests to"
|
||||
#[arg(short, long)]
|
||||
upstream: Vec<String>,
|
||||
#[clap(
|
||||
long,
|
||||
about = "Perform active health checks on this interval (in seconds)",
|
||||
default_value = "10"
|
||||
)]
|
||||
|
||||
/// "Perform active health checks on this interval (in seconds)"
|
||||
#[arg(long, default_value = "10")]
|
||||
active_health_check_interval: usize,
|
||||
#[clap(
|
||||
long,
|
||||
about = "Path to send request to for active health checks",
|
||||
default_value = "/"
|
||||
)]
|
||||
|
||||
/// "Path to send request to for active health checks"
|
||||
#[arg(long, default_value = "/")]
|
||||
active_health_check_path: String,
|
||||
#[clap(
|
||||
long,
|
||||
about = "Maximum number of requests to accept per IP per minute (0 = unlimited)",
|
||||
default_value = "0"
|
||||
)]
|
||||
|
||||
/// "Maximum number of requests to accept per IP per minute (0 = unlimited)"
|
||||
#[arg(long, default_value = "0")]
|
||||
max_requests_per_minute: usize,
|
||||
}
|
||||
|
||||
@ -100,7 +92,7 @@ fn main() {
|
||||
|
||||
fn connect_to_upstream(state: &ProxyState) -> Result<TcpStream, std::io::Error> {
|
||||
let mut rng = rand::rngs::StdRng::from_entropy();
|
||||
let upstream_idx = rng.gen_range(0, state.upstream_addresses.len());
|
||||
let upstream_idx = rng.gen_range(0..state.upstream_addresses.len());
|
||||
let upstream_ip = &state.upstream_addresses[upstream_idx];
|
||||
TcpStream::connect(upstream_ip).or_else(|err| {
|
||||
log::error!("Failed to connect to upstream {}: {}", upstream_ip, err);
|
||||
|
||||
@ -3,7 +3,7 @@ mod common;
|
||||
use common::{init_logging, BalanceBeam, EchoServer, ErrorServer, Server};
|
||||
|
||||
use std::time::Duration;
|
||||
use tokio::time::delay_for;
|
||||
use tokio::time::sleep;
|
||||
|
||||
async fn setup_with_params(
|
||||
n_upstreams: usize,
|
||||
@ -162,7 +162,7 @@ async fn test_active_health_checks_check_http_status() {
|
||||
upstreams.push(Box::new(ErrorServer::new_at_address(failed_ip).await));
|
||||
|
||||
log::info!("Waiting for health checks to realize server is dead...");
|
||||
delay_for(Duration::from_secs(3)).await;
|
||||
sleep(Duration::from_secs(3)).await;
|
||||
|
||||
// Make sure we get back successful requests
|
||||
for i in 0..8 {
|
||||
@ -209,7 +209,7 @@ async fn test_active_health_checks_restore_failed_upstream() {
|
||||
upstreams.push(Box::new(EchoServer::new_at_address(failed_ip).await));
|
||||
|
||||
log::info!("Waiting a few seconds for the active health check to run...");
|
||||
delay_for(Duration::from_secs(3)).await;
|
||||
sleep(Duration::from_secs(3)).await;
|
||||
|
||||
log::info!("Sending some more requests");
|
||||
for i in 0..5 {
|
||||
|
||||
@ -2,7 +2,7 @@ use rand::Rng;
|
||||
use std::time::Duration;
|
||||
use tokio::io::{AsyncBufReadExt, BufReader};
|
||||
use tokio::process::{Child, Command};
|
||||
use tokio::time::delay_for;
|
||||
use tokio::time::sleep;
|
||||
|
||||
pub struct BalanceBeam {
|
||||
#[allow(dead_code)]
|
||||
@ -25,7 +25,7 @@ impl BalanceBeam {
|
||||
max_requests_per_minute: Option<usize>,
|
||||
) -> BalanceBeam {
|
||||
let mut rng = rand::thread_rng();
|
||||
let address = format!("127.0.0.1:{}", rng.gen_range(1024, 65535));
|
||||
let address = format!("127.0.0.1:{}", rng.gen_range(1024..65535));
|
||||
let mut cmd = Command::new(BalanceBeam::target_bin_path());
|
||||
cmd.arg("--bind").arg(&address);
|
||||
for upstream in upstreams {
|
||||
@ -80,7 +80,7 @@ impl BalanceBeam {
|
||||
});
|
||||
|
||||
// Hack: wait for executable to start running
|
||||
delay_for(Duration::from_secs(1)).await;
|
||||
sleep(Duration::from_secs(1)).await;
|
||||
BalanceBeam { child, address }
|
||||
}
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ pub struct EchoServer {
|
||||
impl EchoServer {
|
||||
pub async fn new() -> EchoServer {
|
||||
let mut rng = rand::thread_rng();
|
||||
EchoServer::new_at_address(format!("127.0.0.1:{}", rng.gen_range(1024, 65535))).await
|
||||
EchoServer::new_at_address(format!("127.0.0.1:{}", rng.gen_range(1024..65535))).await
|
||||
}
|
||||
|
||||
pub async fn new_at_address(bind_addr_string: String) -> EchoServer {
|
||||
|
||||
@ -30,7 +30,7 @@ impl ErrorServer {
|
||||
#[allow(dead_code)]
|
||||
pub async fn new() -> ErrorServer {
|
||||
let mut rng = rand::thread_rng();
|
||||
ErrorServer::new_at_address(format!("127.0.0.1:{}", rng.gen_range(1024, 65535))).await
|
||||
ErrorServer::new_at_address(format!("127.0.0.1:{}", rng.gen_range(1024..65535))).await
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user