bug 1517909 - format build telemetry time correctly when seconds has no fractional component. r=nalexander

It turns out that Python's `datetime.isoformat` method will leave off the
fractional component of seconds if it would be all zeroes, but the voluptuous
`Datetime` validator wants it to be present, so it's possible to hit an error
if you run mach at exactly an integer second.

This patch switches from `isoformat` to `strftime` with an explicit format
string instead.

Differential Revision: https://phabricator.services.mozilla.com/D15981

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ted Mielczarek 2019-01-08 21:29:26 +00:00
Родитель dc192a4fd7
Коммит 70af650a9f
3 изменённых файлов: 23 добавлений и 2 удалений

Просмотреть файл

@ -154,5 +154,12 @@ def test_registrar_dispatch(run_mach):
assert d['command'] == 'python'
def test_zero_microseconds(run_mach):
data = run_mach('python', '--exec-file',
os.path.join(os.path.dirname(__file__), 'zero_microseconds.py'))
d = data[0]
assert d['command'] == 'python'
if __name__ == '__main__':
mozunit.main()

Просмотреть файл

@ -0,0 +1,14 @@
# This code is loaded via `mach python --exec-file`, so it runs in the scope of
# the `mach python` command.
old = self._mach_context.post_dispatch_handler # noqa: F821
def handler(context, handler, instance, result,
start_time, end_time, depth, args):
global old
# Round off sub-second precision.
old(context, handler, instance, result,
int(start_time), end_time, depth, args)
self._mach_context.post_dispatch_handler = handler # noqa: F821

Просмотреть файл

@ -258,8 +258,8 @@ def gather_telemetry(command='', success=False, start_time=None, end_time=None,
'''
data = {
'client_id': get_client_id(mach_context.state_dir),
# Simplest way to get an rfc3339 datetime string, AFAICT.
'time': datetime.utcfromtimestamp(start_time).isoformat(b'T') + 'Z',
# Get an rfc3339 datetime string.
'time': datetime.utcfromtimestamp(start_time).strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
'command': command,
'argv': filter_args(command, sys.argv, paths),
'success': success,