Skip to content

Commit

Permalink
Merge 87cdb6e into 4546c22
Browse files Browse the repository at this point in the history
  • Loading branch information
xnuter committed Jun 12, 2021
2 parents 4546c22 + 87cdb6e commit 062c435
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: build
args: --release
args: --release --full

- name: Create artifact directory
run: mkdir artifacts
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Build
run: cargo build --verbose
run: cargo build --verbose --features full
- name: Run tests
run: cargo test --verbose

- name: Run tests full
run: cargo test --verbose --features full
- name: Run tests tls
run: cargo test --verbose --features tls-native

26 changes: 17 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "perf-gauge"
version = "0.1.8"
version = "0.1.9"
authors = ["Eugene Retunsky"]
license = "MIT OR Apache-2.0"
edition = "2018"
Expand All @@ -16,8 +16,7 @@ Gauging performance of network services. Snapshot or continuous, supports Promet

[dependencies]
clap = "3.0.0-beta.1"
reqwest = { version = "0.11", features = ["hyper-tls", "stream"] }
base64="0.13"
base64 = "0.13"
derive_builder = "0.9"
log = "0.4"
log4rs = "1"
Expand All @@ -32,16 +31,25 @@ async-trait = "0.1"
bytesize = "1.0"
humantime = "2.0"
regex = "1.3"
prometheus = {version = "0.11", features=["push"] }
rand = "0.8"
futures-util = "0.3"
hyper = { version = "0.14", features = ["full"] }
prometheus = { version = "0.11", features = ["push"], default-features = false, optional = true }
hyper-tls = {version = "0.5", default-features = false, optional = true }
native-tls = {version = "0.2", default-features = false, optional = true }
tokio-native-tls = {version = "0.3", default-features = false, optional = true }
hyper-boring = {version = "2", default-features = false, optional = true }
boring = {version = "1", default-features = false, optional = true }

[dev-dependencies]
mockito = "0.28"
tokio-test = "0.4"

[profile.dev]
opt-level = 0

[profile.release]
opt-level = 3
[features]
default = []
report_to_prometheus = ["prometheus"]
tls = ["hyper-tls"]
tls-native = ["tls", "native-tls", "tokio-native-tls"]
tls-boring = ["tls", "hyper-boring", "boring"]
full = ["report_to_prometheus", "tls-native"]
full-boring = ["report_to_prometheus", "tls-boring"]
61 changes: 46 additions & 15 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ use crate::bench_session::{BenchSession, BenchSessionBuilder, RateLadder, RateLa
/// except according to those terms.
use crate::http_bench_session::{HttpBenchAdapter, HttpBenchAdapterBuilder};
use crate::metrics::{DefaultConsoleReporter, ExternalMetricsServiceReporter};
use crate::prometheus_reporter::PrometheusReporter;
use clap::{clap_app, ArgMatches};
use core::fmt;
use std::net::SocketAddr;
use std::process::exit;
use std::str::FromStr;
use std::sync::Arc;
Expand Down Expand Up @@ -61,8 +59,7 @@ impl BenchmarkConfig {
(@subcommand http =>
(about: "Run in HTTP(S) mode")
(version: "0.1.8")
(@arg TUNNEL: --tunnel +takes_value "HTTP Tunnel used for connection, e.g. http://my-proxy.org")
(@arg IGNORE_CERT: --ignore_cert "Allow self signed certificates. Applies to the target (not proxy).")
(@arg IGNORE_CERT: --ignore_cert "Allow self signed certificates.")
(@arg CONN_REUSE: --conn_reuse "If connections should be re-used")
(@arg STORE_COOKIES: --store_cookies "If cookies should be stored")
(@arg HTTP2_ONLY: --http2_only "Enforce HTTP/2 only")
Expand Down Expand Up @@ -122,6 +119,44 @@ impl BenchmarkConfig {
.expect("RateLadderBuilder failed")
};

Ok(BenchmarkConfigBuilder::default()
.name(test_case_name.clone())
.rate_ladder(rate_ladder)
.concurrency(parse_num(concurrency, "Cannot parse CONCURRENCY"))
.verbose(false)
.continuous(matches.is_present("CONTINUOUS"))
.mode(BenchmarkConfig::build_mode(&matches))
.reporters(BenchmarkConfig::build_metric_destinations(
test_case_name,
matches,
))
.build()
.expect("BenchmarkConfig failed"))
}

#[cfg(not(feature = "report_to_prometheus"))]
fn build_metric_destinations(
test_case_name: Option<String>,
matches: ArgMatches,
) -> Vec<Arc<Box<dyn ExternalMetricsServiceReporter + Send + Sync>>> {
if matches.value_of("PROMETHEUS_ADDR").is_some() {
println!("Prometheus is not supported in this configuration");
exit(-1);
}

vec![Arc::new(Box::new(DefaultConsoleReporter::new(
test_case_name,
)))]
}

#[cfg(feature = "report_to_prometheus")]
fn build_metric_destinations(
test_case_name: Option<String>,
matches: ArgMatches,
) -> Vec<Arc<Box<dyn ExternalMetricsServiceReporter + Send + Sync>>> {
use crate::prometheus_reporter::PrometheusReporter;
use std::net::SocketAddr;

let mut metrics_destinations: Vec<
Arc<Box<dyn ExternalMetricsServiceReporter + Send + Sync + 'static>>,
> = vec![Arc::new(Box::new(DefaultConsoleReporter::new(
Expand All @@ -139,20 +174,17 @@ impl BenchmarkConfig {
))));
}

Ok(BenchmarkConfigBuilder::default()
.name(test_case_name)
.rate_ladder(rate_ladder)
.concurrency(parse_num(concurrency, "Cannot parse CONCURRENCY"))
.verbose(false)
.continuous(matches.is_present("CONTINUOUS"))
.mode(BenchmarkConfig::build_mode(&matches))
.reporters(metrics_destinations)
.build()
.expect("BenchmarkConfig failed"))
metrics_destinations
}

fn build_mode(matches: &ArgMatches) -> BenchmarkMode {
let mode = if let Some(config) = matches.subcommand_matches("http") {
#[cfg(feature = "tls-boring")]
if config.is_present("IGNORE_CERT") {
println!("--ignore_cert is not supported for BoringSSL");
exit(-1);
}

let http_config = HttpBenchAdapterBuilder::default()
.url(
config
Expand All @@ -161,7 +193,6 @@ impl BenchmarkConfig {
.map(|s| s.to_string())
.collect(),
)
.tunnel(config.value_of("TUNNEL").map(|s| s.to_string()))
.ignore_cert(config.is_present("IGNORE_CERT"))
.conn_reuse(config.is_present("CONN_REUSE"))
.store_cookies(config.is_present("STORE_COOKIES"))
Expand Down
Loading

0 comments on commit 062c435

Please sign in to comment.