Skip to content

Commit

Permalink
#246: Fix coding style issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
slashrsm committed Nov 8, 2021
1 parent 4f5a33e commit 38c81fc
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 46 deletions.
65 changes: 34 additions & 31 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ pub struct GooseConfiguration {
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:")]
#[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)]
Expand Down Expand Up @@ -1508,39 +1511,39 @@ impl GooseConfiguration {

// 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);
.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);
.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
Expand Down
23 changes: 13 additions & 10 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,10 @@ impl GooseRequestMetricAggregate {

let counter = match self.requests_per_second.get(&time_bucket) {
Some(previous_count) => {
debug!("got time bucket {:?} counter: {}", time_bucket, previous_count);
debug!(
"got time bucket {:?} counter: {}",
time_bucket, previous_count
);
*previous_count + 1
}

Expand All @@ -476,7 +479,10 @@ impl GooseRequestMetricAggregate {
};

self.requests_per_second.insert(time_bucket, counter);
debug!("incremented time bucket {} counter: {}", time_bucket, counter);
debug!(
"incremented time bucket {} counter: {}",
time_bucket, counter
);
}
}
/// Implement ordering for GooseRequestMetricAggregate.
Expand Down Expand Up @@ -2987,24 +2993,21 @@ impl GooseAttack {
for (_path, path_metric) in self.metrics.requests.iter() {
for (bucket, count) in path_metric.requests_per_second.iter() {
let count = match aggregated_count.get(bucket) {
Some(prev) => { prev + *count as usize }
Some(prev) => prev + *count as usize,

None => { *count as usize }
None => *count as usize,
};
aggregated_count.insert(*bucket, count);
}
}

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,
);
let (requests_per_second, _failures_per_second) =
per_second_calculations(self.configuration.rps_bucket, *count, 0);

rps[*bucket as usize] = requests_per_second;
};
}

graph_rps_template = report::graph_rps_template(rps, self.configuration.rps_bucket);
} else {
Expand Down
12 changes: 7 additions & 5 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,13 @@ pub fn error_row(error: &metrics::GooseErrorMetricAggregate) -> String {

pub fn graph_rps_template(rps: Vec<f32>, bucket_size: usize) -> String {
let values = json!(rps);
let buckets = json!(
(0..rps.len()).
map(|bucket| format!("{}s - {}s", (bucket * bucket_size), ((bucket + 1) * bucket_size)))
.collect::<Vec<_>>()
);
let buckets = json!((0..rps.len())
.map(|bucket| format!(
"{}s - {}s",
(bucket * bucket_size),
((bucket + 1) * bucket_size)
))
.collect::<Vec<_>>());

format!(
r#"<div class="graph-rps">
Expand Down

0 comments on commit 38c81fc

Please sign in to comment.