-
Notifications
You must be signed in to change notification settings - Fork 156
test(common,logger,metrics): run e2e tests for metrics in both Node runtimes #678
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c6218b0
chore(metrics): refactor metrics e2e to make stack and resource name …
ijemmy b051d4a
chore(metrics): refactor the decorator test in the same way
ijemmy e612f6b
chore(metrics): refactor file name to be consistent
ijemmy dc39df7
chore(logger): refactor logger E2E test to use commons/e2eUtil instea…
ijemmy a45f054
test(metrics): run e2e tests on both Node12 and Node14 runtime
ijemmy 7ca572e
test(commons): move e2eUtils to an appropriate folder and write unit …
ijemmy 4e0c6b7
Update packages/commons/jest.config.js
ijemmy 270206b
chore(tracer,logger) merge change to upgrade to CDK v2 and resolve co…
ijemmy f9915f0
test(logger,metrics): move e2eUtils into the same folder as cdk-cli a…
ijemmy 8e31273
test(logger,metrics); update test:e2e target to not be specific to pa…
ijemmy cfb3931
test(commons): fix unit test for InvocationLogs
ijemmy 58899f5
chore(commons): remove istanbul ignore line
ijemmy 6a2dd7d
doc(all): update CONTRIBUTING.md to refer to v2
ijemmy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './utils/lambda'; | ||
export * from './Utility'; | ||
export * from './tests/e2e'; | ||
export * as ContextExamples from './tests/resources/contexts'; | ||
export * as Events from './tests/resources/events'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './e2eUtils'; | ||
export * from './InvocationLogs'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/** | ||
* Test InvocationLogs class | ||
* | ||
* @group unit/commons/invocationLogs | ||
* | ||
*/ | ||
|
||
import { InvocationLogs, LEVEL } from '../../src'; | ||
|
||
const exampleLogs = `START RequestId: c6af9ac6-7b61-11e6-9a41-93e812345678 Version: $LATEST | ||
2022-01-27T16:04:39.323Z\tc6af9ac6-7b61-11e6-9a41-93e812345678\tDEBUG\t{"cold_start":true,"function_arn":"arn:aws:lambda:eu-west-1:561912387782:function:loggerMiddyStandardFeatures-c555a2ec-1121-4586-9c04-185ab36ea34c","function_memory_size":128,"function_name":"loggerMiddyStandardFeatures-c555a2ec-1121-4586-9c04-185ab36ea34c","function_request_id":"7f586697-238a-4c3b-9250-a5f057c1119c","level":"DEBUG","message":"This is a DEBUG log but contains the word INFO some context and persistent key","service":"logger-e2e-testing","timestamp":"2022-01-27T16:04:39.323Z","persistentKey":"works"} | ||
2022-01-27T16:04:39.323Z\tc6af9ac6-7b61-11e6-9a41-93e812345678\tINFO\t{"cold_start":true,"function_arn":"arn:aws:lambda:eu-west-1:561912387782:function:loggerMiddyStandardFeatures-c555a2ec-1121-4586-9c04-185ab36ea34c","function_memory_size":128,"function_name":"loggerMiddyStandardFeatures-c555a2ec-1121-4586-9c04-185ab36ea34c","function_request_id":"7f586697-238a-4c3b-9250-a5f057c1119c","level":"INFO","message":"This is an INFO log with some context","service":"logger-e2e-testing","timestamp":"2022-01-27T16:04:39.323Z","persistentKey":"works","additionalKey":"additionalValue"} | ||
2022-01-27T16:04:39.323Z\tc6af9ac6-7b61-11e6-9a41-93e812345678\tINFO\t{"cold_start":true,"function_arn":"arn:aws:lambda:eu-west-1:561912387782:function:loggerMiddyStandardFeatures-c555a2ec-1121-4586-9c04-185ab36ea34c","function_memory_size":128,"function_name":"loggerMiddyStandardFeatures-c555a2ec-1121-4586-9c04-185ab36ea34c","function_request_id":"7f586697-238a-4c3b-9250-a5f057c1119c","level":"INFO","message":"This is a second INFO log with some context","service":"logger-e2e-testing","timestamp":"2022-01-27T16:04:39.323Z","persistentKey":"works","additionalKey":"additionalValue"} | ||
2022-01-27T16:04:39.323Z\tc6af9ac6-7b61-11e6-9a41-93e812345678\tERROR\t{"cold_start":true,"function_arn":"arn:aws:lambda:eu-west-1:561912387782:function:loggerMiddyStandardFeatures-c555a2ec-1121-4586-9c04-185ab36ea34c","function_memory_size":128,"function_name":"loggerMiddyStandardFeatures-c555a2ec-1121-4586-9c04-185ab36ea34c","function_request_id":"7f586697-238a-4c3b-9250-a5f057c1119c","level":"ERROR","message":"There was an error","service":"logger-e2e-testing","timestamp":"2022-01-27T16:04:39.323Z","persistentKey":"works","error":{"name":"Error","location":"/var/task/index.js:2778","message":"you cannot prevent this","stack":"Error: you cannot prevent this\\n at testFunction (/var/task/index.js:2778:11)\\n at runRequest (/var/task/index.js:2314:36)"}} | ||
END RequestId: c6af9ac6-7b61-11e6-9a41-93e812345678 | ||
REPORT RequestId: c6af9ac6-7b61-11e6-9a41-93e812345678\tDuration: 2.16 ms\tBilled Duration: 3 ms\tMemory Size: 128 MB\tMax Memory Used: 57 MB\t`; | ||
|
||
describe('Constructor', () => { | ||
test('it should parse base64 text correctly', () => { | ||
const invocationLogs = new InvocationLogs(Buffer.from(exampleLogs).toString('base64')); | ||
expect(invocationLogs.getFunctionLogs(LEVEL.DEBUG).length).toBe(1); | ||
expect(invocationLogs.getFunctionLogs(LEVEL.INFO).length).toBe(2); | ||
expect(invocationLogs.getFunctionLogs(LEVEL.ERROR).length).toBe(1); | ||
}); | ||
|
||
}); | ||
|
||
describe('doesAnyFunctionLogsContains()', () => { | ||
let invocationLogs: InvocationLogs; | ||
|
||
beforeEach(() => { | ||
invocationLogs = new InvocationLogs(Buffer.from(exampleLogs).toString('base64')); | ||
}); | ||
test('it should return true if the text appear in any logs', () => { | ||
const phraseInMessage = 'This is'; | ||
expect(invocationLogs.doesAnyFunctionLogsContains(phraseInMessage)).toBe(true); | ||
|
||
}); | ||
test('it should return false if the text does not appear in any logs', () => { | ||
const phraseNotInMessage = 'A quick brown fox jumps over the lazy dog'; | ||
expect(invocationLogs.doesAnyFunctionLogsContains(phraseNotInMessage)).toBe(false); | ||
}); | ||
|
||
test('it should return true for key in the log', () => { | ||
const keyInLog = 'error'; | ||
expect(invocationLogs.doesAnyFunctionLogsContains(keyInLog)).toBe(true); | ||
}); | ||
|
||
test('it should return true for a text in an error key', () => { | ||
const textInError = '/var/task/index.js:2778'; | ||
expect(invocationLogs.doesAnyFunctionLogsContains(textInError)).toBe(true); | ||
}); | ||
test('it should return false for the text that appears only on the ', () => { | ||
const textInStartLine = 'Version: $LATEST'; | ||
const textInEndLine = 'END RequestId'; | ||
const textInReportLine = 'Billed Duration'; | ||
expect(invocationLogs.doesAnyFunctionLogsContains(textInStartLine)).toBe(false); | ||
expect(invocationLogs.doesAnyFunctionLogsContains(textInEndLine)).toBe(false); | ||
expect(invocationLogs.doesAnyFunctionLogsContains(textInReportLine)).toBe(false); | ||
}); | ||
|
||
test('it should apply filter log based on the given level', () => { | ||
const debugLogHasWordINFO = invocationLogs.doesAnyFunctionLogsContains('INFO', LEVEL.DEBUG); | ||
expect(debugLogHasWordINFO).toBe(true); | ||
|
||
const infoLogHasWordINFO = invocationLogs.doesAnyFunctionLogsContains('INFO', LEVEL.INFO); | ||
expect(infoLogHasWordINFO).toBe(true); | ||
|
||
const errorLogHasWordINFO = invocationLogs.doesAnyFunctionLogsContains('INFO', LEVEL.ERROR); | ||
expect(errorLogHasWordINFO).toBe(false); | ||
|
||
}); | ||
}); | ||
|
||
describe('getFunctionLogs()', () => { | ||
let invocationLogs: InvocationLogs; | ||
|
||
beforeEach(() => { | ||
invocationLogs = new InvocationLogs(Buffer.from(exampleLogs).toString('base64')); | ||
}); | ||
|
||
test('it should retrive logs of the given level only', () => { | ||
const infoLogs = invocationLogs.getFunctionLogs(LEVEL.INFO); | ||
expect(infoLogs.length).toBe(2); | ||
expect(infoLogs[0].includes('INFO')).toBe(true); | ||
expect(infoLogs[1].includes('INFO')).toBe(true); | ||
expect(infoLogs[0].includes('ERROR')).toBe(false); | ||
expect(infoLogs[1].includes('ERROR')).toBe(false); | ||
|
||
const errorLogs = invocationLogs.getFunctionLogs(LEVEL.ERROR); | ||
expect(errorLogs.length).toBe(1); | ||
expect(errorLogs[0].includes('INFO')).toBe(false); | ||
expect(errorLogs[0].includes('ERROR')).toBe(true); | ||
}); | ||
|
||
test('it should NOT return logs generated by Lambda service (e.g. START, END, and REPORT)', () => { | ||
const errorLogs = invocationLogs.getFunctionLogs(LEVEL.ERROR); | ||
expect(errorLogs.length).toBe(1); | ||
expect(errorLogs[0].includes('START')).toBe(false); | ||
expect(errorLogs[0].includes('END')).toBe(false); | ||
expect(errorLogs[0].includes('REPORT')).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('parseFunctionLog()', () => { | ||
test('it should return object with the correct values based on the given log', () => { | ||
const rawLogStr = '2022-01-27T16:04:39.323Z\tc6af9ac6-7b61-11e6-9a41-93e812345678\tDEBUG\t{"cold_start":true,"function_arn":"arn:aws:lambda:eu-west-1:561912387782:function:loggerMiddyStandardFeatures-c555a2ec-1121-4586-9c04-185ab36ea34c","function_memory_size":128,"function_name":"loggerMiddyStandardFeatures-c555a2ec-1121-4586-9c04-185ab36ea34c","function_request_id":"7f586697-238a-4c3b-9250-a5f057c1119c","level":"DEBUG","message":"This is a DEBUG log but contains the word INFO some context and persistent key","service":"logger-e2e-testing","timestamp":"2022-01-27T16:04:39.323Z","persistentKey":"works"}'; | ||
|
||
const logObj = InvocationLogs.parseFunctionLog(rawLogStr); | ||
expect(logObj.timestamp).toBe('2022-01-27T16:04:39.323Z'); | ||
expect(logObj.invocationId).toBe('c6af9ac6-7b61-11e6-9a41-93e812345678'); | ||
expect(logObj.logLevel).toBe(LEVEL.DEBUG); | ||
expect(logObj.logObject).toStrictEqual({ | ||
cold_start: true, | ||
function_arn: 'arn:aws:lambda:eu-west-1:561912387782:function:loggerMiddyStandardFeatures-c555a2ec-1121-4586-9c04-185ab36ea34c', | ||
function_memory_size: 128, | ||
function_name: 'loggerMiddyStandardFeatures-c555a2ec-1121-4586-9c04-185ab36ea34c', | ||
function_request_id: '7f586697-238a-4c3b-9250-a5f057c1119c', | ||
level: 'DEBUG', | ||
message: 'This is a DEBUG log but contains the word INFO some context and persistent key', | ||
service: 'logger-e2e-testing', | ||
timestamp: '2022-01-27T16:04:39.323Z', | ||
persistentKey: 'works', | ||
}); | ||
}); | ||
|
||
test('it should throw an error if receive incorrect formatted raw log string', () => { | ||
const noTabString = 'no-tab-character'; | ||
expect(() => { | ||
InvocationLogs.parseFunctionLog(noTabString); | ||
}).toThrow(Error); | ||
|
||
const missSomeElements = '2022-01-27T16:04:39.323Z\tc6af9ac6-7b61-11e6-9a41-93e812345678\tDEBUG\t'; | ||
expect(() => { | ||
InvocationLogs.parseFunctionLog(missSomeElements); | ||
}).toThrow(Error); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const RESOURCE_NAME_PREFIX = 'Logger-E2E'; | ||
export const TEST_CASE_TIMEOUT = 20_000; // 20 seconds | ||
export const SETUP_TIMEOUT = 300_000; // 300 seconds | ||
export const TEARDOWN_TIMEOUT = 200_000; | ||
export const STACK_OUTPUT_LOG_GROUP = 'LogGroupName'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.