cloudwatch-metrics
Advanced tools
Comparing version 1.3.0 to 1.3.2
30
index.js
@@ -82,3 +82,3 @@ /** | ||
var CloudWatch = require('aws-sdk/clients/cloudwatch'); | ||
var { CloudWatchClient, PutMetricDataCommand }= require('@aws-sdk/client-cloudwatch'); | ||
const SummarySet = require('./src/summarySet'); | ||
@@ -113,4 +113,4 @@ | ||
* customized metricName and units. Each CloudWatchMetric object has it's own internal | ||
* AWS.CloudWatch object to prevent errors due to overlapping callings to | ||
* AWS.CloudWatch#putMetricData. | ||
* CloudWatchClient object to prevent errors due to overlapping callings to | ||
* CloudWatchClient#send. | ||
* | ||
@@ -129,3 +129,3 @@ * @param {String} namespace CloudWatch namespace | ||
var self = this; | ||
self.cloudwatch = new CloudWatch(_awsConfig); | ||
self.cloudwatch = new CloudWatchClient(_awsConfig); | ||
self.namespace = namespace; | ||
@@ -139,7 +139,7 @@ self.units = units; | ||
if (self.options.enabled) { | ||
self._interval = setInterval(() => { | ||
self._interval = global.setInterval(() => { | ||
self._sendMetrics(); | ||
}, self.options.sendInterval); | ||
this._summaryInterval = setInterval(() => { | ||
this._summaryInterval = global.setInterval(() => { | ||
this._summarizeMetrics(); | ||
@@ -193,5 +193,5 @@ }, this.options.summaryInterval); | ||
if (self._storedMetrics.length === self.options.maxCapacity) { | ||
clearInterval(self._interval); | ||
global.clearInterval(self._interval); | ||
self._sendMetrics(); | ||
self._interval = setInterval(() => { | ||
self._interval = global.setInterval(() => { | ||
self._sendMetrics(); | ||
@@ -283,7 +283,6 @@ }, self.options.sendInterval); | ||
if (!dataPoints || !dataPoints.length) return; | ||
self.cloudwatch.putMetricData({ | ||
self.cloudwatch.send(new PutMetricDataCommand({ | ||
MetricData: dataPoints, | ||
Namespace: self.namespace | ||
}, self.options.sendCallback); | ||
}), self.options.sendCallback); | ||
}; | ||
@@ -295,4 +294,7 @@ | ||
Metric.prototype.shutdown = function() { | ||
clearInterval(this._interval); | ||
global.clearInterval(this._interval); | ||
global.clearInterval(this._summaryInterval); | ||
this._sendMetrics(); | ||
this._summarizeMetrics(); | ||
}; | ||
@@ -344,6 +346,6 @@ | ||
Metric.prototype._putSummaryMetrics = function(MetricData) { | ||
this.cloudwatch.putMetricData({ | ||
this.cloudwatch.send(new PutMetricDataCommand({ | ||
MetricData, | ||
Namespace: this.namespace, | ||
}, this.options.sendCallback); | ||
}), this.options.sendCallback); | ||
}; | ||
@@ -350,0 +352,0 @@ |
{ | ||
"name": "cloudwatch-metrics", | ||
"version": "1.3.0", | ||
"version": "1.3.2", | ||
"description": "A simple wrapper for simplifying using Cloudwatch metrics", | ||
@@ -27,3 +27,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"aws-sdk": "^2.412.0" | ||
"@aws-sdk/client-cloudwatch": "^3.332.0" | ||
}, | ||
@@ -33,3 +33,3 @@ "devDependencies": { | ||
"eslint-config-mixmax": "^0.6.0", | ||
"jasmine": "^2.5.2", | ||
"jasmine": "^2.99.0", | ||
"pre-commit": "^1.2.2", | ||
@@ -36,0 +36,0 @@ "rewire": "^2.5.2", |
@@ -140,1 +140,7 @@ ## cloudwatch-metrics | ||
``` | ||
## Publishing a new version | ||
``` | ||
GH_TOKEN=xxx npx semantic-release --no-ci | ||
``` |
@@ -1,2 +0,2 @@ | ||
/* globals describe, afterEach, it, expect, spyOn, jasmine */ | ||
/* globals describe, beforeEach, afterEach, it, expect, spyOn, jasmine */ | ||
@@ -9,7 +9,7 @@ var _ = require('underscore'); | ||
describe('cloudwatch-metrics', function() { | ||
var restoreAWS; | ||
var restoreAWS, metric; | ||
function attachHook(hook) { | ||
restoreAWS = cloudwatchMetric.__set__('CloudWatch', function() { | ||
this.putMetricData = hook; | ||
restoreAWS = cloudwatchMetric.__set__('CloudWatchClient', function() { | ||
this.send = hook; | ||
}); | ||
@@ -23,2 +23,6 @@ } | ||
} | ||
if (metric) { | ||
metric.shutdown(); | ||
} | ||
}); | ||
@@ -29,3 +33,3 @@ | ||
attachHook(function(data, cb) { | ||
expect(data).toEqual({ | ||
expect(data).toEqual(jasmine.objectContaining({input: { | ||
MetricData: [{ | ||
@@ -44,7 +48,7 @@ Dimensions: [{ | ||
Namespace: 'namespace' | ||
}); | ||
}})); | ||
cb(); | ||
}); | ||
var metric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
metric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
Name: 'environment', | ||
@@ -62,3 +66,3 @@ Value: 'PROD' | ||
attachHook(function(data, cb) { | ||
expect(data).toEqual({ | ||
expect(data).toEqual(jasmine.objectContaining({input: { | ||
MetricData: [{ | ||
@@ -77,7 +81,7 @@ Dimensions: [{ | ||
Namespace: 'namespace' | ||
}); | ||
}})); | ||
cb(); | ||
}); | ||
var metric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
metric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
Name: 'environment', | ||
@@ -100,3 +104,3 @@ Value: 'PROD' | ||
attachHook(function(data, cb) { | ||
expect(data).toEqual({ | ||
expect(data).toEqual(jasmine.objectContaining({input: { | ||
MetricData: [{ | ||
@@ -126,7 +130,7 @@ Dimensions: [{ | ||
Namespace: 'namespace' | ||
}); | ||
}})); | ||
cb(); | ||
}); | ||
var metric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
metric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
Name: 'environment', | ||
@@ -148,3 +152,3 @@ Value: 'PROD' | ||
attachHook(function(data, cb) { | ||
expect(data).toEqual({ | ||
expect(data).toEqual(jasmine.objectContaining({input: { | ||
MetricData: [{ | ||
@@ -164,8 +168,8 @@ Dimensions: [{ | ||
Namespace: 'namespace' | ||
}); | ||
expect(Date.parse(data.MetricData[0].Timestamp)).toBeLessThanOrEqual(Date.now()); | ||
}})); | ||
expect(Date.parse(data.input.MetricData[0].Timestamp)).toBeLessThanOrEqual(Date.now()); | ||
cb(); | ||
}); | ||
var metric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
metric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
Name: 'environment', | ||
@@ -186,3 +190,3 @@ Value: 'PROD' | ||
attachHook(function(data, cb) { | ||
expect(data).toEqual({ | ||
expect(data).toEqual(jasmine.objectContaining({input: { | ||
MetricData: [{ | ||
@@ -202,7 +206,7 @@ Dimensions: [{ | ||
Namespace: 'namespace' | ||
}); | ||
}})); | ||
cb(); | ||
}); | ||
var metric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
metric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
Name: 'environment', | ||
@@ -223,3 +227,3 @@ Value: 'PROD' | ||
attachHook(function (data, cb) { | ||
expect(data).toEqual({ | ||
expect(data).toEqual(jasmine.objectContaining({input: { | ||
MetricData: [{ | ||
@@ -238,3 +242,3 @@ Dimensions: [{ | ||
Namespace: 'namespace' | ||
}); | ||
}})); | ||
cb(); | ||
@@ -257,3 +261,3 @@ }); | ||
it('should ignore metrics when not in the sample range', function() { | ||
var metric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
metric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
Name: 'environment', | ||
@@ -271,3 +275,3 @@ Value: 'PROD' | ||
it('should call put when the we decide to sample a metric', function() { | ||
var metric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
metric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
Name: 'environment', | ||
@@ -292,3 +296,3 @@ Value: 'PROD' | ||
const metric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
metric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
Name: 'environment', | ||
@@ -315,3 +319,3 @@ Value: 'PROD', | ||
++hookCalls; | ||
expect(data).toEqual({ | ||
expect(data).toEqual(jasmine.objectContaining({input: { | ||
MetricData: [{ | ||
@@ -367,7 +371,7 @@ Dimensions: [{ | ||
Namespace: 'namespace' | ||
}); | ||
}})); | ||
cb(); | ||
}); | ||
const metric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
metric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
Name: 'environment', | ||
@@ -395,3 +399,3 @@ Value: 'PROD', | ||
++hookCalls; | ||
expect(data).toEqual({ | ||
expect(data).toEqual(jasmine.objectContaining({input: { | ||
MetricData: [{ | ||
@@ -431,7 +435,7 @@ Dimensions: [{ | ||
Namespace: 'namespace' | ||
}); | ||
}})); | ||
cb(); | ||
}); | ||
const metric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
metric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
Name: 'environment', | ||
@@ -456,2 +460,43 @@ Value: 'PROD', | ||
}); | ||
describe('shutdown', function () { | ||
let setIntervalSpy, clearIntervalSpy; | ||
beforeEach(function () { | ||
setIntervalSpy = jasmine.createSpy('setInterval'); | ||
clearIntervalSpy = jasmine.createSpy('clearInterval'); | ||
spyOn(global, 'setInterval').and.callFake(setIntervalSpy); | ||
spyOn(global, 'clearInterval').and.callFake(clearIntervalSpy); | ||
}); | ||
afterEach(function () { | ||
setIntervalSpy.calls.reset(); | ||
clearIntervalSpy.calls.reset(); | ||
}); | ||
it('clears all timers and sends remaining metrics', function() { | ||
const sent = jasmine.createSpy('sent'); | ||
attachHook(sent); | ||
const scopedMetric = new cloudwatchMetric.Metric('namespace', 'Count', [{ | ||
Name: 'environment', | ||
Value: 'PROD' | ||
}], { | ||
sendInterval: 1000, | ||
summaryInterval: 1000, | ||
enabled: true | ||
}); | ||
expect(setIntervalSpy).toHaveBeenCalledTimes(2); | ||
scopedMetric.put(1, 'metricName', [{ Name:'ExtraDimension', Value: 'Value'}]); | ||
scopedMetric.summaryPut(10, 'summaryMetric', [{ Name: 'ExtraDimension', Value: 'Value'}]); | ||
expect(sent).not.toHaveBeenCalled(); | ||
scopedMetric.shutdown(); | ||
expect(sent).toHaveBeenCalledTimes(2); | ||
expect(clearIntervalSpy).toHaveBeenCalledTimes(2); | ||
}); | ||
}); | ||
}); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
35789
13
836
145
1
+ Added@aws-crypto/ie11-detection@3.0.0(transitive)
+ Added@aws-crypto/sha256-browser@3.0.0(transitive)
+ Added@aws-crypto/sha256-js@3.0.0(transitive)
+ Added@aws-crypto/supports-web-crypto@3.0.0(transitive)
+ Added@aws-crypto/util@3.0.0(transitive)
+ Added@aws-sdk/client-cloudwatch@3.590.0(transitive)
+ Added@aws-sdk/client-sso@3.590.0(transitive)
+ Added@aws-sdk/client-sso-oidc@3.590.0(transitive)
+ Added@aws-sdk/client-sts@3.590.0(transitive)
+ Added@aws-sdk/core@3.588.0(transitive)
+ Added@aws-sdk/credential-provider-env@3.587.0(transitive)
+ Added@aws-sdk/credential-provider-http@3.587.0(transitive)
+ Added@aws-sdk/credential-provider-ini@3.590.0(transitive)
+ Added@aws-sdk/credential-provider-node@3.590.0(transitive)
+ Added@aws-sdk/credential-provider-process@3.587.0(transitive)
+ Added@aws-sdk/credential-provider-sso@3.590.0(transitive)
+ Added@aws-sdk/credential-provider-web-identity@3.587.0(transitive)
+ Added@aws-sdk/middleware-host-header@3.577.0(transitive)
+ Added@aws-sdk/middleware-logger@3.577.0(transitive)
+ Added@aws-sdk/middleware-recursion-detection@3.577.0(transitive)
+ Added@aws-sdk/middleware-user-agent@3.587.0(transitive)
+ Added@aws-sdk/region-config-resolver@3.587.0(transitive)
+ Added@aws-sdk/token-providers@3.587.0(transitive)
+ Added@aws-sdk/types@3.577.0(transitive)
+ Added@aws-sdk/util-endpoints@3.587.0(transitive)
+ Added@aws-sdk/util-locate-window@3.568.0(transitive)
+ Added@aws-sdk/util-user-agent-browser@3.577.0(transitive)
+ Added@aws-sdk/util-user-agent-node@3.587.0(transitive)
+ Added@aws-sdk/util-utf8-browser@3.259.0(transitive)
+ Added@smithy/abort-controller@3.0.0(transitive)
+ Added@smithy/config-resolver@3.0.1(transitive)
+ Added@smithy/core@2.2.0(transitive)
+ Added@smithy/credential-provider-imds@3.1.0(transitive)
+ Added@smithy/fetch-http-handler@3.0.1(transitive)
+ Added@smithy/hash-node@3.0.0(transitive)
+ Added@smithy/invalid-dependency@3.0.0(transitive)
+ Added@smithy/is-array-buffer@3.0.0(transitive)
+ Added@smithy/middleware-compression@3.0.1(transitive)
+ Added@smithy/middleware-content-length@3.0.0(transitive)
+ Added@smithy/middleware-endpoint@3.0.1(transitive)
+ Added@smithy/middleware-retry@3.0.3(transitive)
+ Added@smithy/middleware-serde@3.0.0(transitive)
+ Added@smithy/middleware-stack@3.0.0(transitive)
+ Added@smithy/node-config-provider@3.1.0(transitive)
+ Added@smithy/node-http-handler@3.0.0(transitive)
+ Added@smithy/property-provider@3.1.0(transitive)
+ Added@smithy/protocol-http@4.0.0(transitive)
+ Added@smithy/querystring-builder@3.0.0(transitive)
+ Added@smithy/querystring-parser@3.0.0(transitive)
+ Added@smithy/service-error-classification@3.0.0(transitive)
+ Added@smithy/shared-ini-file-loader@3.1.0(transitive)
+ Added@smithy/signature-v4@3.0.0(transitive)
+ Added@smithy/smithy-client@3.1.1(transitive)
+ Added@smithy/types@3.0.0(transitive)
+ Added@smithy/url-parser@3.0.0(transitive)
+ Added@smithy/util-base64@3.0.0(transitive)
+ Added@smithy/util-body-length-browser@3.0.0(transitive)
+ Added@smithy/util-body-length-node@3.0.0(transitive)
+ Added@smithy/util-buffer-from@3.0.0(transitive)
+ Added@smithy/util-config-provider@3.0.0(transitive)
+ Added@smithy/util-defaults-mode-browser@3.0.3(transitive)
+ Added@smithy/util-defaults-mode-node@3.0.3(transitive)
+ Added@smithy/util-endpoints@2.0.1(transitive)
+ Added@smithy/util-hex-encoding@3.0.0(transitive)
+ Added@smithy/util-middleware@3.0.0(transitive)
+ Added@smithy/util-retry@3.0.0(transitive)
+ Added@smithy/util-stream@3.0.1(transitive)
+ Added@smithy/util-uri-escape@3.0.0(transitive)
+ Added@smithy/util-utf8@3.0.0(transitive)
+ Added@smithy/util-waiter@3.0.0(transitive)
+ Addedbowser@2.11.0(transitive)
+ Addedfast-xml-parser@4.2.5(transitive)
+ Addedfflate@0.8.1(transitive)
+ Addedstrnum@1.0.5(transitive)
+ Addedtslib@1.14.12.6.3(transitive)
+ Addeduuid@9.0.1(transitive)
- Removedaws-sdk@^2.412.0
- Removedavailable-typed-arrays@1.0.7(transitive)
- Removedaws-sdk@2.1635.0(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedbuffer@4.9.2(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedevents@1.1.1(transitive)
- Removedfor-each@0.3.3(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedhasown@2.0.2(transitive)
- Removedieee754@1.1.13(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-arguments@1.1.1(transitive)
- Removedis-callable@1.2.7(transitive)
- Removedis-generator-function@1.0.10(transitive)
- Removedis-typed-array@1.1.13(transitive)
- Removedisarray@1.0.0(transitive)
- Removedjmespath@0.16.0(transitive)
- Removedpossible-typed-array-names@1.0.0(transitive)
- Removedpunycode@1.3.2(transitive)
- Removedquerystring@0.2.0(transitive)
- Removedsax@1.2.1(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedurl@0.10.3(transitive)
- Removedutil@0.12.5(transitive)
- Removeduuid@8.0.0(transitive)
- Removedwhich-typed-array@1.1.15(transitive)
- Removedxml2js@0.6.2(transitive)
- Removedxmlbuilder@11.0.1(transitive)