forked from philips-labs/terraform-aws-github-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add option to format logging in JSON for lambdas (philips-labs#…
…1228) * feat(log): Adding Support for JSON logging * Passing in log_type to other lambdas * Casting e as Error * Add log_level variable, fix formatting * Correcting failed resolution * Using latest releases for testing * Passing in log_level to sub-modules * Update terraform.yml * Manually removing `node-fetch` * Moving logger object to new file * Resolving merge from develop Wouldn't be a conflict resolve without a miss * Logging when job is not queued * Updating handler names
- Loading branch information
Showing
40 changed files
with
532 additions
and
228 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
"typescript": "^4.4.4" | ||
}, | ||
"dependencies": { | ||
"tslog": "^3.2.2", | ||
"axios": "^0.24.0" | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/src/lambda.ts
This file contains 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 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
10 changes: 10 additions & 0 deletions
10
modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/src/syncer/logger.ts
This file contains 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,10 @@ | ||
import { Logger } from 'tslog'; | ||
|
||
export const logger = new Logger({ | ||
colorizePrettyLogs: false, | ||
displayInstanceName: false, | ||
minLevel: process.env.LOG_LEVEL || 'info', | ||
name: 'runner-binaries-syncer', | ||
overwriteConsole: true, | ||
type: process.env.LOG_TYPE || 'pretty', | ||
}); |
6 changes: 6 additions & 0 deletions
6
modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/src/syncer/modules.d.ts
This file contains 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,6 @@ | ||
declare namespace NodeJS { | ||
export interface ProcessEnv { | ||
LOG_LEVEL: 'silly' | 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal'; | ||
LOG_TYPE: 'json' | 'pretty' | 'hidden'; | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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,27 +1,31 @@ | ||
import { scaleUp as scaleUpAction } from './scale-runners/scale-up'; | ||
import { scaleDown as scaleDownAction } from './scale-runners/scale-down'; | ||
import { SQSEvent, ScheduledEvent, Context } from 'aws-lambda'; | ||
import { scaleUp } from './scale-runners/scale-up'; | ||
import { scaleDown } from './scale-runners/scale-down'; | ||
import { SQSEvent, ScheduledEvent, Context, Callback } from 'aws-lambda'; | ||
import { logger } from './scale-runners/logger'; | ||
import 'source-map-support/register'; | ||
|
||
export const scaleUp = async (event: SQSEvent, context: Context, callback: any): Promise<void> => { | ||
console.debug(JSON.stringify(event)); | ||
export async function scaleUpHandler(event: SQSEvent, context: Context, callback: Callback): Promise<void> { | ||
logger.setSettings({ requestId: context.awsRequestId }); | ||
logger.debug(JSON.stringify(event)); | ||
try { | ||
for (const e of event.Records) { | ||
await scaleUpAction(e.eventSource, JSON.parse(e.body)); | ||
await scaleUp(e.eventSource, JSON.parse(e.body)); | ||
} | ||
|
||
callback(null); | ||
} catch (e) { | ||
console.error(e); | ||
logger.error(e); | ||
callback('Failed handling SQS event'); | ||
} | ||
}; | ||
} | ||
|
||
export const scaleDown = async (event: ScheduledEvent, context: Context, callback: any): Promise<void> => { | ||
export async function scaleDownHandler(event: ScheduledEvent, context: Context, callback: Callback): Promise<void> { | ||
logger.setSettings({ requestId: context.awsRequestId }); | ||
try { | ||
await scaleDownAction(); | ||
await scaleDown(); | ||
callback(null); | ||
} catch (e) { | ||
console.error(e); | ||
logger.error(e); | ||
callback('Failed'); | ||
} | ||
}; | ||
} |
This file contains 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
Oops, something went wrong.