Skip to content

Commit

Permalink
Merge pull request #102 from DataDog/yann/metric-data-type-support
Browse files Browse the repository at this point in the history
[api] `Metrics`: support long` data type
  • Loading branch information
yannmh committed Nov 16, 2015
2 parents 13a1e4b + cf680e1 commit 240fdf5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion datadog/api/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ class Metric(SearchableAPIResource, SendableAPIResource):
_METRIC_QUERY_ENDPOINT = '/query'
_METRIC_SUBMIT_ENDPOINT = '/series'

_SUPPORTED_DATA_TYPES = (int, float, long)

@classmethod
def _process_points(cls, points):
now = time.time()
if isinstance(points, (float, int)):
if isinstance(points, cls._SUPPORTED_DATA_TYPES):
points = [(now, points)]
elif isinstance(points, tuple):
points = [points]

return points

@classmethod
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,13 @@ def test_points_submission(self):
serie = [dict(metric='metric.1', points=13),
dict(metric='metric.2', points=19)]
self.submit_and_assess_metric_payload(serie)

def test_data_type_support(self):
"""
`Metric` API supports built-in real numerical data types.
"""
supported_data_types = [1, 1.0, 1L]

for point in supported_data_types:
serie = dict(metric='metric.numerical', points=point)
self.submit_and_assess_metric_payload(serie)

0 comments on commit 240fdf5

Please sign in to comment.