Socket
Socket
Sign inDemoInstall

cloudwatch-metrics

Package Overview
Dependencies
142
Maintainers
33
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.0 to 1.3.2

.github/workflows/ci.yml

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);
});
});
});
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc