Accept Unicode in the Aggregator

Our aggregator is rejecting unicode values for dimension key,value
and metric names.

Change-Id: Ic23a29702475f2b2c7ca0788bab678ebe190822c
This commit is contained in:
Michael James Hoppal 2015-08-24 09:26:48 -06:00
parent b669559730
commit 22c704560c
2 changed files with 27 additions and 3 deletions

View File

@ -151,7 +151,7 @@ class MetricsAggregator(object):
value_meta=None, timestamp=None, sample_rate=1):
if dimensions:
for k, v in dimensions.iteritems():
if not isinstance(k, str):
if not isinstance(k, (str, unicode)):
log.error("invalid dimension key {0} must be a string: {1} -> {2}".format(k, name, dimensions))
raise InvalidDimensionKey
if len(k) > 255 or len(k) < 1:
@ -161,7 +161,7 @@ class MetricsAggregator(object):
log.error("invalid characters in dimension key {0}: {1} -> {2}".format(k, name, dimensions))
raise InvalidDimensionKey
if not isinstance(v, str):
if not isinstance(v, (str, unicode)):
log.error("invalid dimension value {0} for key {1} must be a string: {2} -> {3}".format(v, k, name,
dimensions))
raise InvalidDimensionValue
@ -174,7 +174,7 @@ class MetricsAggregator(object):
dimensions))
raise InvalidDimensionValue
if not isinstance(name, str):
if not isinstance(name, (str, unicode)):
log.error("invalid metric name must be a string: {0} -> {1}".format(name, dimensions))
raise InvalidMetricName
if len(name) > 255 or len(name) < 1:

View File

@ -40,6 +40,30 @@ class TestMetricsAggregator(unittest.TestCase):
dimensions=dimensions,
value_meta=value_meta)
def testValidMetricUnicodeDimensionValue(self):
dimensions = {unichr(2440): 'B', 'B': 'C', 'D': 'E'}
value_meta = {"This is a test": "test, test, test"}
self.submit_metric("Foo",
5,
dimensions=dimensions,
value_meta=value_meta)
def testValidMetricUnicodeDimensionKey(self):
dimensions = {'A': 'B', 'B': unichr(920), 'D': 'E'}
value_meta = {"This is a test": "test, test, test"}
self.submit_metric("Foo",
5,
dimensions=dimensions,
value_meta=value_meta)
def testValidMetricUnicodeMetricName(self):
dimensions = {'A': 'B', 'B': 'C', 'D': 'E'}
value_meta = {"This is a test": "test, test, test"}
self.submit_metric(unichr(6021),
5,
dimensions=dimensions,
value_meta=value_meta)
def testInvalidMetricName(self):
dimensions = {'A': 'B', 'B': 'C', 'D': 'E'}
value_meta = {"This is a test": "test, test, test"}