Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[processor] Save the merged report and infer labels from browser_channel #529

Merged
merged 2 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions results-processor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For other reviewers, what changed here is str(gcs_paths).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, gcs_path is the last item in gcs_paths, the iteration variable, and it wasn't intended to be used outside of the loop.


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:
Expand Down
32 changes: 27 additions & 5 deletions results-processor/wptreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -414,15 +423,22 @@ 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.

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.
Expand All @@ -438,9 +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())
# Set the default channel to stable.
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('')
Expand Down
31 changes: 31 additions & 0 deletions results-processor/wptreport_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,34 @@ 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']
)
r._report['run_info']['browser_channel'] = 'beta'
self.assertListEqual(
prepare_labels(r, '', 'blade-runner'),
['beta', 'blade-runner', 'firefox']
)