Skip to content

Commit

Permalink
tag1consulting#246: Enable requests per second graph on the report by…
Browse files Browse the repository at this point in the history
… default and remove additional options.
  • Loading branch information
slashrsm committed Nov 18, 2021
1 parent 45fa7e9 commit 923c6d0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 60 deletions.
54 changes: 1 addition & 53 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ const DEFAULT_PORT: &str = "5115";
/// --debug-format FORMAT Sets debug log format (csv, json, raw, pretty)
/// --no-debug-body Do not include the response body in the debug log
/// --status-codes Tracks additional status code metrics
/// --requests-per-second Tracks additional requests per second metrics
/// --rps-bucket Size (in seconds) of the time-based requests per second bucket (default: 10)
///
/// Advanced:
/// --no-telnet Doesn't enable telnet Controller
Expand Down Expand Up @@ -190,18 +188,8 @@ pub struct GooseConfiguration {
#[options(no_short)]
pub no_debug_body: bool,
/// Tracks additional status code metrics
#[options(no_short, help = "Tracks additional status code metrics")]
#[options(no_short, help = "Tracks additional status code metrics\n\nAdvanced:")]
pub status_codes: bool,
/// Tracks additional request per second metrics
#[options(no_short, help = "Tracks additional request per second metrics")]
pub requests_per_second: bool,
// Size (in seconds) of the time-based requests per second bucket (default: 10)
// Add a blank line and then an Advanced: header after this option
#[options(
no_short,
help = "Size of the time bucket in time-based requests per second calculations\n\nAdvanced:"
)]
pub rps_bucket: usize,
/// Doesn't enable telnet Controller
#[options(no_short)]
pub no_telnet: bool,
Expand Down Expand Up @@ -335,10 +323,6 @@ pub(crate) struct GooseDefaults {
pub co_mitigation: Option<GooseCoordinatedOmissionMitigation>,
/// An optional default to track additional status code metrics.
pub status_codes: Option<bool>,
/// An optional default to track requests per second metrics.
pub requests_per_second: Option<bool>,
// An optional default size of the requests per second bucket size.
pub rps_bucket: Option<usize>,
/// An optional default maximum requests per second.
pub throttle_requests: Option<usize>,
/// An optional default to follows base_url redirect with subsequent request.
Expand Down Expand Up @@ -1540,42 +1524,6 @@ impl GooseConfiguration {
])
.unwrap_or(false);

// Configure `requests_per_second`.
self.requests_per_second = self
.get_value(vec![
// Use --requests-per-second if set.
GooseValue {
value: Some(self.requests_per_second),
filter: !self.requests_per_second,
message: "requests_per_second",
},
// Otherwise use GooseDefault if set.
GooseValue {
value: defaults.requests_per_second,
filter: defaults.requests_per_second.is_none() || self.worker,
message: "requests_per_second",
},
])
.unwrap_or(false);

// Configure `rps_bucket`.
self.rps_bucket = self
.get_value(vec![
// Use --requests-per-second-bucket if set.
GooseValue {
value: Some(self.rps_bucket),
filter: self.rps_bucket == 0,
message: "rps_bucket",
},
// Otherwise use GooseDefault if set.
GooseValue {
value: defaults.rps_bucket,
filter: defaults.rps_bucket.is_none() || self.worker,
message: "rps_bucket",
},
])
.unwrap_or(10);

// Configure `no_telnet`.
self.no_telnet = self
.get_value(vec![
Expand Down
14 changes: 7 additions & 7 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,8 @@ impl GooseRequestMetricAggregate {
}

/// Record request in requests per second metric.
pub(crate) fn record_requests_per_second(&mut self, bucket_size: usize) {
let time_bucket = (Utc::now().timestamp() - self.start_time) as usize / bucket_size;
pub(crate) fn record_requests_per_second(&mut self) {
let time_bucket = (Utc::now().timestamp() - self.start_time) as usize / 10;

let counter = match self.requests_per_second.get(&time_bucket) {
Some(previous_count) => {
Expand Down Expand Up @@ -2447,8 +2447,8 @@ impl GooseAttack {
if self.configuration.status_codes {
merge_request.set_status_code(request_metric.status_code);
}
if self.configuration.requests_per_second {
merge_request.record_requests_per_second(self.configuration.rps_bucket);
if !self.configuration.report_file.is_empty() {
merge_request.record_requests_per_second();
}
if request_metric.success {
merge_request.success_count += 1;
Expand Down Expand Up @@ -2987,7 +2987,7 @@ impl GooseAttack {
}

let graph_rps_template: String;
if self.configuration.requests_per_second {
if !self.configuration.report_file.is_empty() {
let mut aggregated_count: HashMap<usize, usize> = HashMap::new();
for (_path, path_metric) in self.metrics.requests.iter() {
for (bucket, count) in path_metric.requests_per_second.iter() {
Expand All @@ -3003,12 +3003,12 @@ impl GooseAttack {
let mut rps: Vec<f32> = vec![0.0; aggregated_count.len()];
for (bucket, count) in aggregated_count.iter() {
let (requests_per_second, _failures_per_second) =
per_second_calculations(self.configuration.rps_bucket, *count, 0);
per_second_calculations(10, *count, 0);

rps[*bucket as usize] = requests_per_second;
}

graph_rps_template = report::graph_rps_template(rps, self.configuration.rps_bucket);
graph_rps_template = report::graph_rps_template(rps, 10);
} else {
graph_rps_template = "".to_string();
}
Expand Down

0 comments on commit 923c6d0

Please sign in to comment.