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

Commit

Permalink
Avoid aggegating Datadog deployment events accross envs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikael Johansson committed Sep 1, 2016
1 parent fe9e0a2 commit 6347ae9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/lighter/datadog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def __init__(self, token, tags=[]):
self._url = 'https://app.datadoghq.com'
self._tags = tags + ['source:lighter', 'type:change']

def notify(self, title, message, id, tags=[], priority='normal', alert_type='success'):
if not title or not message or not id:
logging.warn('Datadog title, message and id required')
def notify(self, title, message, aggregation_key, tags=[], priority='normal', alert_type='success'):
if not title or not message or not aggregation_key:
logging.warn('Datadog title, message and aggregation_key required')
return

merged_tags = list(tags) + self._tags
Expand All @@ -28,7 +28,7 @@ def notify(self, title, message, id, tags=[], priority='normal', alert_type='suc
self._call('/api/v1/events', {
'title': title,
'text': message,
'aggregation_key': 'lighter_' + id,
'aggregation_key': 'lighter_' + aggregation_key,
'tags': merged_tags,
'priority': priority,
'alert_type': alert_type,
Expand Down
2 changes: 1 addition & 1 deletion src/lighter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def deploy(marathonurl, filenames, noop=False, force=False, targetdir=None):
util.rget(service.document, 'datadog', 'token'),
util.toList(util.rget(service.document, 'datadog', 'tags')))
datadog.notify(
id=service.id,
aggregation_key="%s_%s" % (service.environment, service.id),
title="Deployed %s to the %s environment" % (service.id, service.environment),
message="%%%%%% \n Lighter deployed **%s** with image **%s** to **%s** (%s) \n %%%%%%" % (
service.id, service.image, service.environment, parsedMarathonUrl.netloc),
Expand Down
16 changes: 11 additions & 5 deletions src/lighter/test/datadog_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def testNotify(self, mock_jsonRequest):
Datadog('abc').notify(
title='test title',
message='test message',
id='/jenkins/test',
aggregation_key='/jenkins/test',
tags=['environment:test'],
priority='normal',
alert_type='info')
Expand All @@ -23,25 +23,31 @@ def testNoApiKey(self, mock_jsonRequest):
Datadog('').notify(
title='test title',
message='test message',
id='/jenkins/test',
aggregation_key='/jenkins/test',
tags=['environment:test'],
priority='normal',
alert_type='info')
self.assertEquals(mock_jsonRequest.call_count, 0)

@patch('lighter.util.jsonRequest')
def testNoTitle(self, mock_jsonRequest):
Datadog('abc').notify(title='', message='test message', id='/jenkins/test', tags=['environment:test'], priority='normal', alert_type='info')
Datadog('abc').notify(
title='',
message='test message',
aggregation_key='/jenkins/test',
tags=['environment:test'],
priority='normal',
alert_type='info')
self.assertEquals(mock_jsonRequest.call_count, 0)

@patch('lighter.util.jsonRequest')
def testNoMessage(self, mock_jsonRequest):
Datadog('abc').notify(title='test title', message='', id='/jenkins/test', tags=['environment:test'], priority='normal', alert_type='info')
Datadog('abc').notify(title='test title', message='', aggregation_key='/jenkins/test', tags=['environment:test'], priority='normal', alert_type='info')
self.assertEquals(mock_jsonRequest.call_count, 0)

@patch('lighter.util.jsonRequest')
def testNoID(self, mock_jsonRequest):
Datadog('abc').notify(title='test title', message='test message', id='', tags=['environment:test'], priority='normal', alert_type='info')
Datadog('abc').notify(title='test title', message='test message', aggregation_key='', tags=['environment:test'], priority='normal', alert_type='info')
self.assertEquals(mock_jsonRequest.call_count, 0)

def _createJsonRequestWrapper(self, marathonurl='http://localhost:1'):
Expand Down

0 comments on commit 6347ae9

Please sign in to comment.