Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Set aws.lambda.invocation.memory_usage in MB
Browse files Browse the repository at this point in the history
  • Loading branch information
İbrahim Gürses committed Dec 13, 2018
1 parent 290900d commit ea90c3e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/plugins/Invocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Invocation {
this.invocationData.tags['aws.lambda.log_stream_name'] = originalContext.logStreamName;
this.invocationData.tags['aws.lambda.invocation.request_id'] = originalContext.awsRequestId;
const { heapUsed } = process.memoryUsage();
this.invocationData.tags['aws.lambda.invocation.memory_usage'] = heapUsed;
this.invocationData.tags['aws.lambda.invocation.memory_usage'] = Math.floor(heapUsed / (1024 * 1024));
}

afterInvocation = (data: any) => {
Expand Down
8 changes: 6 additions & 2 deletions test/plugins/invocation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ describe('Invocation', () => {
const invocation = Invocation();
invocation.setPluginContext(pluginContext);
const beforeInvocationData = createMockBeforeInvocationData();
process.memoryUsage = jest.fn(() => {
return {
heapUsed: 39845888
};
});
it('Should set variables to their initial value', async () => {
await invocation.beforeInvocation(beforeInvocationData);
invocation.invocationData.tags['aws.lambda.invocation.memory_usage'] = 100;
expect(invocation.reporter).toBe(beforeInvocationData.reporter);
expect(invocation.apiKey).toBe(pluginContext.apiKey);
expect(invocation.invocationData.id).toBeTruthy();
Expand Down Expand Up @@ -86,7 +90,7 @@ describe('Invocation', () => {
'aws.lambda.memory_limit': 512,
'aws.lambda.name': 'test',
'aws.region': 'region',
'aws.lambda.invocation.memory_usage': 100,
'aws.lambda.invocation.memory_usage': 38,
'aws.lambda.invocation.request_id': 'awsRequestId',});
});
});
Expand Down

0 comments on commit ea90c3e

Please sign in to comment.