-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update Travis CI Ubuntu and Python Versions. * Bump Package Version to 1.8.0. * Clean Code to Make Linters Pass. * Bring Back #noqa for Queue Import. * Update Docstrings in client.py * Bring Back Accidentally Deleted Line.
- Loading branch information
Showing
31 changed files
with
66 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Wavefront SDK Usage Example.""" | ||
|
||
import sys | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#!/usr/bin/env python3 | ||
# coding: utf-8 | ||
"""Wavefront Python SDK. | ||
<p>This is a Wavefront Python SDK</p> | ||
|
@@ -15,7 +14,7 @@ | |
|
||
setuptools.setup( | ||
name='wavefront-sdk-python', | ||
version='1.7.9', | ||
version='1.8.0', | ||
author='Wavefront by VMware', | ||
author_email='[email protected]', | ||
url='https://github.com/wavefrontHQ/wavefront-sdk-python', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
# pylint: disable=duplicate-code | ||
# -*- coding: utf-8 -*- | ||
"""Wavefront Client for Proxy and Direct Ingestion. | ||
@author Yogesh Prasad Kurmi ([email protected]) | ||
|
@@ -15,25 +13,26 @@ | |
|
||
try: | ||
import queue | ||
except ImportError: | ||
except ImportError: # Python 2.x | ||
import Queue as queue # noqa | ||
|
||
from . import entities | ||
from .common import connection_handler, constants, utils | ||
from .common.metrics import registry | ||
|
||
|
||
# pylint: disable=too-many-instance-attributes | ||
class WavefrontClient(connection_handler.ConnectionHandler, | ||
entities.WavefrontMetricSender, | ||
entities.WavefrontHistogramSender, | ||
entities.WavefrontTracingSpanSender, | ||
entities.WavefrontEventSender): | ||
"""Wavefront data ingestion client. | ||
Sends data directly/via proxy to Wavefront cluster.. | ||
Send data directly/via proxy to Wavefront cluster. | ||
""" | ||
|
||
# pylint: disable=too-many-instance-attributes | ||
|
||
WAVEFRONT_METRIC_FORMAT = 'wavefront' | ||
WAVEFRONT_HISTOGRAM_FORMAT = 'histogram' | ||
WAVEFRONT_TRACING_SPAN_FORMAT = 'trace' | ||
|
@@ -43,16 +42,9 @@ class WavefrontClient(connection_handler.ConnectionHandler, | |
REPORT_END_POINT = '/report' | ||
EVENT_END_POINT = '/api/v2/event' | ||
|
||
# pylint: disable=too-many-arguments | ||
# pylint: disable=too-many-statements | ||
|
||
def __init__(self, | ||
server, | ||
token, | ||
max_queue_size=50000, | ||
batch_size=10000, | ||
flush_interval_seconds=5, | ||
enable_internal_metrics=True): | ||
def __init__(self, server, token, max_queue_size=50000, batch_size=10000, | ||
flush_interval_seconds=5, enable_internal_metrics=True): | ||
# pylint: disable=too-many-arguments,too-many-statements | ||
"""Construct Direct Client. | ||
@param server: Server address, | ||
|
@@ -105,7 +97,6 @@ def __init__(self, | |
else: | ||
self._sdk_metrics_registry = registry.WavefrontSdkMetricsRegistry( | ||
wf_metric_sender=None) | ||
|
||
self._sdk_metrics_registry.new_gauge( | ||
'points.queue.size', self._metrics_buffer.qsize) | ||
self._sdk_metrics_registry.new_gauge( | ||
|
@@ -117,25 +108,27 @@ def __init__(self, | |
'points.invalid') | ||
self._points_dropped = self._sdk_metrics_registry.new_delta_counter( | ||
'points.dropped') | ||
self._points_report_errors = self._sdk_metrics_registry.new_delta_counter( | ||
'points.report.errors') | ||
|
||
self._points_report_errors = ( | ||
self._sdk_metrics_registry.new_delta_counter( | ||
'points.report.errors')) | ||
self._sdk_metrics_registry.new_gauge( | ||
'histograms.queue.size', self._histograms_buffer.qsize) | ||
'histograms.queue.size', | ||
self._histograms_buffer.qsize) | ||
self._sdk_metrics_registry.new_gauge( | ||
'histograms.queue.remaining_capacity', | ||
remaining_capacity_getter(self._histograms_buffer)) | ||
self._histograms_valid = self._sdk_metrics_registry.new_delta_counter( | ||
'histograms.valid') | ||
self._histograms_invalid = self._sdk_metrics_registry.new_delta_counter( | ||
'histograms.invalid') | ||
self._histograms_dropped = self._sdk_metrics_registry.new_delta_counter( | ||
'histograms.dropped') | ||
self._histograms_invalid = ( | ||
self._sdk_metrics_registry.new_delta_counter('histograms.invalid')) | ||
self._histograms_dropped = ( | ||
self._sdk_metrics_registry.new_delta_counter('histograms.dropped')) | ||
self._histograms_report_errors = ( | ||
self._sdk_metrics_registry.new_delta_counter('histograms.report.errors')) | ||
|
||
self._sdk_metrics_registry.new_delta_counter( | ||
'histograms.report.errors')) | ||
self._sdk_metrics_registry.new_gauge( | ||
'spans.queue.size', self._tracing_spans_buffer.qsize) | ||
'spans.queue.size', | ||
self._tracing_spans_buffer.qsize) | ||
self._sdk_metrics_registry.new_gauge( | ||
'spans.queue.remaining_capacity', | ||
remaining_capacity_getter(self._tracing_spans_buffer)) | ||
|
@@ -145,11 +138,12 @@ def __init__(self, | |
'spans.invalid') | ||
self._spans_dropped = self._sdk_metrics_registry.new_delta_counter( | ||
'spans.dropped') | ||
self._spans_report_errors = self._sdk_metrics_registry.new_delta_counter( | ||
'spans.report.errors') | ||
|
||
self._spans_report_errors = ( | ||
self._sdk_metrics_registry.new_delta_counter( | ||
'spans.report.errors')) | ||
self._sdk_metrics_registry.new_gauge( | ||
'span_logs.queue.size', self._spans_log_buffer.qsize) | ||
'span_logs.queue.size', | ||
self._spans_log_buffer.qsize) | ||
self._sdk_metrics_registry.new_gauge( | ||
'span_logs.queue.remaining_capacity', | ||
remaining_capacity_getter(self._spans_log_buffer)) | ||
|
@@ -159,11 +153,12 @@ def __init__(self, | |
'span_logs.invalid') | ||
self._span_logs_dropped = self._sdk_metrics_registry.new_delta_counter( | ||
'span_logs.dropped') | ||
self._span_logs_report_errors = self._sdk_metrics_registry.new_delta_counter( | ||
'span_logs.report.errors') | ||
|
||
self._span_logs_report_errors = ( | ||
self._sdk_metrics_registry.new_delta_counter( | ||
'span_logs.report.errors')) | ||
self._sdk_metrics_registry.new_gauge( | ||
'events.queue.size', self._events_buffer.qsize) | ||
'events.queue.size', | ||
self._events_buffer.qsize) | ||
self._sdk_metrics_registry.new_gauge( | ||
'events.queue.remaining_capacity', | ||
remaining_capacity_getter(self._events_buffer)) | ||
|
@@ -173,10 +168,12 @@ def __init__(self, | |
'events.invalid') | ||
self._events_dropped = self._sdk_metrics_registry.new_delta_counter( | ||
'events.dropped') | ||
self._events_report_errors = self._sdk_metrics_registry.new_delta_counter( | ||
'events.report.errors') | ||
self._events_report_errors = ( | ||
self._sdk_metrics_registry.new_delta_counter( | ||
'events.report.errors')) | ||
|
||
def _report(self, points, data_format, entity_prefix, report_errors): | ||
# Raw string is used for the docstring as there's a backslash. | ||
r"""One api call sending one given string data. | ||
@param points: List of data in string format, concat by '\n' | ||
|
@@ -198,13 +195,11 @@ def _report(self, points, data_format, entity_prefix, report_errors): | |
params = {'f': data_format} | ||
compressed_data = utils.gzip_compress(points.encode('utf-8')) | ||
response = requests.post(self.server + self.REPORT_END_POINT, | ||
params=params, | ||
headers=self._headers, | ||
params=params, headers=self._headers, | ||
data=compressed_data) | ||
|
||
self._sdk_metrics_registry.new_delta_counter( | ||
'{}.report.{}'.format(entity_prefix, | ||
response.status_code)).inc() | ||
self._sdk_metrics_registry.new_delta_counter('{}.report.{}'.format( | ||
entity_prefix, response.status_code)).inc() | ||
response.raise_for_status() | ||
except Exception as error: | ||
report_errors.inc() | ||
|
@@ -230,7 +225,7 @@ def _batch_report(self, batch_line_data, data_format, entity_prefix, | |
self._report('\n'.join(batch) + '\n', data_format, | ||
entity_prefix, report_errors) | ||
# pylint: disable=broad-except,fixme | ||
# TODO: Please replace a generic Exception with a specific one. | ||
# TODO: Replace a generic Exception with a specific one. | ||
except Exception as error: | ||
logging.error( | ||
'Failed to report %s data points to wavefront %s', | ||
|
@@ -301,6 +296,7 @@ def close(self): | |
self._sdk_metrics_registry.close(timeout_secs=1) | ||
|
||
def send_metric(self, name, value, timestamp, source, tags): | ||
# pylint: disable=too-many-arguments | ||
"""Send Metric Data via proxy/direct ingestion client. | ||
Wavefront Metrics Data format | ||
|
@@ -320,8 +316,9 @@ def send_metric(self, name, value, timestamp, source, tags): | |
@type tags: dict | ||
""" | ||
try: | ||
line_data = utils.metric_to_line_data( | ||
name, value, timestamp, source, tags, self._default_source) | ||
line_data = utils.metric_to_line_data(name, value, timestamp, | ||
source, tags, | ||
self._default_source) | ||
self._points_valid.inc() | ||
except ValueError as error: | ||
self._points_invalid.inc() | ||
|
@@ -346,6 +343,7 @@ def send_metric_now(self, metrics): | |
|
||
def send_distribution(self, name, centroids, histogram_granularities, | ||
timestamp, source, tags): | ||
# pylint: disable=too-many-arguments | ||
"""Send Distribution Data via proxy/direct ingestion client. | ||
Wavefront Histogram Data format | ||
|
@@ -368,9 +366,10 @@ def send_distribution(self, name, centroids, histogram_granularities, | |
@type tags: dict | ||
""" | ||
try: | ||
line_data = utils.histogram_to_line_data( | ||
name, centroids, histogram_granularities, timestamp, | ||
source, tags, self._default_source) | ||
line_data = utils.histogram_to_line_data(name, centroids, | ||
histogram_granularities, | ||
timestamp, source, tags, | ||
self._default_source) | ||
self._histograms_valid.inc() | ||
except ValueError as error: | ||
self._histograms_invalid.inc() | ||
|
@@ -393,10 +392,9 @@ def send_distribution_now(self, distributions): | |
self._batch_report(distributions, self.WAVEFRONT_HISTOGRAM_FORMAT, | ||
'histograms', self._histograms_report_errors) | ||
|
||
# pylint: disable=too-many-arguments | ||
|
||
def send_span(self, name, start_millis, duration_millis, source, trace_id, | ||
span_id, parents, follows_from, tags, span_logs): | ||
# pylint: disable=too-many-arguments | ||
"""Send span data via proxy/direct ingestion client. | ||
Wavefront Tracing Span Data format | ||
|
@@ -444,8 +442,8 @@ def send_span(self, name, start_millis, duration_millis, source, trace_id, | |
raise error | ||
if span_logs: | ||
try: | ||
line_data = utils.span_log_to_line_data( | ||
trace_id, span_id, span_logs) | ||
line_data = utils.span_log_to_line_data(trace_id, span_id, | ||
span_logs) | ||
self._span_logs_valid.inc() | ||
except ValueError as error: | ||
self._span_logs_invalid.inc() | ||
|
@@ -484,6 +482,7 @@ def send_span_log_now(self, span_logs): | |
|
||
def send_event(self, name, start_time, end_time, source, tags, | ||
annotations): | ||
# pylint: disable=too-many-arguments | ||
"""Send Event Data via proxy/direct ingestion client. | ||
Wavefront Event Data format | ||
|
@@ -510,13 +509,14 @@ def send_event(self, name, start_time, end_time, source, tags, | |
""" | ||
try: | ||
if self._token: | ||
line_data = utils.event_to_json( | ||
name, start_time, end_time, source, tags, annotations, | ||
self._default_source) | ||
line_data = utils.event_to_json(name, start_time, end_time, | ||
source, tags, annotations, | ||
self._default_source) | ||
else: | ||
line_data = utils.event_to_line_data( | ||
name, start_time, end_time, source, tags, annotations, | ||
self._default_source) | ||
line_data = utils.event_to_line_data(name, start_time, | ||
end_time, source, tags, | ||
annotations, | ||
self._default_source) | ||
self._events_valid.inc() | ||
except ValueError as error: | ||
self._events_invalid.inc() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Wavefront MultiClient to support Data Ingestion for Multiple Clients. | ||
@author Yogesh Prasad Kurmi ([email protected]) | ||
|
@@ -10,7 +9,7 @@ | |
from wavefront_sdk.multi_clients import WavefrontMultiClient | ||
|
||
|
||
# pylint: disable=W0232 | ||
# pylint: disable=W0232 # Class has no __init__ method | ||
class WavefrontClientFactory: | ||
"""Wavefront client factory. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Provide utils functions. | ||
@author Hao Song ([email protected]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
"""A connection handler for both proxy and direct client. | ||
@author: Hao Song ([email protected]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Wavefront SDK Metrics. | ||
@author Hao Song ([email protected]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Wavefront SDK Counter. | ||
@author Hao Song ([email protected]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Wavefront SDK Delta Counter. | ||
@author Joanna Ko ([email protected]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Wavefront SDK Gauge. | ||
@author Hao Song ([email protected]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Wavefront SDK Metric. | ||
@author Hao Song ([email protected]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Wavefront SDK Metrics Registry. | ||
@author Hao Song ([email protected]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Connection Handler class for sending data to a Wavefront proxy. | ||
@author: Hao Song ([email protected]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Utils module contains useful function for preparing and processing data. | ||
|
Oops, something went wrong.