Auto merge of #29222 - delan:mach-filter-intermittents-json, r=cybai

mach filter-intermittents: add progress and --json output mode

filter-intermittents takes a while, because it needs to look up each failure against the tracker api (or GitHub api), so it would be nice to know how long we’ll need to wait when running it interactively. The output is also pretty-printed in a format that’s not the easiest to analyse.

This patch adds some progress output (on stderr, one line with \\r), plus a --json output format as follows:

[{"test": "/path/to/foo", "output": "..."}, {"test": "/path/to/bar", "output": "..."}, ...]

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [ ] ~~`./mach build -d` does not report any errors~~
- [ ] ~~`./mach test-tidy` does not report any errors~~
- [ ] These changes fix #___ (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because they affect mach filter-intermittents only
This commit is contained in:
bors-servo 2023-01-11 11:31:57 +01:00 committed by GitHub
commit ce92b7bfbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -529,6 +529,8 @@ class MachCommands(CommandBase):
help='Print filtered log to file')
@CommandArgument('--log-intermittents', default=None,
help='Print intermittents to file')
@CommandArgument('--json', dest="json_mode", default=False, action="store_true",
help='Output filtered and intermittents as JSON')
@CommandArgument('--auth', default=None,
help='File containing basic authorization credentials for Github API (format `username:password`)')
@CommandArgument('--tracker-api', default=None, action='store',
@ -539,6 +541,7 @@ class MachCommands(CommandBase):
summary,
log_filteredsummary,
log_intermittents,
json_mode,
auth,
tracker_api,
reporter_api):
@ -551,6 +554,7 @@ class MachCommands(CommandBase):
failures = [json.loads(line) for line in file]
actual_failures = []
intermittents = []
progress = 0
for failure in failures:
if tracker_api:
if tracker_api == 'default':
@ -576,20 +580,30 @@ class MachCommands(CommandBase):
data = json.load(search)
is_intermittent = data['total_count'] > 0
progress += 1
print(f" [{progress}/{len(failures)}]", file=sys.stderr, end="\r")
if is_intermittent:
if 'output' in failure:
if json_mode:
intermittents.append(failure)
elif 'output' in failure:
intermittents.append(failure["output"])
else:
intermittents.append("%s [expected %s] %s \n"
% (failure["status"], failure["expected"], failure['test']))
else:
if 'output' in failure:
if json_mode:
actual_failures.append(failure)
elif 'output' in failure:
actual_failures.append(failure["output"])
else:
actual_failures.append("%s [expected %s] %s \n"
% (failure["status"], failure["expected"], failure['test']))
def format(outputs, description, file=sys.stdout):
if json_mode:
formatted = json.dumps(outputs)
else:
formatted = "%s %s:\n%s" % (len(outputs), description, "\n".join(outputs))
if file == sys.stdout:
file.write(formatted)