Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't panic when graph has no data #555

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [#552](https://github.com/tag1consulting/goose/pull/552) add `scenario_index`, `scenario_name`, `transaction_index` and `transaction_name` to the request log
- [#553](https://github.com/tag1consulting/goose/pull/553) remove `serde_cbor` dependency no longer required due to [#529]
- [#554](https://github.com/tag1consulting/goose/pull/554) update `flume`, `itertools`, `strum`, `strum_macros`, `tokio-tungstenite`, and `tungestenite` dependencies to latest versions
- [#555](https://github.com/tag1consulting/goose/pull/555) don't panic when report has no data

## 0.17.0 December 9, 2022
- [#529](https://github.com/tag1consulting/goose/pull/529) **API change** temporaryily removed Gaggle support `gaggle` feature) to allow upgrading Tokio and other dependencies.
Expand Down
162 changes: 83 additions & 79 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,79 +357,82 @@ impl<'a, T: Clone + TimeSeriesValue<T, U>, U: Serialize + Copy + PartialEq + Par
}

let mut total_values: TimeSeries<T, U> = TimeSeries::new();
let (legend, main_label, main_values, other_values) = if self.data.len() > 1 {
// If we are dealing with a metric with granular data we need to calculate totals.
for (_, single_data) in self.data.iter() {
total_values.add_time_series(single_data);
}
if self.data.is_empty() {
"<!-- no data, no legend -->".to_string()
} else {
let (legend, main_label, main_values, other_values) = if self.data.len() > 1 {
// If we are dealing with a metric with granular data we need to calculate totals.
for (_, single_data) in self.data.iter() {
total_values.add_time_series(single_data);
}

// We will have multiple lines. We need to prepare the legend section on the graph
// and create data series for all of them.
let mut legend = vec!["Total"];

let mut other_values = String::new();
if self.granular_data {
// In order for this to sort correctly we need to flip label and time series since tuples
// are sorted lexicographically so we want time series to be the first element of the tuple.
for (sub_data, label) in self
.data
.iter()
.map(|(label, sub_data)| (sub_data, label))
.sorted()
.rev()
{
legend.push(label);

let formatted_line = format!(
r#"{{
name: '{label}',
type: 'line',
symbol: 'none',
sampling: 'lttb',
data: {values},
}},
"#,
label = label,
values = json!(self.add_timestamp_to_html_graph_data(
&sub_data.get_graph_data(),
test_started_time
))
);
other_values += formatted_line.as_str();
// We will have multiple lines. We need to prepare the legend section on the graph
// and create data series for all of them.
let mut legend = vec!["Total"];

let mut other_values = String::new();
if self.granular_data {
// In order for this to sort correctly we need to flip label and time series since tuples
// are sorted lexicographically so we want time series to be the first element of the tuple.
for (sub_data, label) in self
.data
.iter()
.map(|(label, sub_data)| (sub_data, label))
.sorted()
.rev()
{
legend.push(label);

let formatted_line = format!(
r#"{{
name: '{label}',
type: 'line',
symbol: 'none',
sampling: 'lttb',
data: {values},
}},
"#,
label = label,
values = json!(self.add_timestamp_to_html_graph_data(
&sub_data.get_graph_data(),
test_started_time
))
);
other_values += formatted_line.as_str();
}
(
format!(
r#"legend: {{
type: '{legend_type}',
width: '75%',
data: {data},
}},"#,
legend_type = if self.data.len() > 4 {
"scroll"
} else {
"plain"
},
data = json!(legend)
),
"Total",
&total_values,
other_values,
)
} else {
("".to_string(), "Total", &total_values, "".to_string())
}
} else {
// If there is only one data series in the metric we simply display it.
(
format!(
r#"legend: {{
type: '{legend_type}',
width: '75%',
data: {data},
}},"#,
legend_type = if self.data.len() > 4 {
"scroll"
} else {
"plain"
},
data = json!(legend)
),
"Total",
&total_values,
other_values,
"".to_string(),
self.data.keys().next().unwrap().as_str(),
self.data.values().next().unwrap(),
"".to_string(),
)
} else {
("".to_string(), "Total", &total_values, "".to_string())
}
} else {
// If there is only one data series in the metric we simply display it.
(
"".to_string(),
self.data.keys().next().unwrap().as_str(),
self.data.values().next().unwrap(),
"".to_string(),
)
};
};

format!(
r#"<div class="graph">
format!(
r#"<div class="graph">
<div id="{html_id}" style="width: 1000px; height:500px; background: white;"></div>

<script type="text/javascript">
Expand Down Expand Up @@ -496,17 +499,18 @@ impl<'a, T: Clone + TimeSeriesValue<T, U>, U: Serialize + Copy + PartialEq + Par
}});
</script>
</div>"#,
html_id = self.html_id,
main_values = json!(self.add_timestamp_to_html_graph_data(
&main_values.get_graph_data(),
test_started_time
)),
y_axis_label = self.y_axis_label,
main_label = main_label,
legend = legend,
other_values = other_values,
steps = steps,
)
html_id = self.html_id,
main_values = json!(self.add_timestamp_to_html_graph_data(
&main_values.get_graph_data(),
test_started_time
)),
y_axis_label = self.y_axis_label,
main_label = main_label,
legend = legend,
other_values = other_values,
steps = steps,
)
}
}

/// Adds timestamps to the graph data series to ensure correct time display on x axis.
Expand Down
Loading