bug 1505325 - refactor telemetry gathering slightly. r=firefox-build-system-reviewers,chmanchester

After bug 1497638 the method by which build telemetry data gets written
to disk is slightly convoluted. Since we're now invoking `gather_telemetry`
from `post_dispatch_handler`, we just make that function return the data
it gathers and inline the contents of `telemetry_handler` after the call
to it.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ted Mielczarek 2018-11-10 19:04:06 +00:00
Родитель 8e018fdef0
Коммит 0da497b124
2 изменённых файлов: 23 добавлений и 34 удалений

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

@ -201,28 +201,6 @@ def bootstrap(topsrcdir, mozilla_dir=None):
mozversioncontrol.MissingVCSTool):
return None
def telemetry_handler(context, data):
# We have not opted-in to telemetry
if not context.settings.build.telemetry:
return
telemetry_dir = os.path.join(get_state_dir()[0], 'telemetry')
try:
os.mkdir(telemetry_dir)
except OSError as e:
if e.errno != errno.EEXIST:
raise
outgoing_dir = os.path.join(telemetry_dir, 'outgoing')
try:
os.mkdir(outgoing_dir)
except OSError as e:
if e.errno != errno.EEXIST:
raise
with open(os.path.join(outgoing_dir, str(uuid.uuid4()) + '.json'),
'w') as f:
json.dump(data, f, sort_keys=True)
def should_skip_dispatch(context, handler):
# The user is performing a maintenance command.
if handler.name in ('bootstrap', 'doctor', 'mach-commands', 'vcs-setup',
@ -260,10 +238,27 @@ def bootstrap(topsrcdir, mozilla_dir=None):
substs = {}
# We gather telemetry for every operation...
gather_telemetry(command=handler.name, success=(result == 0),
start_time=start_time, end_time=end_time,
mach_context=context, substs=substs,
paths=[instance.topsrcdir, instance.topobjdir])
data = gather_telemetry(command=handler.name, success=(result == 0),
start_time=start_time, end_time=end_time,
mach_context=context, substs=substs,
paths=[instance.topsrcdir, instance.topobjdir])
if data:
telemetry_dir = os.path.join(get_state_dir()[0], 'telemetry')
try:
os.mkdir(telemetry_dir)
except OSError as e:
if e.errno != errno.EEXIST:
raise
outgoing_dir = os.path.join(telemetry_dir, 'outgoing')
try:
os.mkdir(outgoing_dir)
except OSError as e:
if e.errno != errno.EEXIST:
raise
with open(os.path.join(outgoing_dir, str(uuid.uuid4()) + '.json'),
'w') as f:
json.dump(data, f, sort_keys=True)
# Never submit data when running in automation.
if 'MOZ_AUTOMATION' in os.environ or 'TASK_ID' in os.environ:
@ -307,9 +302,6 @@ def bootstrap(topsrcdir, mozilla_dir=None):
if key == 'topdir':
return topsrcdir
if key == 'telemetry_handler':
return telemetry_handler
if key == 'post_dispatch_handler':
return post_dispatch_handler

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

@ -265,13 +265,10 @@ def gather_telemetry(command='', success=False, start_time=None, end_time=None,
try:
# Validate against the schema.
schema(data)
return data
except MultipleInvalid as exc:
msg = ['Build telemetry is invalid:']
for error in exc.errors:
msg.append(str(error))
print('\n'.join(msg) + '\n' + pprint.pformat(data))
telemetry_handler = getattr(mach_context,
'telemetry_handler', None)
if telemetry_handler:
telemetry_handler(mach_context, data)
return None