X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=csit.infra.dash%2Fapp%2Fcdash%2Ftrending%2Fgraphs.py;h=ede3a06fd491d93362493b284d56292236ca344a;hb=7d3054dede4f630e9b20ac0e69f029bea93bdf5f;hp=b6581e67f4008e923a7e2309d9dc00df26c89205;hpb=a214378b5d0589fcbd9a9cc8c9b25bce8a862cec;p=csit.git diff --git a/csit.infra.dash/app/cdash/trending/graphs.py b/csit.infra.dash/app/cdash/trending/graphs.py index b6581e67f4..ede3a06fd4 100644 --- a/csit.infra.dash/app/cdash/trending/graphs.py +++ b/csit.infra.dash/app/cdash/trending/graphs.py @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Cisco and/or its affiliates. +# Copyright (c) 2024 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -14,35 +14,13 @@ """Implementation of graphs for trending data. """ +import logging import plotly.graph_objects as go import pandas as pd -import hdrh.histogram -import hdrh.codec - from ..utils.constants import Constants as C -from ..utils.utils import classify_anomalies, get_color - - -def _get_hdrh_latencies(row: pd.Series, name: str) -> dict: - """Get the HDRH latencies from the test data. - - :param row: A row fron the data frame with test data. - :param name: The test name to be displayed as the graph title. - :type row: pandas.Series - :type name: str - :returns: Dictionary with HDRH latencies. - :rtype: dict - """ - - latencies = {"name": name} - for key in C.LAT_HDRH: - try: - latencies[key] = row[key] - except KeyError: - return None - - return latencies +from ..utils.utils import get_color, get_hdrh_latencies +from ..utils.anomalies import classify_anomalies def select_trending_data(data: pd.DataFrame, itm: dict) -> pd.DataFrame: @@ -93,7 +71,7 @@ def graph_trending( data: pd.DataFrame, sel: dict, layout: dict, - normalize: bool + normalize: bool=False ) -> tuple: """Generate the trending graph(s) - MRR, NDR, PDR and for PDR also Latences (result_latency_forward_pdr_50_avg). @@ -120,7 +98,7 @@ def graph_trending( name: str, df: pd.DataFrame, color: str, - norm_factor: float + nf: float ) -> list: """Generate the trending traces for the trending graph. @@ -128,57 +106,107 @@ def graph_trending( :param name: The test name to be displayed as the graph title. :param df: Data frame with test data. :param color: The color of the trace (samples and trend line). - :param norm_factor: The factor used for normalization of the results to + :param nf: The factor used for normalization of the results to CPU frequency set to Constants.NORM_FREQUENCY. :type ttype: str :type name: str :type df: pandas.DataFrame :type color: str - :type norm_factor: float + :type nf: float :returns: Traces (samples, trending line, anomalies) :rtype: list """ df = df.dropna(subset=[C.VALUE[ttype], ]) if df.empty: - return list() - - x_axis = df["start_time"].tolist() - if ttype == "pdr-lat": - y_data = [(v / norm_factor) for v in df[C.VALUE[ttype]].tolist()] - else: - y_data = [(v * norm_factor) for v in df[C.VALUE[ttype]].tolist()] - - anomalies, trend_avg, trend_stdev = classify_anomalies( - {k: v for k, v in zip(x_axis, y_data)} - ) + return list(), list() hover = list() customdata = list() customdata_samples = list() - for idx, (_, row) in enumerate(df.iterrows()): - d_type = "trex" if row["dut_type"] == "none" else row["dut_type"] + name_lst = name.split("-") + for _, row in df.iterrows(): + h_tput, h_band, h_lat = str(), str(), str() + if ttype in ("mrr", "mrr-bandwidth"): + h_tput = ( + f"tput avg [{row['result_receive_rate_rate_unit']}]: " + f"{row['result_receive_rate_rate_avg'] * nf:,.0f}
" + f"tput stdev [{row['result_receive_rate_rate_unit']}]: " + f"{row['result_receive_rate_rate_stdev'] * nf:,.0f}
" + ) + if pd.notna(row["result_receive_rate_bandwidth_avg"]): + h_band = ( + f"bandwidth avg " + f"[{row['result_receive_rate_bandwidth_unit']}]: " + f"{row['result_receive_rate_bandwidth_avg'] * nf:,.0f}" + "
" + f"bandwidth stdev " + f"[{row['result_receive_rate_bandwidth_unit']}]: " + f"{row['result_receive_rate_bandwidth_stdev']* nf:,.0f}" + "
" + ) + elif ttype in ("ndr", "ndr-bandwidth"): + h_tput = ( + f"tput [{row['result_ndr_lower_rate_unit']}]: " + f"{row['result_ndr_lower_rate_value'] * nf:,.0f}
" + ) + if pd.notna(row["result_ndr_lower_bandwidth_value"]): + h_band = ( + f"bandwidth [{row['result_ndr_lower_bandwidth_unit']}]:" + f" {row['result_ndr_lower_bandwidth_value'] * nf:,.0f}" + "
" + ) + elif ttype in ("pdr", "pdr-bandwidth", "latency"): + h_tput = ( + f"tput [{row['result_pdr_lower_rate_unit']}]: " + f"{row['result_pdr_lower_rate_value'] * nf:,.0f}
" + ) + if pd.notna(row["result_pdr_lower_bandwidth_value"]): + h_band = ( + f"bandwidth [{row['result_pdr_lower_bandwidth_unit']}]:" + f" {row['result_pdr_lower_bandwidth_value'] * nf:,.0f}" + "
" + ) + if pd.notna(row["result_latency_forward_pdr_50_avg"]): + h_lat = ( + f"latency " + f"[{row['result_latency_forward_pdr_50_unit']}]: " + f"{row['result_latency_forward_pdr_50_avg'] / nf:,.0f}" + "
" + ) + elif ttype in ("hoststack-cps", "hoststack-rps", + "hoststack-cps-bandwidth", + "hoststack-rps-bandwidth", "hoststack-latency"): + h_tput = ( + f"tput [{row['result_rate_unit']}]: " + f"{row['result_rate_value'] * nf:,.0f}
" + ) + h_band = ( + f"bandwidth [{row['result_bandwidth_unit']}]: " + f"{row['result_bandwidth_value'] * nf:,.0f}
" + ) + h_lat = ( + f"latency [{row['result_latency_unit']}]: " + f"{row['result_latency_value'] / nf:,.0f}
" + ) + elif ttype in ("hoststack-bps", ): + h_band = ( + f"bandwidth [{row['result_bandwidth_unit']}]: " + f"{row['result_bandwidth_value'] * nf:,.0f}
" + ) hover_itm = ( + f"dut: {name_lst[0]}
" + f"infra: {'-'.join(name_lst[1:5])}
" + f"test: {'-'.join(name_lst[5:])}
" f"date: {row['start_time'].strftime('%Y-%m-%d %H:%M:%S')}
" - f" [{row[C.UNIT[ttype]]}]: {y_data[idx]:,.0f}
" - f"" - f"{d_type}-ref: {row['dut_version']}
" + f"{h_tput}{h_band}{h_lat}" + f"{row['dut_type']}-ref: {row['dut_version']}
" f"csit-ref: {row['job']}/{row['build']}
" f"hosts: {', '.join(row['hosts'])}" ) - if ttype == "mrr": - stdev = ( - f"stdev [{row['result_receive_rate_rate_unit']}]: " - f"{row['result_receive_rate_rate_stdev']:,.0f}
" - ) - else: - stdev = "" - hover_itm = hover_itm.replace( - "", "latency" if ttype == "pdr-lat" else "average" - ).replace("", stdev) hover.append(hover_itm) - if ttype == "pdr-lat": - customdata_samples.append(_get_hdrh_latencies(row, name)) + if ttype == "latency": + customdata_samples.append(get_hdrh_latencies(row, name)) customdata.append({"name": name}) else: customdata_samples.append( @@ -186,18 +214,35 @@ def graph_trending( ) customdata.append({"name": name}) + x_axis = df["start_time"].tolist() + if "latency" in ttype: + y_data = [(v / nf) for v in df[C.VALUE[ttype]].tolist()] + else: + y_data = [(v * nf) for v in df[C.VALUE[ttype]].tolist()] + units = df[C.UNIT[ttype]].unique().tolist() + + try: + anomalies, trend_avg, trend_stdev = classify_anomalies( + {k: v for k, v in zip(x_axis, y_data)} + ) + except ValueError as err: + logging.error(err) + return list(), list() + 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]}
" + f"infra: {'-'.join(name_lst[1:5])}
" + f"test: {'-'.join(name_lst[5:])}
" f"date: {row['start_time'].strftime('%Y-%m-%d %H:%M:%S')}
" - f"trend [pps]: {avg:,.0f}
" - f"stdev [pps]: {stdev:,.0f}
" - f"{d_type}-ref: {row['dut_version']}
" + f"trend [{row[C.UNIT[ttype]]}]: {avg:,.0f}
" + f"stdev [{row[C.UNIT[ttype]]}]: {stdev:,.0f}
" + f"{row['dut_type']}-ref: {row['dut_version']}
" f"csit-ref: {row['job']}/{row['build']}
" f"hosts: {', '.join(row['hosts'])}" ) - if ttype == "pdr-lat": + if ttype == "latency": hover_itm = hover_itm.replace("[pps]", "[us]") hover_trend.append(hover_itm) @@ -213,7 +258,7 @@ def graph_trending( "symbol": "circle", }, text=hover, - hoverinfo="text+name", + hoverinfo="text", showlegend=True, legendgroup=name, customdata=customdata_samples @@ -229,7 +274,7 @@ def graph_trending( "color": color, }, text=hover_trend, - hoverinfo="text+name", + hoverinfo="text", showlegend=False, legendgroup=name, customdata=customdata @@ -247,11 +292,14 @@ def graph_trending( anomaly_y.append(trend_avg[idx]) anomaly_color.append(C.ANOMALY_COLOR[anomaly]) hover_itm = ( + f"dut: {name_lst[0]}
" + f"infra: {'-'.join(name_lst[1:5])}
" + f"test: {'-'.join(name_lst[5:])}
" f"date: {x_axis[idx].strftime('%Y-%m-%d %H:%M:%S')}
" f"trend [pps]: {trend_avg[idx]:,.0f}
" f"classification: {anomaly}" ) - if ttype == "pdr-lat": + if ttype == "latency": hover_itm = hover_itm.replace("[pps]", "[us]") hover.append(hover_itm) anomaly_color.extend([0.0, 0.5, 1.0]) @@ -261,7 +309,7 @@ def graph_trending( y=anomaly_y, mode="markers", text=hover, - hoverinfo="text+name", + hoverinfo="text", showlegend=False, legendgroup=name, name=name, @@ -271,7 +319,7 @@ def graph_trending( "symbol": "circle-open", "color": anomaly_color, "colorscale": C.COLORSCALE_LAT \ - if ttype == "pdr-lat" else C.COLORSCALE_TPUT, + if ttype == "latency" else C.COLORSCALE_TPUT, "showscale": True, "line": { "width": 2 @@ -284,7 +332,7 @@ def graph_trending( "tickmode": "array", "tickvals": [0.167, 0.500, 0.833], "ticktext": C.TICK_TEXT_LAT \ - if ttype == "pdr-lat" else C.TICK_TEXT_TPUT, + if ttype == "latency" else C.TICK_TEXT_TPUT, "ticks": "", "ticklen": 0, "tickangle": -90, @@ -294,11 +342,13 @@ def graph_trending( ) ) - return traces + return traces, units fig_tput = None fig_lat = None + fig_band = None + y_units = set() for idx, itm in enumerate(sel): df = select_trending_data(data, itm) if df is None or df.empty: @@ -307,143 +357,116 @@ def graph_trending( if normalize: phy = itm["phy"].split("-") topo_arch = f"{phy[0]}-{phy[1]}" if len(phy) == 4 else str() - norm_factor = (C.NORM_FREQUENCY / C.FREQUENCY[topo_arch]) \ + norm_factor = (C.NORM_FREQUENCY / C.FREQUENCY.get(topo_arch, 1.0)) \ if topo_arch else 1.0 else: norm_factor = 1.0 - traces = _generate_trending_traces(itm["testtype"], itm["id"], df, - get_color(idx), norm_factor) + + if itm["area"] == "hoststack": + ttype = f"hoststack-{itm['testtype']}" + else: + ttype = itm["testtype"] + + traces, units = _generate_trending_traces( + ttype, + itm["id"], + df, + get_color(idx), + norm_factor + ) if traces: if not fig_tput: fig_tput = go.Figure() fig_tput.add_traces(traces) - if itm["testtype"] == "pdr": - traces = _generate_trending_traces("pdr-lat", itm["id"], df, - get_color(idx), norm_factor) + if ttype in ("ndr", "pdr", "mrr", "hoststack-cps", "hoststack-rps"): + 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 ttype in ("pdr", "hoststack-cps", "hoststack-rps"): + traces, _ = _generate_trending_traces( + "latency" if ttype == "pdr" else "hoststack-latency", + itm["id"], + df, + get_color(idx), + norm_factor + ) if traces: if not fig_lat: fig_lat = go.Figure() fig_lat.add_traces(traces) + y_units.update(units) + if fig_tput: - fig_tput.update_layout(layout.get("plot-trending-tput", dict())) + fig_layout = layout.get("plot-trending-tput", dict()) + 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 - - -def graph_hdrh_latency(data: dict, layout: dict) -> go.Figure: - """Generate HDR Latency histogram graphs. - - :param data: HDRH data. - :param layout: Layout of plot.ly graph. - :type data: dict - :type layout: dict - :returns: HDR latency Histogram. - :rtype: plotly.graph_objects.Figure - """ - - fig = None - - traces = list() - for idx, (lat_name, lat_hdrh) in enumerate(data.items()): - try: - decoded = hdrh.histogram.HdrHistogram.decode(lat_hdrh) - except (hdrh.codec.HdrLengthException, TypeError): - continue - previous_x = 0.0 - prev_perc = 0.0 - xaxis = list() - yaxis = list() - hovertext = list() - for item in decoded.get_recorded_iterator(): - # The real value is "percentile". - # For 100%, we cut that down to "x_perc" to avoid - # infinity. - percentile = item.percentile_level_iterated_to - x_perc = min(percentile, C.PERCENTILE_MAX) - xaxis.append(previous_x) - yaxis.append(item.value_iterated_to) - hovertext.append( - f"{C.GRAPH_LAT_HDRH_DESC[lat_name]}
" - f"Direction: {('W-E', 'E-W')[idx % 2]}
" - f"Percentile: {prev_perc:.5f}-{percentile:.5f}%
" - f"Latency: {item.value_iterated_to}uSec" - ) - next_x = 100.0 / (100.0 - x_perc) - xaxis.append(next_x) - yaxis.append(item.value_iterated_to) - hovertext.append( - f"{C.GRAPH_LAT_HDRH_DESC[lat_name]}
" - f"Direction: {('W-E', 'E-W')[idx % 2]}
" - f"Percentile: {prev_perc:.5f}-{percentile:.5f}%
" - f"Latency: {item.value_iterated_to}uSec" - ) - previous_x = next_x - prev_perc = percentile - - traces.append( - go.Scatter( - x=xaxis, - y=yaxis, - name=C.GRAPH_LAT_HDRH_DESC[lat_name], - mode="lines", - legendgroup=C.GRAPH_LAT_HDRH_DESC[lat_name], - showlegend=bool(idx % 2), - line=dict( - color=get_color(int(idx/2)), - dash="solid", - width=1 if idx % 2 else 2 - ), - hovertext=hovertext, - hoverinfo="text" - ) - ) - if traces: - fig = go.Figure() - fig.add_traces(traces) - layout_hdrh = layout.get("plot-hdrh-latency", None) - if lat_hdrh: - fig.update_layout(layout_hdrh) - - return fig + return fig_tput, fig_band, fig_lat -def graph_tm_trending(data: pd.DataFrame, layout: dict) -> list: +def graph_tm_trending( + data: pd.DataFrame, + layout: dict, + all_in_one: bool=False + ) -> list: """Generates one trending graph per test, each graph includes all selected metrics. :param data: Data frame with telemetry data. :param layout: Layout of plot.ly graph. + :param all_in_one: If True, all telemetry traces are placed in one graph, + otherwise they are split to separate graphs grouped by test ID. :type data: pandas.DataFrame :type layout: dict + :type all_in_one: bool :returns: List of generated graphs together with test names. list(tuple(plotly.graph_objects.Figure(), str()), tuple(...), ...) :rtype: list """ + if data.empty: + return list() - def _generate_graph( + def _generate_traces( data: pd.DataFrame, test: str, - layout: dict - ) -> go.Figure: + all_in_one: bool, + color_index: int + ) -> list: """Generates a trending graph for given test with all metrics. :param data: Data frame with telemetry data for the given test. :param test: The name of the test. - :param layout: Layout of plot.ly graph. + :param all_in_one: If True, all telemetry traces are placed in one + graph, otherwise they are split to separate graphs grouped by + test ID. + :param color_index: The index of the test used if all_in_one is True. :type data: pandas.DataFrame :type test: str - :type layout: dict - :returns: A trending graph. - :rtype: plotly.graph_objects.Figure + :type all_in_one: bool + :type color_index: int + :returns: List of traces. + :rtype: list """ - graph = None traces = list() - 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: @@ -454,10 +477,33 @@ def graph_tm_trending(data: pd.DataFrame, layout: dict) -> list: y_data = [float(itm) for itm in df["tm_value"].tolist()] hover = list() for i, (_, row) in enumerate(df.iterrows()): + if row["test_type"] == "mrr": + rate = ( + f"mrr avg [{row[C.UNIT['mrr']]}]: " + f"{row[C.VALUE['mrr']]:,.0f}
" + f"mrr stdev [{row[C.UNIT['mrr']]}]: " + f"{row['result_receive_rate_rate_stdev']:,.0f}
" + ) + elif row["test_type"] == "ndrpdr": + if "-pdr" in test: + rate = ( + f"pdr [{row[C.UNIT['pdr']]}]: " + f"{row[C.VALUE['pdr']]:,.0f}
" + ) + elif "-ndr" in test: + rate = ( + f"ndr [{row[C.UNIT['ndr']]}]: " + f"{row[C.VALUE['ndr']]:,.0f}
" + ) + else: + rate = str() + else: + rate = str() hover.append( f"date: " f"{row['start_time'].strftime('%Y-%m-%d %H:%M:%S')}
" - f"value: {y_data[i]:,.0f}
" + f"value: {y_data[i]:,.2f}
" + f"{rate}" f"{row['dut_type']}-ref: {row['dut_version']}
" f"csit-ref: {row['job']}/{row['build']}
" ) @@ -471,19 +517,25 @@ def graph_tm_trending(data: pd.DataFrame, layout: dict) -> list: hover_trend.append( f"date: " f"{row['start_time'].strftime('%Y-%m-%d %H:%M:%S')}
" - f"trend: {avg:,.0f}
" - f"stdev: {stdev:,.0f}
" + f"trend: {avg:,.2f}
" + f"stdev: {stdev:,.2f}
" f"{row['dut_type']}-ref: {row['dut_version']}
" f"csit-ref: {row['job']}/{row['build']}" ) else: anomalies = None - color = get_color(idx) + if all_in_one: + color = get_color(color_index * len(metrics) + idx) + metric_name = f"{test}
{metric}" + else: + color = get_color(idx) + metric_name = metric + traces.append( go.Scatter( # Samples x=x_axis, y=y_data, - name=metric, + name=metric_name, mode="markers", marker={ "size": 5, @@ -493,7 +545,7 @@ def graph_tm_trending(data: pd.DataFrame, layout: dict) -> list: text=hover, hoverinfo="text+name", showlegend=True, - legendgroup=metric + legendgroup=metric_name ) ) if anomalies: @@ -501,7 +553,7 @@ def graph_tm_trending(data: pd.DataFrame, layout: dict) -> list: go.Scatter( # Trend line x=x_axis, y=trend_avg, - name=metric, + name=metric_name, mode="lines", line={ "shape": "linear", @@ -511,7 +563,7 @@ def graph_tm_trending(data: pd.DataFrame, layout: dict) -> list: text=hover_trend, hoverinfo="text+name", showlegend=False, - legendgroup=metric + legendgroup=metric_name ) ) @@ -526,7 +578,7 @@ def graph_tm_trending(data: pd.DataFrame, layout: dict) -> list: anomaly_color.append(C.ANOMALY_COLOR[anomaly]) hover_itm = ( f"date: {x_axis[idx].strftime('%Y-%m-%d %H:%M:%S')}" - f"
trend: {trend_avg[idx]:,.0f}" + f"
trend: {trend_avg[idx]:,.2f}" f"
classification: {anomaly}" ) hover.append(hover_itm) @@ -539,8 +591,8 @@ def graph_tm_trending(data: pd.DataFrame, layout: dict) -> list: text=hover, hoverinfo="text+name", showlegend=False, - legendgroup=metric, - name=metric, + legendgroup=metric_name, + name=metric_name, marker={ "size": 15, "symbol": "circle-open", @@ -567,23 +619,37 @@ def graph_tm_trending(data: pd.DataFrame, layout: dict) -> list: ) ) - if traces: - graph = go.Figure() - graph.add_traces(traces) - graph.update_layout(layout.get("plot-trending-telemetry", dict())) - - return graph - + 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()) - if data.empty: - return tm_trending_graphs + if all_in_one: + all_traces = list() - for test in data.test_name.unique(): + all_metrics = set() + all_tests = list() + for idx, test in enumerate(data.test_name.unique()): df = data.loc[(data["test_name"] == test)] - graph = _generate_graph(df, test, layout) - if graph: - tm_trending_graphs.append((graph, test, )) - - return tm_trending_graphs + 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, ], )) + + if all_in_one: + graph = go.Figure() + graph.add_traces(all_traces) + graph.update_layout(graph_layout) + tm_trending_graphs.append((graph, all_tests, )) + + return tm_trending_graphs, list(all_metrics)