From 0da497b1248080b11fa75a167b55cb3dd04ecc40 Mon Sep 17 00:00:00 2001 From: Ted Mielczarek Date: Sat, 10 Nov 2018 19:04:06 +0000 Subject: [PATCH] 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 --- build/mach_bootstrap.py | 50 +++++++++++---------------- python/mozbuild/mozbuild/telemetry.py | 7 ++-- 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/build/mach_bootstrap.py b/build/mach_bootstrap.py index 519870af34a1..76f645a14e8a 100644 --- a/build/mach_bootstrap.py +++ b/build/mach_bootstrap.py @@ -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 diff --git a/python/mozbuild/mozbuild/telemetry.py b/python/mozbuild/mozbuild/telemetry.py index 22b34d45b92c..bdb5b4dd3646 100644 --- a/python/mozbuild/mozbuild/telemetry.py +++ b/python/mozbuild/mozbuild/telemetry.py @@ -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