Skip to content

Commit

Permalink
fix(uploads): fix buffer that is sent to s3 (#60)
Browse files Browse the repository at this point in the history
fix #59
  • Loading branch information
coreylight authored Jul 27, 2018
1 parent f59c22d commit 90e24f2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 12 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,15 @@ class ProfilerPlugin {

getFileUploadMeta() {
// returns a promise here
const {
invokedFunctionArn: arn,
awsRequestId: requestId
} = this.invocationInstance.context;

return coreUtil.getFileUploadMeta({
auth: this.token
auth: this.token,
arn,
requestId
});
}

Expand All @@ -122,7 +129,9 @@ class ProfilerPlugin {
this.uploads.push(fileUploadMeta.jwtAccess);
this.signedRequestUrl = fileUploadMeta.signedRequest;
} else {
return this.log(`S3 signer service error. Response: ${fileUploadMeta}`);
return this.log(
`S3 signer service error. Response: ${JSON.stringify(fileUploadMeta)}`
);
}
} catch (err) {
this.log(err);
Expand Down Expand Up @@ -151,7 +160,7 @@ class ProfilerPlugin {
await request({
url: this.signedRequestUrl,
method: 'PUT',
body: Buffer.concat(archiveBuffer).toString()
body: Buffer.concat(archiveBuffer)
});
resolve();
});
Expand Down
6 changes: 3 additions & 3 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ async function runFn(opts, fn = (e, ctx) => ctx.succeed('pass')) {
test('Works with profiler enabled', async function runTest() {
await runFn({ enabled: true });
expect(putData).toHaveLength(1);
expect(putData[0].toString()).toMatch(/profile\.cpuprofile/);
expect(putData[0].toString().length).toBeGreaterThan(1000);
});

test('Works with heapSnapshot enabled', async function runTest() {
await runFn({ heapSnapshot: true });
expect(putData).toHaveLength(1);
expect(putData[0].toString()).toMatch(/profile\.heapsnapshot/);
expect(putData[0].toString().length).toBeGreaterThan(1e6);
});

test('Works with both enabled', async function runTest() {
await runFn({ enabled: true, heapSnapshot: true });
expect(putData).toHaveLength(1);
expect(putData[0].toString()).toMatch(/cpuprofile[^]+heapsnapshot/);
expect(putData[0].toString().length).toBeGreaterThan(1e6);
});

0 comments on commit 90e24f2

Please sign in to comment.