From da23f19a1ac6084e76ee2ebe5177a4266481d57b Mon Sep 17 00:00:00 2001 From: Robert Ma Date: Fri, 7 Sep 2018 18:51:05 -0400 Subject: [PATCH 1/2] [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. --- results-processor/main.py | 12 ++++++++++-- results-processor/wptreport.py | 9 ++++++++- results-processor/wptreport_test.py | 26 ++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 3 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..752ab8f5aae 100755 --- a/results-processor/wptreport.py +++ b/results-processor/wptreport.py @@ -414,6 +414,14 @@ 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. + + 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,7 +446,6 @@ 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') # Remove any empty labels. 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'] + ) From 9521c10b7aa5755e0dcadaf663a16fa83f3d2983 Mon Sep 17 00:00:00 2001 From: Robert Ma Date: Tue, 11 Sep 2018 10:27:37 -0400 Subject: [PATCH 2/2] [processor] Infer the channel label from reports When the uploader does not provide a channel label, the processor will now set it based on a new property in the report, `run_info.browser_channel`, introduced in https://github.com/web-platform-tests/wpt/pull/12679 . A new channel label, "beta", is also introduced in this commit, since we now have beta browsers running on Taskcluster daily. --- results-processor/wptreport.py | 23 +++++++++++++++++++---- results-processor/wptreport_test.py | 5 +++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/results-processor/wptreport.py b/results-processor/wptreport.py index 752ab8f5aae..85108ef6836 100755 --- a/results-processor/wptreport.py +++ b/results-processor/wptreport.py @@ -23,6 +23,15 @@ DEFAULT_PROJECT = 'wptdashboard' GCS_PUBLIC_DOMAIN = 'https://storage.googleapis.com' +CHANNEL_TO_LABEL = { + 'release': 'stable', + 'stable': 'stable', + 'beta': 'beta', + 'dev': 'experimental', + 'experimental': 'experimental', + 'nightly': 'experimental', + 'preview': 'experimental', +} _log = logging.getLogger(__name__) @@ -429,8 +438,7 @@ def prepare_labels(report, labels_str, uploader): The following labels will be automatically added: * The name of the uploader * The name of the browser - * "stable" (as in release channels), if neither "stable" or "experimental" - is provided by the uploader. + * The release channel of the browser (if the uploader doesn't provide one) Args: report: A WPTReport. @@ -446,8 +454,15 @@ 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()) - if ('stable' not in labels) and ('experimental' not in labels): - labels.add('stable') + + # Add the release channel label. + if not any([i in labels for i in set(CHANNEL_TO_LABEL.values())]): + if report.run_info.get('browser_channel') in CHANNEL_TO_LABEL: + labels.add(CHANNEL_TO_LABEL[report.run_info['browser_channel']]) + else: + # Default to "stable". + 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 7f9caaddfb2..1fe7914ad3b 100644 --- a/results-processor/wptreport_test.py +++ b/results-processor/wptreport_test.py @@ -505,3 +505,8 @@ def test_prepare_labels_from_browser_channel(self): prepare_labels(r, '', 'blade-runner'), ['blade-runner', 'experimental', 'firefox'] ) + r._report['run_info']['browser_channel'] = 'beta' + self.assertListEqual( + prepare_labels(r, '', 'blade-runner'), + ['beta', 'blade-runner', 'firefox'] + )