-
Notifications
You must be signed in to change notification settings - Fork 722
refactor(webhook): add persistent keys in logs #5030
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ export async function publishForRunners( | |
|
|
||
| const checkBodySizeResult = checkBodySize(body, headers); | ||
|
|
||
| const { event, eventType } = readEvent(headers, body); | ||
| const { event, eventType } = readEvent(headers, body, ['workflow_job']); | ||
| logger.info(`Github event ${event.action} accepted for ${event.repository.full_name}`); | ||
| if (checkBodySizeResult.sizeExceeded) { | ||
| // We only warn for large event, when moving the event bridge we can only can accept events up to 256KB | ||
|
|
@@ -39,11 +39,10 @@ export async function publishOnEventBridge( | |
|
|
||
| await verifySignature(headers, body, config.webhookSecret); | ||
|
|
||
| const eventType = headers['x-github-event'] as string; | ||
| checkEventIsSupported(eventType, config.allowedEvents); | ||
|
|
||
| const checkBodySizeResult = checkBodySize(body, headers); | ||
|
|
||
| const { eventType } = readEvent(headers, body, config.allowedEvents); | ||
|
|
||
| logger.info( | ||
| `Github event ${headers['x-github-event'] as string} accepted for ` + | ||
| `${headers['x-github-hook-installation-target-id'] as string}`, | ||
|
|
@@ -127,9 +126,13 @@ function checkEventIsSupported(eventType: string, allowedEvents: string[]): void | |
| } | ||
| } | ||
|
|
||
| function readEvent(headers: IncomingHttpHeaders, body: string): { event: WorkflowJobEvent; eventType: string } { | ||
| function readEvent( | ||
| headers: IncomingHttpHeaders, | ||
| body: string, | ||
| allowedEvents: string[], | ||
| ): { event: WorkflowJobEvent; eventType: string } { | ||
| const eventType = headers['x-github-event'] as string; | ||
| checkEventIsSupported(eventType, ['workflow_job']); | ||
| checkEventIsSupported(eventType, allowedEvents); | ||
|
|
||
| const event = JSON.parse(body) as WorkflowJobEvent; | ||
| logger.appendPersistentKeys({ | ||
|
Comment on lines
134
to
138
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
publishOnEventBridgenow callsreadEvent(which doesJSON.parseand appends workflow_job-derived persistent keys) before checkingsizeExceeded. This means oversized payloads will still be fully parsed and may throw before the code can publish theerror.<eventType>event. If the intent is to always emit the error event for oversized bodies, consider moving thereadEventcall inside the non-oversize branch, or makingreadEventable to safely extract/log only header-derived fields whensizeExceededis true.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@npalm Same here