Fix Metric.send() to play nice with multiple metrics #56
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In short, method signature and usage (http://docs.datadoghq.com/api/#metrics) is different and misguiding. Also, it will send the wrong data if user pass list of metrics with
points
as a single value. Below is a detailed explanation.Here's a Metric.send() method without docstrings:
There're few issues with it:
metrics
will be a list of a sinle list ([[your metrics here]]
). Let's see what happens next.for metric in metrics
will take a list of metrics and compare it with a dict - indeed, list is not a dict, so no calls to cls._process_points(). It will absolutely not changemetrics
in any way. Sincepoints
must be a list of lists of timestamp and a value[[timestamp, value]]
, wrong data will be sent. Though datadog api will say202 Accepted
, it will not not accept any data at all.Metric.send(*metrics)
), and it will call_process_points()
and transform data in the right way. But then it will take only first metric (it will be a dict), and sinceseries
must be a list, not a dict, we will get an error. And that's what I changed - 1 line of code.