File tree 2 files changed +35
-2
lines changed
2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 4
4
5
5
from carbon .util import parseDestinations
6
6
from carbon .util import enableTcpKeepAlive
7
+ from carbon .util import TaggedSeries
7
8
8
9
9
10
class UtilTest (TestCase ):
@@ -21,6 +22,33 @@ def setTcpKeepAlive(self, value):
21
22
enableTcpKeepAlive (_Transport (), True , None )
22
23
self .assertEquals (s .getsockopt (socket .SOL_TCP , socket .SO_KEEPALIVE ), 1 )
23
24
25
+ def test_sanitizing_name_as_tag_value (self ):
26
+ test_cases = [
27
+ {
28
+ 'original' : "my~.test.abc" ,
29
+ 'expected' : "my.test.abc" ,
30
+ }, {
31
+ 'original' : "a.b.c" ,
32
+ 'expected' : "a.b.c" ,
33
+ }, {
34
+ 'original' : "~~a~~.~~~b~~~.~~~c~~~" ,
35
+ 'expected' : "a.b.c" ,
36
+ }, {
37
+ 'original' : "a.b.c~" ,
38
+ 'expected' : "a.b.c" ,
39
+ }, {
40
+ 'original' : "~a.b.c" ,
41
+ 'expected' : "a.b.c" ,
42
+ }, {
43
+ 'original' : "~a~" ,
44
+ 'expected' : "a" ,
45
+ },
46
+ ]
47
+
48
+ for test_case in test_cases :
49
+ result = TaggedSeries .sanitize_name_as_tag_value (test_case ['original' ])
50
+ self .assertEquals (result , test_case ['expected' ])
51
+
24
52
25
53
# Destinations have the form:
26
54
# <host> ::= <string without colons> | "[" <string> "]"
Original file line number Diff line number Diff line change @@ -365,7 +365,7 @@ def parse_openmetrics(cls, path):
365
365
tags [m .group (1 )] = m .group (2 ).replace (r'\"' , '"' ).replace (r'\\' , '\\ ' )
366
366
rawtags = rawtags [len (m .group (0 )):]
367
367
368
- tags ['name' ] = metric
368
+ tags ['name' ] = cls . sanitize_name_as_tag_value ( metric )
369
369
return cls (metric , tags )
370
370
371
371
@classmethod
@@ -386,9 +386,14 @@ def parse_carbon(cls, path):
386
386
387
387
tags [tag [0 ]] = tag [1 ]
388
388
389
- tags ['name' ] = metric
389
+ tags ['name' ] = cls . sanitize_name_as_tag_value ( metric )
390
390
return cls (metric , tags )
391
391
392
+ @staticmethod
393
+ def sanitize_name_as_tag_value (name ):
394
+ """take a metric name and sanitize it so it is guaranteed to be a valid tag value"""
395
+ return name .replace ('~' , '' )
396
+
392
397
@staticmethod
393
398
def format (tags ):
394
399
return tags .get ('name' , '' ) + '' .join (sorted ([
You can’t perform that action at this time.
0 commit comments