C-Dash: Add bandwidth to trending graphs
[csit.git] / csit.infra.dash / app / cdash / trending / graphs.py
index 7d74775..fcfee26 100644 (file)
@@ -134,14 +134,17 @@ def graph_trending(
         hover = list()
         customdata = list()
         customdata_samples = list()
+        name_lst = name.split("-")
         for idx, (_, row) in enumerate(df.iterrows()):
-            d_type = "trex" if row["dut_type"] == "none" else row["dut_type"]
             hover_itm = (
+                f"dut: {name_lst[0]}<br>"
+                f"infra: {'-'.join(name_lst[1:5])}<br>"
+                f"test: {'-'.join(name_lst[5:])}<br>"
                 f"date: {row['start_time'].strftime('%Y-%m-%d %H:%M:%S')}<br>"
                 f"<prop> [{row[C.UNIT[ttype]]}]: {y_data[idx]:,.0f}<br>"
                 f"<stdev>"
                 f"<additional-info>"
-                f"{d_type}-ref: {row['dut_version']}<br>"
+                f"{row['dut_type']}-ref: {row['dut_version']}<br>"
                 f"csit-ref: {row['job']}/{row['build']}<br>"
                 f"hosts: {', '.join(row['hosts'])}"
             )
@@ -156,8 +159,14 @@ def graph_trending(
                 add_info = (
                     f"bandwidth [{row[C.UNIT['hoststack-bps']]}]: "
                     f"{row[C.VALUE['hoststack-bps']]:,.0f}<br>"
-                    f"latency [{row[C.UNIT['hoststack-lat']]}]: "
-                    f"{row[C.VALUE['hoststack-lat']]:,.0f}<br>"
+                    f"latency [{row[C.UNIT['hoststack-latency']]}]: "
+                    f"{row[C.VALUE['hoststack-latency']]:,.0f}<br>"
+                )
+            elif ttype in ("ndr", "pdr"):  # Add mrr
+                test_type = f"{ttype}-bandwidth"
+                add_info = (
+                    f"bandwidth [{row[C.UNIT[test_type]]}]: "
+                    f"{row[C.VALUE[test_type]]:,.0f}<br>"
                 )
             else:
                 add_info = str()
@@ -176,12 +185,14 @@ def graph_trending(
 
         hover_trend = list()
         for avg, stdev, (_, row) in zip(trend_avg, trend_stdev, df.iterrows()):
-            d_type = "trex" if row["dut_type"] == "none" else row["dut_type"]
             hover_itm = (
+                f"dut: {name_lst[0]}<br>"
+                f"infra: {'-'.join(name_lst[1:5])}<br>"
+                f"test: {'-'.join(name_lst[5:])}<br>"
                 f"date: {row['start_time'].strftime('%Y-%m-%d %H:%M:%S')}<br>"
                 f"trend [{row[C.UNIT[ttype]]}]: {avg:,.0f}<br>"
                 f"stdev [{row[C.UNIT[ttype]]}]: {stdev:,.0f}<br>"
-                f"{d_type}-ref: {row['dut_version']}<br>"
+                f"{row['dut_type']}-ref: {row['dut_version']}<br>"
                 f"csit-ref: {row['job']}/{row['build']}<br>"
                 f"hosts: {', '.join(row['hosts'])}"
             )
@@ -201,7 +212,7 @@ def graph_trending(
                     "symbol": "circle",
                 },
                 text=hover,
-                hoverinfo="text+name",
+                hoverinfo="text",
                 showlegend=True,
                 legendgroup=name,
                 customdata=customdata_samples
@@ -217,7 +228,7 @@ def graph_trending(
                     "color": color,
                 },
                 text=hover_trend,
-                hoverinfo="text+name",
+                hoverinfo="text",
                 showlegend=False,
                 legendgroup=name,
                 customdata=customdata
@@ -235,6 +246,9 @@ def graph_trending(
                     anomaly_y.append(trend_avg[idx])
                     anomaly_color.append(C.ANOMALY_COLOR[anomaly])
                     hover_itm = (
+                        f"dut: {name_lst[0]}<br>"
+                        f"infra: {'-'.join(name_lst[1:5])}<br>"
+                        f"test: {'-'.join(name_lst[5:])}<br>"
                         f"date: {x_axis[idx].strftime('%Y-%m-%d %H:%M:%S')}<br>"
                         f"trend [pps]: {trend_avg[idx]:,.0f}<br>"
                         f"classification: {anomaly}"
@@ -249,7 +263,7 @@ def graph_trending(
                     y=anomaly_y,
                     mode="markers",
                     text=hover,
-                    hoverinfo="text+name",
+                    hoverinfo="text",
                     showlegend=False,
                     legendgroup=name,
                     name=name,
@@ -287,6 +301,7 @@ def graph_trending(
 
     fig_tput = None
     fig_lat = None
+    fig_band = None
     y_units = set()
     for idx, itm in enumerate(sel):
         df = select_trending_data(data, itm)
@@ -318,6 +333,19 @@ def graph_trending(
                 fig_tput = go.Figure()
             fig_tput.add_traces(traces)
 
+        if ttype in ("ndr", "pdr"):  # Add mrr
+            traces, _ = _generate_trending_traces(
+                f"{ttype}-bandwidth",
+                itm["id"],
+                df,
+                get_color(idx),
+                norm_factor
+            )
+            if traces:
+                if not fig_band:
+                    fig_band = go.Figure()
+                fig_band.add_traces(traces)
+
         if itm["testtype"] == "pdr":
             traces, _ = _generate_trending_traces(
                 "latency",
@@ -338,10 +366,12 @@ def graph_trending(
         fig_layout["yaxis"]["title"] = \
             f"Throughput [{'|'.join(sorted(y_units))}]"
         fig_tput.update_layout(fig_layout)
+    if fig_band:
+        fig_band.update_layout(layout.get("plot-trending-bandwidth", dict()))
     if fig_lat:
         fig_lat.update_layout(layout.get("plot-trending-lat", dict()))
 
-    return fig_tput, fig_lat
+    return fig_tput, fig_band, fig_lat
 
 
 def graph_tm_trending(
@@ -389,8 +419,8 @@ def graph_tm_trending(
         :rtype: list
         """
         traces = list()
-        nr_of_metrics = len(data.tm_metric.unique())
-        for idx, metric in enumerate(data.tm_metric.unique()):
+        metrics = data.tm_metric.unique().tolist()
+        for idx, metric in enumerate(metrics):
             if "-pdr" in test and "='pdr'" not in metric:
                 continue
             if "-ndr" in test and "='ndr'" not in metric:
@@ -449,7 +479,7 @@ def graph_tm_trending(
             else:
                 anomalies = None
             if all_in_one:
-                color = get_color(color_index * nr_of_metrics + idx)
+                color = get_color(color_index * len(metrics) + idx)
                 metric_name = f"{test}<br>{metric}"
             else:
                 color = get_color(idx)
@@ -502,7 +532,7 @@ def graph_tm_trending(
                         anomaly_color.append(C.ANOMALY_COLOR[anomaly])
                         hover_itm = (
                             f"date: {x_axis[idx].strftime('%Y-%m-%d %H:%M:%S')}"
-                            f"<br>trend: {trend_avg[idx]:,.0f}"
+                            f"<br>trend: {trend_avg[idx]:,.2f}"
                             f"<br>classification: {anomaly}"
                         )
                         hover.append(hover_itm)
@@ -543,7 +573,10 @@ def graph_tm_trending(
                     )
                 )
 
-        return traces
+        unique_metrics = set()
+        for itm in metrics:
+            unique_metrics.add(itm.split("{", 1)[0])
+        return traces, unique_metrics
 
     tm_trending_graphs = list()
     graph_layout = layout.get("plot-trending-telemetry", dict())
@@ -551,22 +584,26 @@ def graph_tm_trending(
     if all_in_one:
         all_traces = list()
 
+    all_metrics = set()
+    all_tests = list()
     for idx, test in enumerate(data.test_name.unique()):
         df = data.loc[(data["test_name"] == test)]
-        traces = _generate_traces(df, test, all_in_one, idx)
+        traces, metrics = _generate_traces(df, test, all_in_one, idx)
         if traces:
+            all_metrics.update(metrics)
             if all_in_one:
                 all_traces.extend(traces)
+                all_tests.append(test)
             else:
                 graph = go.Figure()
                 graph.add_traces(traces)
                 graph.update_layout(graph_layout)
-                tm_trending_graphs.append((graph, test, ))
+                tm_trending_graphs.append((graph, [test, ], ))
 
     if all_in_one:
         graph = go.Figure()
         graph.add_traces(all_traces)
         graph.update_layout(graph_layout)
-        tm_trending_graphs.append((graph, str(), ))
+        tm_trending_graphs.append((graph, all_tests, ))
 
-    return tm_trending_graphs
+    return tm_trending_graphs, list(all_metrics)