Ottomata has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/178655

Change subject: Make default key_filter callback replace . and : found in key 
names to _
......................................................................

Make default key_filter callback replace . and : found in key names to _

This makes statsd happier and makes graphite hierarchies make more sense.

Change-Id: I56169743198a1619ca549185a06860e586116c32
---
M logster/parsers/JsonLogster.py
1 file changed, 7 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/debs/logster 
refs/changes/55/178655/1

diff --git a/logster/parsers/JsonLogster.py b/logster/parsers/JsonLogster.py
index 56073f5..b188472 100644
--- a/logster/parsers/JsonLogster.py
+++ b/logster/parsers/JsonLogster.py
@@ -32,18 +32,22 @@
 
         optparser = optparse.OptionParser()
         optparser.add_option('--key-separator', '-k', dest='key_separator', 
default='.',
-        help='Key separator for flattened json object key name. Default: \'.\' 
 \'/\' is not allowed.''')
+        help='Key separator for flattened json object key name. Default: \'.\' 
 \'/\' and \':\' are not allowed.''')
 
         opts, args = optparser.parse_args(args=options)
         self.key_separator = opts.key_separator
+
+        if self.key_separator == '/' or self.key_separator == ':':
+            raise RuntimeError('Cannot use : or / as key_separator.')
 
     def key_filter(self, key):
         '''
         Default key_filter method.  Override and implement
         this method if you want to do any filtering or transforming
-        on specific keys in your JSON object.
+        on specific keys in your JSON object.  This translates
+        key_separator and ':' to underscores.
         '''
-        return key
+        return key.replace(self.key_separator, '_').replace(':', '_')
 
     def get_metric_object(self, metric_name, metric_value):
         '''

-- 
To view, visit https://gerrit.wikimedia.org/r/178655
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I56169743198a1619ca549185a06860e586116c32
Gerrit-PatchSet: 1
Gerrit-Project: operations/debs/logster
Gerrit-Branch: master
Gerrit-Owner: Ottomata <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to