Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump aws-sdk to v3 #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6,771 changes: 4,477 additions & 2,294 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aws-embedded-metrics",
"version": "2.0.4",
"version": "3.0.0",
"description": "AWS Embedded Metrics Client Library",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -37,7 +37,7 @@
"@types/node": "^12.0.8",
"@typescript-eslint/eslint-plugin": "^2.23.0",
"@typescript-eslint/parser": "^2.23.0",
"aws-sdk": "^2.551.0",
"@aws-sdk/client-cloudwatch": "^3.42.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
Expand Down
12 changes: 6 additions & 6 deletions src/logger/MetricsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ export class MetricsContext {
dimensions?: Array<Record<string, string>>,
defaultDimensions?: Record<string, string>,
shouldUseDefaultDimensions?: boolean,
timestamp?: Date | number
timestamp?: Date | number,
) {
this.namespace = namespace || Configuration.namespace
this.namespace = namespace || Configuration.namespace;
this.properties = properties || {};
this.dimensions = dimensions || [];
this.timestamp = timestamp;
this.meta.Timestamp = MetricsContext.resolveMetaTimestamp(timestamp);
this.defaultDimensions = defaultDimensions || {};
if (shouldUseDefaultDimensions != undefined) {
this.shouldUseDefaultDimensions = shouldUseDefaultDimensions
this.shouldUseDefaultDimensions = shouldUseDefaultDimensions;
}
}

private static resolveMetaTimestamp(timestamp?: Date | number): number {
if (timestamp instanceof Date) {
return timestamp.getTime()
return timestamp.getTime();
} else if (timestamp) {
return timestamp;
} else {
Expand All @@ -89,7 +89,7 @@ export class MetricsContext {
this.properties[key] = value;
}

public setTimestamp(timestamp: Date | number) {
public setTimestamp(timestamp: Date | number): void {
this.timestamp = timestamp;
this.meta.Timestamp = MetricsContext.resolveMetaTimestamp(timestamp);
}
Expand Down Expand Up @@ -196,7 +196,7 @@ export class MetricsContext {
Object.assign([], this.dimensions),
this.defaultDimensions,
this.shouldUseDefaultDimensions,
this.timestamp
this.timestamp,
);
}
}
2 changes: 1 addition & 1 deletion src/logger/__tests__/MetricsContext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,5 @@ test('createCopyWithContext copies shouldUseDefaultDimensions', () => {

// assert
expect(newContext).not.toBe(context);
expect(newContext.getDimensions()).toEqual([])
expect(newContext.getDimensions()).toEqual([]);
});
8 changes: 4 additions & 4 deletions src/logger/__tests__/MetricsLogger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ describe('successful', () => {
test('can set timestamp', async () => {
// arrange
const timestamp = faker.date.recent();
logger.setTimestamp(timestamp)
logger.setTimestamp(timestamp);

// act
logger.putMetric(faker.random.word(), faker.random.number());
Expand All @@ -235,7 +235,7 @@ describe('successful', () => {
test('flush() preserves timestamp if set explicitly', async () => {
// arrange
const timestamp = faker.date.recent();
logger.setTimestamp(timestamp)
logger.setTimestamp(timestamp);

// act
logger.putMetric(faker.random.word(), faker.random.number());
Expand Down Expand Up @@ -384,7 +384,7 @@ describe('successful', () => {
const expectTimestampWithin = (context: MetricsContext, range: [Date, Date]) => {
expect(context.meta.Timestamp).toBeGreaterThanOrEqual(range[0].getTime());
expect(context.meta.Timestamp).toBeLessThanOrEqual(range[1].getTime());
}
};
});

describe('failure', () => {
Expand All @@ -398,4 +398,4 @@ describe('failure', () => {
// assert
await expect(logger.flush()).rejects.toBeUndefined();
});
});
});
2 changes: 1 addition & 1 deletion src/sinks/AgentSink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class AgentSink implements ISink {
}

const events = this.serializer.serialize(context);

LOG(`Sending {} events to socket.`, events.length);

for (let index = 0; index < events.length; index++) {
Expand Down
8 changes: 4 additions & 4 deletions test/integ/agent/end-to-end.integ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { metricScope } from '../../../src/logger/MetricScope';
import Sleep from '../../utils/Sleep';
import Configuration from '../../../src/config/Configuration';
import os = require('os');
import CloudWatch = require('aws-sdk/clients/cloudwatch');
const cwmClient = new CloudWatch();
import CloudWatch = require('@aws-sdk/client-cloudwatch');
const cwmClient = new CloudWatch.CloudWatchClient({});

const now = () => new Date().getTime();
const startTime = new Date();
Expand Down Expand Up @@ -75,7 +75,7 @@ doWork();


const metricExists = async (metricName: string, expectedSampleCount: number): Promise<boolean> => {
const request = {
const request: CloudWatch.GetMetricStatisticsCommandInput = {
Namespace: 'aws-embedded-metrics',
MetricName: metricName,
Dimensions: [
Expand All @@ -90,7 +90,7 @@ const metricExists = async (metricName: string, expectedSampleCount: number): Pr
Statistics: ['SampleCount'],
};

const result = await cwmClient.getMetricStatistics(request).promise();
const result = await cwmClient.send(new CloudWatch.GetMetricStatisticsCommand(request));

if (result && result.Datapoints && result.Datapoints.length > 0) {
const samples = result.Datapoints.map(dataPoint => dataPoint.SampleCount || 0).reduce((total, i) => total + i);
Expand Down