From 96482c71beb61e7de0a7e36afda5d45dc0f5aad0 Mon Sep 17 00:00:00 2001 From: Robert Ma Date: Fri, 7 Sep 2018 18:51:05 -0400 Subject: [PATCH] [processor] Save the merged report This change makes the results processor to save the merged report instead of just the last chunk of the report if the original report is chunked when uploaded. Besides, it also sets the channel label (stable/experimental) based on a new property in the report, `run_info.browser_channel`, introduced in https://github.com/web-platform-tests/wpt/pull/12679 . --- results-processor/main.py | 12 ++++++++++-- results-processor/wptreport.py | 17 +++++++++++++++-- results-processor/wptreport_test.py | 26 ++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/results-processor/main.py b/results-processor/main.py index 26df0890980..1c23dff1095 100644 --- a/results-processor/main.py +++ b/results-processor/main.py @@ -168,11 +168,19 @@ def task_handler(): # to tell TaskQueue to drop the task. return ('', HTTPStatus.NO_CONTENT) - resp = "{} results loaded from {}\n".format(len(report.results), gcs_path) + resp = "{} results loaded from {}\n".format( + len(report.results), str(gcs_paths)) raw_results_gcs_path = '/{}/{}/report.json'.format( config.raw_results_bucket(), report.sha_product_path) - gsutil.copy('gs:/' + gcs_path, 'gs:/' + raw_results_gcs_path) + if result_type == 'single': + # If the original report isn't chunked, we store it directly without + # the roundtrip to serialize it back. + gsutil.copy('gs:/' + gcs_paths[0], 'gs:/' + raw_results_gcs_path) + else: + with tempfile.NamedTemporaryFile(suffix='.json.gz') as temp: + report.serialize_gzip(temp.name) + gsutil.copy(temp.name, 'gs:/' + raw_results_gcs_path, gzipped=True) tempdir = tempfile.mkdtemp() try: diff --git a/results-processor/wptreport.py b/results-processor/wptreport.py index 34e62ddf110..4c2250860df 100755 --- a/results-processor/wptreport.py +++ b/results-processor/wptreport.py @@ -414,6 +414,16 @@ def finalize(self): self.sha_product_path self.test_run_metadata + def serialize_gzip(self, filepath): + """Serializes and gzips the in-memory report to a file. + + finalize() should be called first. + + Args: + filepath: A file path to write to. + """ + self.write_gzip_json(filepath, self._report) + def prepare_labels(report, labels_str, uploader): """Prepares the list of labels for a test run. @@ -438,9 +448,12 @@ def prepare_labels(report, labels_str, uploader): # Empty labels may be generated here, but they will be removed later. for label in labels_str.split(','): labels.add(label.strip()) - # Set the default channel to stable. if ('stable' not in labels) and ('experimental' not in labels): - labels.add('stable') + # Extract browser_channel into a label; default to "stable". + if report.run_info.get('browser_channel') in {'nightly', 'dev'}: + labels.add('experimental') + else: + labels.add('stable') # Remove any empty labels. if '' in labels: labels.remove('') diff --git a/results-processor/wptreport_test.py b/results-processor/wptreport_test.py index 1526a2e3f63..7f9caaddfb2 100644 --- a/results-processor/wptreport_test.py +++ b/results-processor/wptreport_test.py @@ -479,3 +479,29 @@ def test_prepare_labels_from_experimental_label(self): prepare_labels(r, 'experimental', 'blade-runner'), ['blade-runner', 'experimental', 'firefox'] ) + + def test_prepare_labels_from_stable_label(self): + r = WPTReport() + r.update_metadata(browser_name='firefox') + self.assertListEqual( + prepare_labels(r, 'stable', 'blade-runner'), + ['blade-runner', 'firefox', 'stable'] + ) + + def test_prepare_labels_from_browser_channel(self): + r = WPTReport() + r._report = { + 'run_info': { + 'product': 'firefox', + 'browser_channel': 'dev', + } + } + self.assertListEqual( + prepare_labels(r, '', 'blade-runner'), + ['blade-runner', 'experimental', 'firefox'] + ) + r._report['run_info']['browser_channel'] = 'nightly' + self.assertListEqual( + prepare_labels(r, '', 'blade-runner'), + ['blade-runner', 'experimental', 'firefox'] + )