mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1652615: Share is_telemetry_enabled() logic between Sentry and telemetry r=firefox-build-system-reviewers,rstewart
Note that this moves settings-loading earlier in the bootstrap procedure, from "_run()" to "run()". Differential Revision: https://phabricator.services.mozilla.com/D83425
This commit is contained in:
parent
82696c5d69
commit
301f146dc4
@ -308,12 +308,8 @@ def bootstrap(topsrcdir, mozilla_dir=None):
|
||||
if depth != 1 or os.environ.get('MACH_MAIN_PID') != str(os.getpid()):
|
||||
return
|
||||
|
||||
# Don't write telemetry data for 'mach' when 'DISABLE_TELEMETRY' is set.
|
||||
if os.environ.get('DISABLE_TELEMETRY') == '1':
|
||||
return
|
||||
|
||||
# We have not opted-in to telemetry
|
||||
if not context.settings.build.telemetry:
|
||||
from mozbuild.telemetry import is_telemetry_enabled
|
||||
if not is_telemetry_enabled(context.settings):
|
||||
return
|
||||
|
||||
from mozbuild.telemetry import gather_telemetry
|
||||
|
@ -36,7 +36,7 @@ from .decorators import (
|
||||
from .dispatcher import CommandAction
|
||||
from .logging import LoggingManager
|
||||
from .registrar import Registrar
|
||||
from .sentry import register_sentry
|
||||
from .sentry import register_sentry, NoopErrorReporter
|
||||
from .util import setenv
|
||||
|
||||
SUGGEST_MACH_BUSTED_TEMPLATE = r'''
|
||||
@ -317,11 +317,7 @@ To see more help for a specific command, run:
|
||||
Returns the integer exit code that should be used. 0 means success. All
|
||||
other values indicate failure.
|
||||
"""
|
||||
if self.populate_context_handler:
|
||||
topsrcdir = self.populate_context_handler('topdir')
|
||||
sentry = register_sentry(argv, topsrcdir)
|
||||
else:
|
||||
sentry = register_sentry(argv)
|
||||
sentry = NoopErrorReporter()
|
||||
|
||||
# If no encoding is defined, we default to UTF-8 because without this
|
||||
# Python 2.7 will assume the default encoding of ASCII. This will blow
|
||||
@ -343,6 +339,18 @@ To see more help for a specific command, run:
|
||||
orig_env = dict(os.environ)
|
||||
|
||||
try:
|
||||
# Load settings as early as possible so things in dispatcher.py
|
||||
# can use them.
|
||||
for provider in Registrar.settings_providers:
|
||||
self.settings.register_provider(provider)
|
||||
self.load_settings(self.settings_paths)
|
||||
|
||||
if self.populate_context_handler:
|
||||
topsrcdir = self.populate_context_handler('topdir')
|
||||
sentry = register_sentry(argv, self.settings, topsrcdir)
|
||||
else:
|
||||
sentry = register_sentry(argv, self.settings)
|
||||
|
||||
if sys.version_info < (3, 0):
|
||||
if stdin.encoding is None:
|
||||
sys.stdin = codecs.getreader('utf-8')(stdin)
|
||||
@ -391,12 +399,6 @@ To see more help for a specific command, run:
|
||||
sys.stderr = orig_stderr
|
||||
|
||||
def _run(self, argv, sentry):
|
||||
# Load settings as early as possible so things in dispatcher.py
|
||||
# can use them.
|
||||
for provider in Registrar.settings_providers:
|
||||
self.settings.register_provider(provider)
|
||||
self.load_settings(self.settings_paths)
|
||||
|
||||
context = CommandContext(cwd=self.cwd,
|
||||
settings=self.settings, log_manager=self.log_manager,
|
||||
commands=Registrar)
|
||||
|
@ -5,15 +5,14 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import abc
|
||||
import os
|
||||
import re
|
||||
from os.path import expanduser
|
||||
|
||||
import sentry_sdk
|
||||
from mozboot.util import get_state_dir
|
||||
from mozbuild.telemetry import is_telemetry_enabled
|
||||
from mozversioncontrol import get_repository_object, InvalidRepoPath
|
||||
from six import string_types
|
||||
from six.moves.configparser import SafeConfigParser, NoOptionError
|
||||
|
||||
# The following developers frequently modify mach code, and testing will commonly cause
|
||||
# exceptions to be thrown. We don't want these exceptions reported to Sentry.
|
||||
@ -49,26 +48,8 @@ class NoopErrorReporter(ErrorReporter):
|
||||
pass
|
||||
|
||||
|
||||
def _is_telemetry_enabled(cfg_file):
|
||||
config = SafeConfigParser()
|
||||
|
||||
if not config.read(cfg_file):
|
||||
return False
|
||||
|
||||
try:
|
||||
telemetry_enabled = config.getboolean("build", "telemetry")
|
||||
except NoOptionError:
|
||||
return False
|
||||
|
||||
if not telemetry_enabled:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def register_sentry(argv, topsrcdir=None):
|
||||
cfg_file = os.path.join(get_state_dir(), 'machrc')
|
||||
if not _is_telemetry_enabled(cfg_file):
|
||||
def register_sentry(argv, settings, topsrcdir=None):
|
||||
if not is_telemetry_enabled(settings):
|
||||
return NoopErrorReporter()
|
||||
|
||||
if topsrcdir:
|
||||
|
@ -340,3 +340,11 @@ def verify_statedir(statedir):
|
||||
os.mkdir(submitted)
|
||||
|
||||
return outgoing, submitted, telemetry_log
|
||||
|
||||
|
||||
def is_telemetry_enabled(settings):
|
||||
# Don't write telemetry data for 'mach' when 'DISABLE_TELEMETRY' is set.
|
||||
if os.environ.get('DISABLE_TELEMETRY') == '1':
|
||||
return False
|
||||
|
||||
return settings.build.telemetry
|
||||
|
Loading…
Reference in New Issue
Block a user