From ae73a39b12cd8318eb2dd7b88a51c35e50dfb052 Mon Sep 17 00:00:00 2001 From: Shashank Reddy Boyapally Date: Mon, 25 Mar 2024 23:49:27 -0400 Subject: [PATCH] changed accordingly to fmatch 0.0.6, and filtering changepoints Signed-off-by: Shashank Reddy Boyapally --- pkg/daemon.py | 28 ++++++++++++++++++++-------- pkg/runTest.py | 2 +- pkg/utils.py | 27 +++++++++++++++------------ 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/pkg/daemon.py b/pkg/daemon.py index 0c2ad4d..c4d80cb 100644 --- a/pkg/daemon.py +++ b/pkg/daemon.py @@ -1,6 +1,7 @@ """ Module to run orion in daemon mode """ + import logging import shutil import os @@ -15,7 +16,12 @@ @app.post("/daemon") -async def daemon(file: UploadFile = File(...), uuid: str = "", baseline: str = ""): +async def daemon( + file: UploadFile = File(...), + uuid: str = "", + baseline: str = "", + filter_changepoints="", +): """starts listening on port 8000 on url /daemon Args: @@ -28,15 +34,21 @@ async def daemon(file: UploadFile = File(...), uuid: str = "", baseline: str = " new_file_name = f"{file_name}_copy{file_extension}" with open(new_file_name, "wb") as buffer: shutil.copyfileobj(file.file, buffer) - argDict={ - 'config': new_file_name, - 'output_path': "output.csv", - 'hunter_analyze': True, - 'output_format': "json", - 'uuid':uuid, - 'baseline':baseline, + argDict = { + "config": new_file_name, + "output_path": "output.csv", + "hunter_analyze": True, + "output_format": "json", + "uuid": uuid, + "baseline": baseline, } + filter_changepoints = ( + True if filter_changepoints == "true" else False # pylint: disable = R1719 + ) result = runTest.run(**argDict) + if filter_changepoints: + for key, value in result.items(): + result[key] = list(filter(lambda x: x.get("is_changepoint", False), value)) try: os.remove(new_file_name) except OSError as e: diff --git a/pkg/runTest.py b/pkg/runTest.py index c355f59..661af6e 100644 --- a/pkg/runTest.py +++ b/pkg/runTest.py @@ -33,7 +33,7 @@ def run(**kwargs): ) if kwargs["hunter_analyze"]: testname, result_data = run_hunter_analyze( - result, test, output=kwargs["output_format"], matcher=match + result, test, output=kwargs["output_format"] ) result_output[testname] = result_data return result_output diff --git a/pkg/utils.py b/pkg/utils.py index b38054c..4db3163 100644 --- a/pkg/utils.py +++ b/pkg/utils.py @@ -16,6 +16,7 @@ from hunter.report import Report, ReportType from hunter.series import Metric, Series +import pyshorteners from pkg.logrus import SingletonLogger @@ -23,7 +24,7 @@ -def run_hunter_analyze(merged_df, test, output, matcher): +def run_hunter_analyze(merged_df, test, output): """Start hunter analyze function Args: @@ -35,15 +36,15 @@ def run_hunter_analyze(merged_df, test, output, matcher): metrics = { column: Metric(1, 1.0) for column in merged_df.columns - if column not in ["uuid", "timestamp"] + if column not in ["uuid","timestamp","buildUrl"] } data = { column: merged_df[column] for column in merged_df.columns - if column not in ["uuid", "timestamp"] + if column not in ["uuid","timestamp","buildUrl"] } attributes = { - column: merged_df[column] for column in merged_df.columns if column in ["uuid"] + column: merged_df[column] for column in merged_df.columns if column in ["uuid","buildUrl"] } series = Series( test_name=test["name"], @@ -63,12 +64,12 @@ def run_hunter_analyze(merged_df, test, output, matcher): if output == "json": change_points_by_metric = series.analyze().change_points - output_json = parse_json_output(merged_df, change_points_by_metric,matcher=matcher) + output_json = parse_json_output(merged_df, change_points_by_metric) return test["name"], output_json return None -def parse_json_output(merged_df, change_points_by_metric,matcher): +def parse_json_output(merged_df, change_points_by_metric): """json output generator function Args: @@ -84,11 +85,8 @@ def parse_json_output(merged_df, change_points_by_metric,matcher): for index, entry in enumerate(df_json): entry["metrics"] = { key: {"value": entry.pop(key), "percentage_change": 0} - for key in entry.keys() - {"uuid", "timestamp"} + for key in entry.keys() - {"uuid", "timestamp", "buildUrl"} } - entry["buildUrl"] = matcher.get_metadata_by_uuid(entry.get("uuid")).get( - "buildUrl" - ) entry["is_changepoint"] = False for key in change_points_by_metric.keys(): @@ -261,7 +259,9 @@ def process_test(test, match, output, uuid, baseline): else: metadata = filter_metadata(uuid,match) logger_instance.info("The test %s has started", test["name"]) - uuids = match.get_uuid_by_metadata(metadata) + runs = match.get_uuid_by_metadata(metadata) + uuids = [run["uuid"] for run in runs] + buildUrls = {run["uuid"]: run["buildUrl"] for run in runs} if baseline in ('', None): uuids = match.get_uuid_by_metadata(metadata) if len(uuids) == 0: @@ -279,7 +279,10 @@ def process_test(test, match, output, uuid, baseline): lambda left, right: pd.merge(left, right, on="uuid", how="inner"), dataframe_list, ) - + shortener = pyshorteners.Shortener() + merged_df["buildUrl"] = merged_df["uuid"].apply( + lambda uuid: shortener.tinyurl.short(buildUrls[uuid]) #pylint: disable = cell-var-from-loop + ) output_file_path = output.split(".")[0] + "-" + test["name"] + ".csv" match.save_results(merged_df, csv_file_path=output_file_path) return merged_df