X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=csit.infra.dash%2Fapp%2Fcdash%2Ftrending%2Fgraphs.py;h=7b14501decb7c0e7495e301fbcd4766dbd1b7c5d;hb=0d6639a38336a3f73e276d81c86ea0d0895e1f40;hp=695bb0e287a4f498c7f08fb8b9a2efa63777ba27;hpb=d154ed2c2720084ecfae3669ccc82ddaa5618b83;p=csit.git diff --git a/csit.infra.dash/app/cdash/trending/graphs.py b/csit.infra.dash/app/cdash/trending/graphs.py index 695bb0e287..7b14501dec 100644 --- a/csit.infra.dash/app/cdash/trending/graphs.py +++ b/csit.infra.dash/app/cdash/trending/graphs.py @@ -17,32 +17,9 @@ 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: @@ -144,7 +121,7 @@ def graph_trending( return list(), list() x_axis = df["start_time"].tolist() - if ttype == "pdr-lat": + if ttype == "latency": 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()] @@ -185,11 +162,11 @@ def graph_trending( else: add_info = str() hover_itm = hover_itm.replace( - "", "latency" if ttype == "pdr-lat" else "average" + "", "latency" if ttype == "latency" else "average" ).replace("", stdev).replace("", add_info) 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( @@ -208,7 +185,7 @@ def graph_trending( 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) @@ -262,7 +239,7 @@ def graph_trending( 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]) @@ -282,7 +259,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 @@ -295,7 +272,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, @@ -343,7 +320,7 @@ def graph_trending( if itm["testtype"] == "pdr": traces, _ = _generate_trending_traces( - "pdr-lat", + "latency", itm["id"], df, get_color(idx), @@ -367,116 +344,53 @@ def graph_trending( 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 - - -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: @@ -487,10 +401,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']}
" ) @@ -504,19 +441,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, @@ -526,7 +469,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: @@ -534,7 +477,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", @@ -544,7 +487,7 @@ def graph_tm_trending(data: pd.DataFrame, layout: dict) -> list: text=hover_trend, hoverinfo="text+name", showlegend=False, - legendgroup=metric + legendgroup=metric_name ) ) @@ -572,8 +515,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", @@ -600,23 +543,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, all_metrics