Upload artifacts to resultdb

We change the way we send the output and the ordered flags to resultdb:
 - we create an 'output' artifact to be uploaded end embedded in summary_html
 - we create a 'cmd' artifact that will capture the order of the flags

Example output from local tests:
https://luci-milo.appspot.com/ui/inv/u-liviurau-2022-11-28-12-06-00-b48f44fff8005ccc/test-results?sortby=&groupby=

Bug: v8:13316
Change-Id: Iad4d1bb299c8f2027060a342833585b946f76977
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4061309
Reviewed-by: Michael Achenbach <machenbach@chromium.org>
Commit-Queue: Liviu Rau <liviurau@google.com>
Cr-Commit-Position: refs/heads/main@{#84517}
This commit is contained in:
Liviu Rau 2022-11-28 15:13:06 +01:00 committed by V8 LUCI CQ
parent 617d631f23
commit c76c2787d9
3 changed files with 42 additions and 32 deletions

View File

@ -24,7 +24,7 @@ def print_failure_header(test, is_flaky=False):
print(output.encode(encoding, errors='replace').decode(encoding))
def formatted_result_output(result):
def formatted_result_output(result, relative=False):
lines = []
if result.output.stderr:
lines.append("--- stderr ---")
@ -32,7 +32,7 @@ def formatted_result_output(result):
if result.output.stdout:
lines.append("--- stdout ---")
lines.append(result.output.stdout.strip())
lines.append("Command: %s" % result.cmd.to_string())
lines.append("Command: %s" % result.cmd.to_string(relative))
if result.output.HasCrashed():
lines.append("exit code: %s" % result.output.exit_code_string)
lines.append("--- CRASHED ---")

View File

@ -4,20 +4,16 @@
import json
import logging
import pprint
import os
import re
import tempfile
from . import base
from .indicators import (
formatted_result_output,
ProgressIndicator,
)
from .util import (
base_test_record,
extract_tags,
strip_ascii_control_characters,
)
from .util import base_test_record
class ResultDBIndicator(ProgressIndicator):
@ -45,17 +41,49 @@ class ResultDBIndicator(ProgressIndicator):
if result.output and result.output.duration:
rdb_result.update(duration=f'{result.output.duration}ms')
if result.has_unexpected_output:
formated_output = formatted_result_output(result)
sanitized = strip_ascii_control_characters(formated_output)
# TODO(liviurau): do we have a better presentation data for this?
# Protobuf strings can have len == 2**32.
rdb_result.update(summaryHtml=f'<pre>{sanitized}</pre>')
formated_output = formatted_result_output(result,relative=True)
relative_cmd = result.cmd.to_string(relative=True)
artifacts = {
'output' : write_artifact(formated_output),
'cmd' : write_artifact(relative_cmd)
}
rdb_result.update(artifacts=artifacts)
summary = '<p><text-artifact artifact-id="output"></p>'
summary += '<p><text-artifact artifact-id="cmd"></p>'
rdb_result.update(summary_html=summary)
record = base_test_record(test, result, run)
rdb_result.update(tags=extract_tags(record))
self.rpc.send(rdb_result)
def write_artifact(value):
with tempfile.NamedTemporaryFile(mode='w', delete=False) as tmp:
tmp.write(value)
return { 'filePath': tmp.name }
def extract_tags(record):
tags = []
for k, v in record.items():
if type(v) == list:
tags += [sanitized_kv_dict(k, e) for e in v]
else:
tags.append(sanitized_kv_dict(k, v))
return tags
def sanitized_kv_dict(k, v):
return dict(key=k, value=strip_ascii_control_characters(v))
def strip_ascii_control_characters(unicode_string):
return re.sub(r'[^\x20-\x7E]', '?', str(unicode_string))
def rdb_sink():
try:
import requests

View File

@ -54,10 +54,6 @@ def kill_processes_linux():
logging.exception('Failed to kill process')
def strip_ascii_control_characters(unicode_string):
return re.sub(r'[^\x20-\x7E]', '?', str(unicode_string))
def base_test_record(test, result, run):
record = {
'name': test.full_name,
@ -77,20 +73,6 @@ def base_test_record(test, result, run):
return record
def extract_tags(record):
tags = []
for k, v in record.items():
if type(v) == list:
tags += [sanitized_kv_dict(k, e) for e in v]
else:
tags.append(sanitized_kv_dict(k, v))
return tags
def sanitized_kv_dict(k, v):
return dict(key=k, value=strip_ascii_control_characters(v))
class FixedSizeTopList():
"""Utility collection for gathering a fixed number of elements with the
biggest value for the given key. It employs a heap from which we pop the