Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support addition of custom tags in heartbeater service #45

Merged
merged 3 commits into from Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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