Skip to content
This repository has been archived by the owner on Jun 11, 2019. It is now read-only.

Commit

Permalink
Fixed Graphite event tagging to account for incorrect Graphite API do…
Browse files Browse the repository at this point in the history
…cumentation
  • Loading branch information
Mikael Johansson committed Nov 2, 2016
1 parent e02f8dd commit 935bcfa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/lighter/graphite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import urllib2
import socket
import time
import re
import lighter.util as util

class Graphite(object):
Expand All @@ -28,10 +29,13 @@ def notify(self, metricname, title, message, tags=[]):
self._call('/events/', {
'what': title,
'data': message,
'tags': merged_tags,
'tags': ' '.join(self._mangle(tag) for tag in merged_tags),
'when': now
})

def _mangle(self, tag):
return re.sub('[\s,]', '_', tag.strip())

def _send(self, address, data):
if not self._address or not self._url:
logging.debug('Graphite is not enabled')
Expand Down
5 changes: 3 additions & 2 deletions src/lighter/test/graphite_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ def testDeployNotify(self, mock_time, mock_socket, mock_jsonRequest):
'http://localhost:80/events/', method='POST', data={
'what': 'Deployed /myproduct/myservice to the default environment',
'data': 'Lighter deployed /myproduct/myservice with image meltwater/myservice:latest to default (localhost:8080)',
'tags': ['environment:default', 'service:/myproduct/myservice', 'somekey:someval',
'anotherkey:anotherval', 'justakey', 'source:lighter', 'type:change'],
'tags':
'environment:default service:/myproduct/myservice somekey:someval anotherkey:anotherval ' +
'justakey es_ca_pe trimwhitespace source:lighter type:change',
'when': 1477507464})

self.assertEquals(1, mock_sock.connect.call_count)
Expand Down
2 changes: 2 additions & 0 deletions src/resources/yaml/integration/graphite-config-tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ graphite:
- somekey:someval
- anotherkey:anotherval
- justakey
- ' es,ca pe '
- trimwhitespace

0 comments on commit 935bcfa

Please sign in to comment.