Bug 1188888 - Part 7 - Bonus - Explicitly restrict histogram names to current patterns. r=chutten
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Wed, 20 Jul 2016 17:10:24 +0200
changeset 306074 d8dcff77656ef4a4a87ed1bf6d3c3cbb46eab22b
parent 306073 13b22aa53d11db1cc9d54566ea8673a74f80c435
child 306075 c9c3c840af699d1bb6e854d467cd8a68fb887573
push id79765
push usercbook@mozilla.com
push dateThu, 21 Jul 2016 14:26:34 +0000
treeherdermozilla-inbound@ab54bfc55266 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschutten
bugs1188888
milestone50.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 1188888 - Part 7 - Bonus - Explicitly restrict histogram names to current patterns. r=chutten
toolkit/components/telemetry/histogram_tools.py
--- a/toolkit/components/telemetry/histogram_tools.py
+++ b/toolkit/components/telemetry/histogram_tools.py
@@ -243,16 +243,24 @@ associated with the histogram.  Returns 
     def check_name(self, name):
         if '#' in name:
             raise ValueError, '"#" not permitted for %s' % (name)
 
         # Avoid C++ identifier conflicts between histogram enums and label enum names.
         if name.startswith("LABELS_"):
             raise ValueError, "Histogram name '%s' can not start with LABELS_" % (name)
 
+        # To make it easier to generate C++ identifiers from this etc., we restrict
+        # the histogram names to a strict pattern.
+        # We skip this on the server to avoid failures with old Histogram.json revisions.
+        if self._strict_type_checks:
+            pattern = '^[a-z][a-z0-9_]+[a-z0-9]$'
+            if not re.match(pattern, name, re.IGNORECASE):
+                raise ValueError, "Histogram name '%s' doesn't confirm to '%s'" % (name, pattern)
+
     def check_expiration(self, name, definition):
         expiration = definition.get('expires_in_version')
 
         if not expiration:
             return
 
         if re.match(r'^[1-9][0-9]*$', expiration):
             expiration = expiration + ".0a1"