File tree 2 files changed +25
-7
lines changed
2 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -26,28 +26,41 @@ def test_sanitizing_name_as_tag_value(self):
26
26
test_cases = [
27
27
{
28
28
'original' : "my~.test.abc" ,
29
- 'expected' : "my.test.abc" ,
29
+ 'expected' : "my~ .test.abc" ,
30
30
}, {
31
31
'original' : "a.b.c" ,
32
32
'expected' : "a.b.c" ,
33
33
}, {
34
34
'original' : "~~a~~.~~~b~~~.~~~c~~~" ,
35
- 'expected' : "a.b.c " ,
35
+ 'expected' : "a~~.~~~b~~~.~~~c~~~ " ,
36
36
}, {
37
37
'original' : "a.b.c~" ,
38
- 'expected' : "a.b.c" ,
38
+ 'expected' : "a.b.c~ " ,
39
39
}, {
40
40
'original' : "~a.b.c" ,
41
41
'expected' : "a.b.c" ,
42
42
}, {
43
43
'original' : "~a~" ,
44
- 'expected' : "a" ,
44
+ 'expected' : "a~" ,
45
+ }, {
46
+ 'original' : "~~~" ,
47
+ 'raises' : True ,
48
+ }, {
49
+ 'original' : "~" ,
50
+ 'raises' : True ,
45
51
},
46
52
]
47
53
48
54
for test_case in test_cases :
49
- result = TaggedSeries .sanitize_name_as_tag_value (test_case ['original' ])
50
- self .assertEquals (result , test_case ['expected' ])
55
+ if test_case .get ('raises' , False ):
56
+ self .assertRaises (
57
+ Exception ,
58
+ TaggedSeries .sanitize_name_as_tag_value ,
59
+ test_case ['original' ],
60
+ )
61
+ else :
62
+ result = TaggedSeries .sanitize_name_as_tag_value (test_case ['original' ])
63
+ self .assertEquals (result , test_case ['expected' ])
51
64
52
65
53
66
# Destinations have the form:
Original file line number Diff line number Diff line change @@ -392,7 +392,12 @@ def parse_carbon(cls, path):
392
392
@staticmethod
393
393
def sanitize_name_as_tag_value (name ):
394
394
"""take a metric name and sanitize it so it is guaranteed to be a valid tag value"""
395
- return name .replace ('~' , '' )
395
+ sanitized = name .lstrip ('~' )
396
+
397
+ if len (sanitized ) == 0 :
398
+ raise Exception ('Cannot use metric name %s as tag value, results in emptry string' % (name ))
399
+
400
+ return sanitized
396
401
397
402
@staticmethod
398
403
def format (tags ):
You can’t perform that action at this time.
0 commit comments