Skip to content

Commit 3a5af62

Browse files
author
Mark Kuhn
authored
Move buildspecs to S3 bucket (#133)
* rm buildspecs * style improvements
1 parent 5e89620 commit 3a5af62

File tree

12 files changed

+73
-142
lines changed

12 files changed

+73
-142
lines changed

buildspecs/buildspec.canary.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

buildspecs/buildspec.release.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

buildspecs/buildspec.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

examples/lambda/src/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
const { metricScope } = require("aws-embedded-metrics");
1+
const { metricScope } = require('aws-embedded-metrics');
22

33
const aggregator = metricScope(metrics => async event => {
4-
console.log("received message");
5-
metrics.putDimensions({ Service: "Aggregator" });
6-
metrics.putMetric("ProcessingLatency", 100, "Milliseconds");
7-
metrics.setProperty("AccountId", "123456789012");
8-
metrics.setProperty("RequestId", "422b1569-16f6-4a03-b8f0-fe3fd9b100f8");
9-
metrics.setProperty("DeviceId", "61270781-c6ac-46f1-baf7-22c808af8162");
10-
metrics.setProperty("Payload", {
4+
console.log('received message');
5+
metrics.putDimensions({ Service: 'Aggregator' });
6+
metrics.putMetric('ProcessingLatency', 100, 'Milliseconds');
7+
metrics.setProperty('AccountId', '123456789012');
8+
metrics.setProperty('RequestId', '422b1569-16f6-4a03-b8f0-fe3fd9b100f8');
9+
metrics.setProperty('DeviceId', '61270781-c6ac-46f1-baf7-22c808af8162');
10+
metrics.setProperty('Payload', {
1111
sampleTime: 123456789,
1212
temperature: 273.0,
13-
pressure: 101.3
13+
pressure: 101.3,
1414
});
15-
console.log("completed aggregation successfully.");
15+
console.log('completed aggregation successfully.');
1616
});
1717

1818
exports.handler = aggregator;

examples/testing/src/module.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
const { metricScope, createMetricsLogger, Unit } = require("aws-embedded-metrics");
1+
const { metricScope, createMetricsLogger, Unit } = require('aws-embedded-metrics');
22

3-
const usingScope = metricScope(metrics =>
4-
async (event, ctx) => {
5-
metrics.putDimensions({ Service: "Aggregator" });
6-
metrics.putMetric("EventCount", event.count, Unit.Count);
7-
metrics.setProperty("AccountId", event.accountId);
8-
metrics.setProperty("RequestId", ctx.requestId);
9-
});
3+
const usingScope = metricScope(metrics => async (event, ctx) => {
4+
metrics.putDimensions({ Service: 'Aggregator' });
5+
metrics.putMetric('EventCount', event.count, Unit.Count);
6+
metrics.setProperty('AccountId', event.accountId);
7+
metrics.setProperty('RequestId', ctx.requestId);
8+
});
109

1110
const usingCreateLogger = async (event, ctx) => {
12-
const metrics = createMetricsLogger();
13-
metrics.putDimensions({ Service: "Aggregator" });
14-
metrics.putMetric("EventCount", event.count, Unit.Count);
15-
metrics.setProperty("AccountId", event.accountId);
16-
metrics.setProperty("RequestId", ctx.requestId);
17-
await metrics.flush();
11+
const metrics = createMetricsLogger();
12+
metrics.putDimensions({ Service: 'Aggregator' });
13+
metrics.putMetric('EventCount', event.count, Unit.Count);
14+
metrics.setProperty('AccountId', event.accountId);
15+
metrics.setProperty('RequestId', ctx.requestId);
16+
await metrics.flush();
1817
};
19-
18+
2019
module.exports = { usingScope, usingCreateLogger };

examples/testing/tests/module.local.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
// set the environment override to Local which just logs to stdout
88
// this needs to be done prior to importing any modules
9-
// because environment detection starts as soon as the
9+
// because environment detection starts as soon as the
1010
// aws-embedded-metrics module is loaded
1111
process.env.AWS_EMF_ENVIRONMENT = 'Local';
1212

@@ -24,4 +24,4 @@ test('usingScope test', async () => {
2424

2525
// assert
2626
// I don't have anything I need to assert...
27-
});
27+
});

src/environment/EC2Environment.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ export class EC2Environment implements IEnvironment {
4949
const options: RequestOptions = {
5050
host,
5151
path: tokenPath,
52-
method: "PUT",
53-
headers: {[tokenRequestHeaderKey]: tokenRequestHeaderValue}
54-
}
52+
method: 'PUT',
53+
headers: { [tokenRequestHeaderKey]: tokenRequestHeaderValue },
54+
};
5555
this.token = await fetchString(options);
5656
} catch (e) {
5757
LOG(e);
@@ -62,9 +62,9 @@ export class EC2Environment implements IEnvironment {
6262
const metadataOptions: RequestOptions = {
6363
host,
6464
path: metadataPath,
65-
method: "GET",
66-
headers: {[metadataRequestTokenHeaderKey]: this.token}
67-
}
65+
method: 'GET',
66+
headers: { [metadataRequestTokenHeaderKey]: this.token },
67+
};
6868
this.metadata = await fetchJSON<IEC2MetadataResponse>(metadataOptions);
6969
return !!this.metadata;
7070
} catch (e) {

src/logger/MetricsLoggerFactory.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ import { MetricsContext } from './MetricsContext';
1919

2020
const createMetricsLogger = (): MetricsLogger => {
2121
const context = MetricsContext.empty();
22-
const logger = new MetricsLogger(resolveEnvironment, context);
23-
return logger;
22+
return new MetricsLogger(resolveEnvironment, context);
2423
};
2524

2625
export { createMetricsLogger };

src/sinks/connections/TcpClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class TcpClient implements ISocketClient {
3232
.on('end', () => this.disconnect('end'))
3333
.on('data', data => LOG('TcpClient received data.', data));
3434

35-
// Used to create an initial connection on the socket right after creation to avoid socket failures.
35+
// Used to create an initial connection on the socket right after creation to avoid socket failures.
3636
this.initialConnect.apply(this);
3737
}
3838

src/utils/Fetch.ts

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,32 @@ const SOCKET_TIMEOUT = 1000;
2525
const fetch = (options: RequestOptions): Promise<Buffer> => {
2626
return new Promise<Buffer>((resolve, reject) => {
2727
const request = httpRequest(options, (response: IncomingMessage) => {
28-
if (!response.statusCode) {
29-
reject(`Received undefined response status code from '${options.host}${options.path}'`);
30-
return;
31-
}
28+
if (!response.statusCode) {
29+
reject(`Received undefined response status code from '${options.host}${options.path}'`);
30+
return;
31+
}
3232

33-
if (response.statusCode < 200 || response.statusCode > 299) {
34-
reject(new Error('Failed to load page, status code: ' + response.statusCode));
35-
return;
36-
}
33+
if (response.statusCode < 200 || response.statusCode > 299) {
34+
reject(new Error('Failed to load page, status code: ' + response.statusCode));
35+
return;
36+
}
3737

38-
// using similar approach to node-fetch
39-
// https://github.com/bitinn/node-fetch/blob/6a5d192034a0f438551dffb6d2d8df2c00921d16/src/body.js#L217
40-
const body: Uint8Array[] = [];
41-
let bodyBytes = 0;
42-
response.on('data', (chunk: Uint8Array) => {
43-
bodyBytes += chunk.length;
44-
body.push(chunk);
45-
});
38+
// using similar approach to node-fetch
39+
// https://github.com/bitinn/node-fetch/blob/6a5d192034a0f438551dffb6d2d8df2c00921d16/src/body.js#L217
40+
const body: Uint8Array[] = [];
41+
let bodyBytes = 0;
42+
response.on('data', (chunk: Uint8Array) => {
43+
bodyBytes += chunk.length;
44+
body.push(chunk);
45+
});
4646

47-
response.on('end', () => {
48-
const buffer: Buffer = Buffer.concat(body, bodyBytes);
49-
resolve(buffer)
50-
});
51-
})
52-
.on('error', (err: unknown) => {
53-
reject(err);
47+
response.on('end', () => {
48+
const buffer: Buffer = Buffer.concat(body, bodyBytes);
49+
resolve(buffer);
5450
});
51+
}).on('error', (err: unknown) => {
52+
reject(err);
53+
});
5554

5655
request.on('socket', socket => {
5756
socket.on('timeout', () => {
@@ -62,8 +61,8 @@ const fetch = (options: RequestOptions): Promise<Buffer> => {
6261
});
6362

6463
request.end();
65-
})
66-
}
64+
});
65+
};
6766

6867
/**
6968
* Fetch a string from a remote HTTP endpoint with the provided headers.
@@ -73,7 +72,7 @@ const fetch = (options: RequestOptions): Promise<Buffer> => {
7372
const fetchString = async (options: RequestOptions): Promise<string> => {
7473
const buffer = await fetch(options);
7574
return buffer.toString();
76-
}
75+
};
7776

7877
/**
7978
* Fetch JSON data from a remote HTTP endpoint with the provided headers and de-serialize to the provided type.
@@ -84,8 +83,8 @@ const fetchString = async (options: RequestOptions): Promise<string> => {
8483
* @param options - HTTP request options
8584
*/
8685
const fetchJSON = async <T>(options: RequestOptions): Promise<T> => {
87-
const responseString = await fetchString(options)
86+
const responseString = await fetchString(options);
8887
return JSON.parse(responseString);
89-
}
88+
};
9089

9190
export { fetch, fetchJSON, fetchString };

test/integ/agent/end-to-end.integ.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,24 @@ test(
5555

5656
Configuration.agentEndpoint = 'tcp://0.0.0.0:25888';
5757

58-
const doWork = metricScope(metrics => () => {
59-
metrics.putDimensions(dimensions);
60-
metrics.putMetric(metricName, 100, 'Milliseconds');
61-
metrics.setProperty('RequestId', '422b1569-16f6-4a03-b8f0-fe3fd9b100f8');
62-
});
63-
64-
// act
65-
doWork();
66-
doWork();
67-
await Sleep(idleTimeout);
68-
doWork();
58+
const doWork = metricScope(metrics => () => {
59+
metrics.putDimensions(dimensions);
60+
metrics.putMetric(metricName, 100, 'Milliseconds');
61+
metrics.setProperty('RequestId', '422b1569-16f6-4a03-b8f0-fe3fd9b100f8');
62+
});
63+
64+
// act
65+
doWork();
66+
doWork();
67+
await Sleep(idleTimeout);
68+
doWork();
6969

7070
// assert
7171
await waitForMetricExistence(metricName, expectedSamples);
7272
},
7373
timeoutMillis,
7474
);
7575

76-
7776
const metricExists = async (metricName: string, expectedSampleCount: number): Promise<boolean> => {
7877
const request = {
7978
Namespace: 'aws-embedded-metrics',

test/utils/TestSink.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ export class TestSink implements ISink {
3333

3434
public accept(context: MetricsContext): Promise<void> {
3535
this.events.push(context);
36-
return this.forceAcceptRejects ? Promise.reject(): Promise.resolve();
36+
return this.forceAcceptRejects ? Promise.reject() : Promise.resolve();
3737
}
3838
}

0 commit comments

Comments
 (0)