Socket
Socket
Sign inDemoInstall

dogapi

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dogapi - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

16

lib/api/metric.js

@@ -15,3 +15,3 @@ var client = require("../client");

* * tags: array of "tag:value"'s to use for the metric
* * metric_type: which metric type to use ("gauge" or "counter") [default: gauge]
* * metric_type|type: which metric type to use ("gauge" or "counter") [default: gauge]
* callback: |

@@ -37,2 +37,5 @@ * function(err, res)

* });
* dogapi.metric.send("my.counter", 5, {type: "counter"}, function(err, results){
* console.dir(results);
* });
* ```

@@ -52,3 +55,4 @@ */

tags: extra.tags,
metric_type: extra.metric_type
// DEV: For backwards compatibility, allow `metric_type`
type: extra.type || extra.metric_type
}

@@ -70,3 +74,3 @@ ];

* * host: the source hostname to use for the metrics
* * metric_type: the type of metric to use ("gauge" or "counter") [default: gauge]
* * metric_type|type: the type of metric to use ("gauge" or "counter") [default: gauge]
* callback: |

@@ -128,2 +132,8 @@ * function(err, res)

metrics[i].points = points;
// DEV: Change `metric_type` to `type` for backwards compatibility
metrics[i].type = metrics[i].type || metrics[i].metric_type;
// Remove `metric_type` if it was set
// DEV: This will not cause an error if `metric_type` does not exist
delete metrics[i].metric_type;
}

@@ -130,0 +140,0 @@

2

package.json
{
"name": "dogapi",
"version": "2.1.0",
"version": "2.1.1",
"description": "Datadog API Node.JS Client",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -32,4 +32,4 @@ var assert = require("assert");

// Properly formatted body
// { body: series: [ {metric: "metric.send", host: undefined, tags: undefined, metric_type: undefined} ] }
// DEV: host/tags/metric_type are optional and should be undefined for this case
// { body: series: [ {metric: "metric.send", host: undefined, tags: undefined, type: undefined} ] }
// DEV: host/tags/type are optional and should be undefined for this case
var data = call_args[2];

@@ -57,4 +57,4 @@ assert(data.hasOwnProperty("body"));

assert.equal(first_series.tags, undefined);
assert(first_series.hasOwnProperty("metric_type"));
assert.equal(first_series.metric_type, undefined);
assert(first_series.hasOwnProperty("type"));
assert.equal(first_series.type, undefined);
});

@@ -136,2 +136,53 @@

});
it("should properly set metric type", function(){
// Make our api call
metric.send("metrics.send.counter", 5, {type: "counter"});
// Assert we called `client.request` with the correct `points`
assert(stub_request.calledOnce);
var call_args = stub_request.getCall(0).args;
// { body: series: [ {points: [], }, ] }
var body = call_args[2].body;
assert.equal(body.series.length, 1);
// Assert we have only 1 series
// series = [ {metric: "", ...}, ... ]
var series = body.series;
assert(Array.isArray(series));
assert.equal(series.length, 1);
// Assert the first series is properly formatted
// first_series = {metric: "", type: "counter", points: [], ...}
var first_series = series[0]
assert.equal(first_series.metric, "metrics.send.counter");
assert(first_series.hasOwnProperty("type"));
assert.equal(first_series.type, "counter");
});
it("should properly set convert metric_type to type", function(){
// Make our api call
metric.send("metrics.send.counter", 5, {metric_type: "counter"});
// Assert we called `client.request` with the correct `points`
assert(stub_request.calledOnce);
var call_args = stub_request.getCall(0).args;
// { body: series: [ {points: [], }, ] }
var body = call_args[2].body;
assert.equal(body.series.length, 1);
// Assert we have only 1 series
// series = [ {metric: "", ...}, ... ]
var series = body.series;
assert(Array.isArray(series));
assert.equal(series.length, 1);
// Assert the first series is properly formatted
// first_series = {metric: "", type: "counter", points: [], ...}
var first_series = series[0]
assert.equal(first_series.metric, "metrics.send.counter");
assert(first_series.hasOwnProperty("type"));
assert.equal(first_series.type, "counter");
});
});

@@ -159,4 +210,4 @@

// Properly formatted body
// { body: series: [ {metric: "metric.send_all", host: undefined, tags: undefined, metric_type: undefined} ] }
// DEV: host/tags/metric_type are optional and should be undefined for this case
// { body: series: [ {metric: "metric.send_all", host: undefined, tags: undefined, type: undefined} ] }
// DEV: host/tags/type are optional and should be undefined for this case
var data = call_args[2];

@@ -229,3 +280,81 @@ assert(data.hasOwnProperty("body"));

});
it("should properly send metric type", function(){
// Make our api call
var metrics = [
{
metric: "metric.send.counter",
points: 5,
type: "counter"
}
];
metric.send_all(metrics);
// Assert we properly called `client.request`
assert(stub_request.calledOnce);
var call_args = stub_request.getCall(0).args;
// Method and endpoint are correct
assert.equal(call_args[0], "POST");
assert.equal(call_args[1], "/series");
// Properly formatted body
// { body: series: [ {metric: "metric.send.counter", host: undefined, tags: undefined, type: "counter"} ] }
// DEV: host/tags are optional and should be undefined for this case
var data = call_args[2];
assert(data.hasOwnProperty("body"));
assert(data.body.hasOwnProperty("series"));
// Assert we have only 1 series
// series = [ {metric: "", ...}, ... ]
var series = data.body.series;
assert(Array.isArray(series));
assert.equal(series.length, 1);
// Assert the first series is properly formatted
// first_series = {metric: "", type: "counter", points: [], ...}
var first_series = series[0]
assert.equal(first_series.metric, "metric.send.counter");
assert(Array.isArray(first_series.points));
assert.deepEqual(first_series.type, "counter");
});
it("should properly send metric_type as type", function(){
// Make our api call
var metrics = [
{
metric: "metric.send.counter",
points: 5,
metric_type: "counter"
}
];
metric.send_all(metrics);
// Assert we properly called `client.request`
assert(stub_request.calledOnce);
var call_args = stub_request.getCall(0).args;
// Method and endpoint are correct
assert.equal(call_args[0], "POST");
assert.equal(call_args[1], "/series");
// Properly formatted body
// { body: series: [ {metric: "metric.send.counter", host: undefined, tags: undefined, type: "counter"} ] }
// DEV: host/tags are optional and should be undefined for this case
var data = call_args[2];
assert(data.hasOwnProperty("body"));
assert(data.body.hasOwnProperty("series"));
// Assert we have only 1 series
// series = [ {metric: "", ...}, ... ]
var series = data.body.series;
assert(Array.isArray(series));
assert.equal(series.length, 1);
// Assert the first series is properly formatted
// first_series = {metric: "", type: "counter", points: [], ...}
var first_series = series[0]
assert.equal(first_series.metric, "metric.send.counter");
assert(Array.isArray(first_series.points));
assert.deepEqual(first_series.type, "counter");
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc