Skip to content

Commit

Permalink
Support addition of custom tags in heartbeater service (#45)
Browse files Browse the repository at this point in the history
* Support addition of custom tags in heartbeater service

* Fix pylint error

* Bump version
  • Loading branch information
haosong authored and sushantdewan123 committed Sep 19, 2019
1 parent 3a1e89a commit 29499db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -15,7 +15,7 @@

setuptools.setup(
name='wavefront-sdk-python',
version='1.2',
version='1.2.1',
author='Wavefront by VMware',
author_email='chitimba@wavefront.com',
url='https://github.com/wavefrontHQ/wavefront-sdk-python',
Expand Down
15 changes: 15 additions & 0 deletions wavefront_sdk/common/heartbeater_service.py
Expand Up @@ -21,6 +21,7 @@

# pylint: disable=E0012,R0205
# pylint: disable=too-few-public-methods
# pylint: disable=too-many-instance-attributes
class HeartbeaterService(object):
"""Service that periodically reports component heartbeats to Wavefront."""

Expand All @@ -38,6 +39,7 @@ def __init__(self, wavefront_client, application_tags, components, source):
self.source = source
self.reporting_interval_seconds = 60 * 5
self.heartbeat_metric_tags_list = []
self.custom_tags_set = set()
if isinstance(components, str):
components = [components]
for component in components:
Expand All @@ -54,6 +56,14 @@ def __init__(self, wavefront_client, application_tags, components, source):
self._timer = None
self._run()

def report_custom_tags(self, custom_tags):
"""
Append custom tags for heartbeat reporting.
@param custom_tags: dict of custom tags.
"""
self.custom_tags_set.add(custom_tags)

def _schedule_timer(self):
self._timer = threading.Timer(self.reporting_interval_seconds,
self._run)
Expand All @@ -72,6 +82,11 @@ def _report(self):
self.wavefront_client.send_metric(HEART_BEAT_METRIC, 1.0,
time.time(), self.source,
heartbeat)
while self.custom_tags_set:
self.wavefront_client.send_metric(HEART_BEAT_METRIC, 1.0,
time.time(), self.source,
self.custom_tags_set.pop())

# pylint: disable=broad-except,fixme
# TODO: Please make sure we catch more specific exception here.
except Exception:
Expand Down

0 comments on commit 29499db

Please sign in to comment.