Bug 1365577 - Don't print whitelist.json warning from histogram_tools.py outside of client builds r=chutten
authorRaajit Raj <raajit.raj@gmail.com>
Fri, 26 May 2017 01:23:15 +0530
changeset 360679 db097ec51f62
parent 360678 297b1dcda856
child 360680 247e0aab1a84
push id43437
push userchutten@mozilla.com
push dateThu, 25 May 2017 20:04:07 +0000
treeherderautoland@db097ec51f62 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschutten
bugs1365577
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1365577 - Don't print whitelist.json warning from histogram_tools.py outside of client builds r=chutten MozReview-Commit-ID: 2vR9UapLiKP
toolkit/components/telemetry/histogram_tools.py
--- a/toolkit/components/telemetry/histogram_tools.py
+++ b/toolkit/components/telemetry/histogram_tools.py
@@ -69,30 +69,32 @@ def exponential_buckets(dmin, dmax, n_bu
         ret_array[bucket_index] = current
     return ret_array
 
 always_allowed_keys = ['kind', 'description', 'cpp_guard', 'expires_in_version',
                        'alert_emails', 'keyed', 'releaseChannelCollection',
                        'bug_numbers', 'record_in_processes']
 
 whitelists = None
-try:
-    whitelist_path = os.path.join(os.path.abspath(os.path.realpath(os.path.dirname(__file__))),
-                                  'histogram-whitelists.json')
-    with open(whitelist_path, 'r') as f:
-        try:
-            whitelists = json.load(f)
-            for name, whitelist in whitelists.iteritems():
-                whitelists[name] = set(whitelist)
-        except ValueError, e:
-            raise ParserError('Error parsing whitelist: %s' % whitelist_path)
-except IOError:
-    whitelists = None
-    print('Unable to parse whitelist: %s.\nAssuming all histograms are acceptable.' %
-          whitelist_path)
+
+
+def load_whitelist():
+    try:
+        whitelist_path = os.path.join(os.path.abspath(os.path.realpath(os.path.dirname(__file__))),
+                                      'histogram-whitelists.json')
+        with open(whitelist_path, 'r') as f:
+            try:
+                whitelists = json.load(f)
+                for name, whitelist in whitelists.iteritems():
+                    whitelists[name] = set(whitelist)
+            except ValueError:
+                raise ParserError('Error parsing whitelist: %s' % whitelist_path)
+    except IOError:
+        whitelists = None
+        raise ParserError('Unable to parse whitelist: %s.' % whitelist_path)
 
 
 class Histogram:
     """A class for representing a histogram definition."""
 
     def __init__(self, name, definition, strict_type_checks=False):
         """Initialize a histogram named name with the given definition.
 definition is a dict-like object that must contain at least the keys:
@@ -589,16 +591,19 @@ try:
 except ImportError:
     pass
 
 
 def from_files(filenames, strict_type_checks=True):
     """Return an iterator that provides a sequence of Histograms for
 the histograms defined in filenames.
     """
+    if strict_type_checks:
+        load_whitelist()
+
     all_histograms = OrderedDict()
     for filename in filenames:
         parser = FILENAME_PARSERS[os.path.basename(filename)]
         histograms = parser(filename, strict_type_checks)
 
         # OrderedDicts are important, because then the iteration order over
         # the parsed histograms is stable, which makes the insertion into
         # all_histograms stable, which makes ordering in generated files