Merge "Allow spaces and apostrophes in dimension key/value"

This commit is contained in:
Jenkins
2016-01-07 03:02:13 +00:00
committed by Gerrit Code Review
4 changed files with 17 additions and 9 deletions

View File

@@ -118,7 +118,9 @@ class MetricsRepository(metrics_repository.MetricsRepository):
# name - optional
if name:
where_clause += ' from "{}" '.format(name.encode('utf8'))
# replace ' with \' to make query parsable
clean_name = name.replace("'", "\\'")
where_clause += ' from "{}" '.format(clean_name.encode('utf8'))
# tenant id
where_clause += " where _tenant_id = '{}' ".format(tenant_id.encode(
@@ -131,9 +133,13 @@ class MetricsRepository(metrics_repository.MetricsRepository):
if dimensions:
for dimension_name, dimension_value in iter(
sorted(dimensions.iteritems())):
# replace ' with \' to make query parsable
clean_dimension_name = dimension_name.replace("\'", "\\'")
clean_dimension_value = dimension_value.replace("\'", "\\'")
where_clause += " and \"{}\" = '{}'".format(
dimension_name.encode('utf8'), dimension_value.encode(
'utf8'))
clean_dimension_name.encode('utf8'),
clean_dimension_value.encode('utf8'))
if start_timestamp is not None:
where_clause += " and time > " + str(int(start_timestamp *

View File

@@ -189,8 +189,8 @@ valid_identifier_chars = (
metric_name = (
pyparsing.Word(valid_identifier_chars, min=1, max=255)("metric_name"))
dimension_name = pyparsing.Word(valid_identifier_chars, min=1, max=255)
dimension_value = pyparsing.Word(valid_identifier_chars, min=1, max=255)
dimension_name = pyparsing.Word(valid_identifier_chars + ' ', min=1, max=255)
dimension_value = pyparsing.Word(valid_identifier_chars + ' ', min=1, max=255)
MINUS = pyparsing.Literal('-')
integer_number = pyparsing.Word(pyparsing.nums)
@@ -289,6 +289,8 @@ def main():
"3test_metric5 lt 3",
"ntp.offset > 1 or ntp.offset < -5",
"max(3test_metric5{it's this=that's it}) lt 5 times 3",
]
for expr in expr_list:
@@ -304,8 +306,8 @@ def main():
sub_expr.fmtd_sub_expr_str.encode('utf8')))
print('sub_expr dimensions: {}'.format(
sub_expr.dimensions_str.encode('utf8')))
print()
print()
print("")
print("")
if __name__ == "__main__":

View File

@@ -21,7 +21,7 @@ import mock
import unittest
invalid_chars = "<>={}(),'\"\\;&"
invalid_chars = "<>={}(),\"\\;&"
class TestMetricNameValidation(unittest.TestCase):

View File

@@ -14,7 +14,7 @@
import re
invalid_chars = "<>={}(),'\"\\\\;&"
invalid_chars = "<>={}(),\"\\\\;&"
restricted_chars = re.compile('[' + invalid_chars + ']')