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 330934 d8dcff77656ef4a4a87ed1bf6d3c3cbb46eab22b
parent 330933 13b22aa53d11db1cc9d54566ea8673a74f80c435
child 330935 c9c3c840af699d1bb6e854d467cd8a68fb887573
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschutten
bugs1188888
milestone50.0a1
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"