From 6aaa4f491463e676c90678b2fd077b53492861c8 Mon Sep 17 00:00:00 2001 From: chotai Date: Thu, 26 Sep 2024 15:37:19 +0100 Subject: [PATCH] Improve logging --- .../github/handlers/handle-tf-svc-infra-workflow.js | 6 +++--- .../github/handlers/handle-triggered-workflow.js | 2 +- ...ler-v2.js => workflow-run-creation-handler-v2.js} | 12 +++++++----- ...t.js => workflow-run-creation-handler-v2.test.js} | 12 ++++++------ ...ndler.js => workflow-run-notification-handler.js} | 6 +++--- src/listeners/github/message-handler.js | 10 +++++----- 6 files changed, 25 insertions(+), 23 deletions(-) rename src/listeners/github/handlers/{workflow-run-handler-v2.js => workflow-run-creation-handler-v2.js} (82%) rename src/listeners/github/handlers/{workflow-run-handler-v2.test.js => workflow-run-creation-handler-v2.test.js} (92%) rename src/listeners/github/handlers/{workflow-run-alert-handler.js => workflow-run-notification-handler.js} (93%) diff --git a/src/listeners/github/handlers/handle-tf-svc-infra-workflow.js b/src/listeners/github/handlers/handle-tf-svc-infra-workflow.js index b983e7e..a3691d3 100644 --- a/src/listeners/github/handlers/handle-tf-svc-infra-workflow.js +++ b/src/listeners/github/handlers/handle-tf-svc-infra-workflow.js @@ -21,7 +21,7 @@ const handleTfSvcInfraWorkflow = async (db, logger, message, workflowFile) => { if (workflowFile === config.get('workflows.createTenantService')) { if (message.action === 'completed') { logger.info( - `Ignoring ${config.get('workflows.createTenantService')} complete status` + `Creation handler: Ignoring ${config.get('workflows.createTenantService')} complete status` ) return } @@ -34,7 +34,7 @@ const handleTfSvcInfraWorkflow = async (db, logger, message, workflowFile) => { workflowFile === config.get('workflows.manualApplyTenantService') ) { if (message.action === 'completed') { - logger.info(`Bulk-updating cdp-tf-svc-infra`) + logger.info(`Creation handler: Bulk updating cdp-tf-svc-infra`) // Any time cdp-tf-svc-infra completes on main, regardless of which commit triggered it // assume all services in management tenant-services.json are successfully created. @@ -52,7 +52,7 @@ const handleTfSvcInfraWorkflow = async (db, logger, message, workflowFile) => { return } - logger.info(`did not process tf-svc-infra workflow`) + logger.info(`Creation handler: Did not process tf-svc-infra workflow`) } catch (e) { logger.error(e) } diff --git a/src/listeners/github/handlers/handle-triggered-workflow.js b/src/listeners/github/handlers/handle-triggered-workflow.js index a9a188f..a034c91 100644 --- a/src/listeners/github/handlers/handle-triggered-workflow.js +++ b/src/listeners/github/handlers/handle-triggered-workflow.js @@ -32,7 +32,7 @@ const handleTriggeredWorkflow = async (db, logger, message) => { ) logger.info( - `attempting to update ${message.repository?.name} status for ${serviceRepo} to ${workflowStatus}` + `Creation handler: Attempting to update ${message.repository?.name} status for ${serviceRepo} to ${workflowStatus}` ) await updateWorkflowStatus( diff --git a/src/listeners/github/handlers/workflow-run-handler-v2.js b/src/listeners/github/handlers/workflow-run-creation-handler-v2.js similarity index 82% rename from src/listeners/github/handlers/workflow-run-handler-v2.js rename to src/listeners/github/handlers/workflow-run-creation-handler-v2.js index e4f46cf..87384d5 100644 --- a/src/listeners/github/handlers/workflow-run-handler-v2.js +++ b/src/listeners/github/handlers/workflow-run-creation-handler-v2.js @@ -37,7 +37,7 @@ const shouldWorkflowBeProcessed = (repo, workflow) => { } } -const workflowRunHandlerV2 = async (server, message) => { +const workflowRunCreationHandlerV2 = async (server, message) => { const db = server.db const workflowRepo = message.repository?.name const headBranch = message.workflow_run?.head_branch @@ -48,7 +48,7 @@ const workflowRunHandlerV2 = async (server, message) => { if (headBranch !== 'main') { logger.info( - `Not processing workflow run ${workflowRepo}/${workflowFile}, not running on main branch` + `Creation handler: Not processing workflow run ${workflowRepo}/${workflowFile}, not running on main branch` ) return } @@ -56,7 +56,7 @@ const workflowRunHandlerV2 = async (server, message) => { // Are we interested in handling the event? if (shouldWorkflowBeProcessed(workflowRepo, workflowFile)) { logger.info( - `Processing workflow_run message for ${workflowRepo}, ${headBranch}/${headSHA}, action: ${message.action}` + `Creation handler: Processing workflow_run message for ${workflowRepo}, ${headBranch}/${headSHA}, action: ${message.action}` ) switch (workflowRepo) { case config.get('github.repos.cdpTfSvcInfra'): @@ -67,8 +67,10 @@ const workflowRunHandlerV2 = async (server, message) => { break } } else { - logger.info(`Not processing ${workflowRepo}/${workflowFile}`) + logger.info( + `Creation handler: Not processing ${workflowRepo}/${workflowFile}` + ) } } -export { workflowRunHandlerV2, shouldWorkflowBeProcessed } +export { workflowRunCreationHandlerV2, shouldWorkflowBeProcessed } diff --git a/src/listeners/github/handlers/workflow-run-handler-v2.test.js b/src/listeners/github/handlers/workflow-run-creation-handler-v2.test.js similarity index 92% rename from src/listeners/github/handlers/workflow-run-handler-v2.test.js rename to src/listeners/github/handlers/workflow-run-creation-handler-v2.test.js index 80f25fc..6300f89 100644 --- a/src/listeners/github/handlers/workflow-run-handler-v2.test.js +++ b/src/listeners/github/handlers/workflow-run-creation-handler-v2.test.js @@ -1,8 +1,8 @@ import { statuses } from '~/src/constants/statuses' import { shouldWorkflowBeProcessed, - workflowRunHandlerV2 -} from '~/src/listeners/github/handlers/workflow-run-handler-v2' + workflowRunCreationHandlerV2 +} from '~/src/listeners/github/handlers/workflow-run-creation-handler-v2' import { handleTriggeredWorkflow } from '~/src/listeners/github/handlers/handle-triggered-workflow' import { handleTfSvcInfraWorkflow } from '~/src/listeners/github/handlers/handle-tf-svc-infra-workflow' @@ -45,7 +45,7 @@ describe('#workflow-run-handler-v2', () => { } } - await workflowRunHandlerV2(mockServer, msg) + await workflowRunCreationHandlerV2(mockServer, msg) expect(handleTriggeredWorkflow).not.toHaveBeenCalled() expect(handleTfSvcInfraWorkflow).not.toHaveBeenCalled() }) @@ -72,7 +72,7 @@ describe('#workflow-run-handler-v2', () => { } } } - await workflowRunHandlerV2(mockServer, msg) + await workflowRunCreationHandlerV2(mockServer, msg) expect(handleTriggeredWorkflow).toHaveBeenCalled() expect(handleTfSvcInfraWorkflow).not.toHaveBeenCalled() }) @@ -99,7 +99,7 @@ describe('#workflow-run-handler-v2', () => { } } } - await workflowRunHandlerV2(mockServer, msg) + await workflowRunCreationHandlerV2(mockServer, msg) expect(handleTriggeredWorkflow).not.toHaveBeenCalled() expect(handleTfSvcInfraWorkflow).toHaveBeenCalled() }) @@ -131,7 +131,7 @@ describe('#workflow-run-handler-v2', () => { } } } - await workflowRunHandlerV2(mockServer, msg) + await workflowRunCreationHandlerV2(mockServer, msg) expect(handleTriggeredWorkflow).not.toHaveBeenCalled() expect(handleTfSvcInfraWorkflow).not.toHaveBeenCalled() }) diff --git a/src/listeners/github/handlers/workflow-run-alert-handler.js b/src/listeners/github/handlers/workflow-run-notification-handler.js similarity index 93% rename from src/listeners/github/handlers/workflow-run-alert-handler.js rename to src/listeners/github/handlers/workflow-run-notification-handler.js index 4812470..eed53ad 100644 --- a/src/listeners/github/handlers/workflow-run-alert-handler.js +++ b/src/listeners/github/handlers/workflow-run-notification-handler.js @@ -88,7 +88,7 @@ function shouldSendAlert(headBranch, action, conclusion) { ) } -async function workflowRunAlertHandler(server, event) { +async function workflowRunNotificationHandler(server, event) { const { name: repo, html_url: repoUrl } = event.repository const action = event.action const { @@ -112,7 +112,7 @@ async function workflowRunAlertHandler(server, event) { if (ActionFailed) { server.logger.info( - `Workflow '${workflowName}' in ${repo} failed: ${workflowUrl}` + `Notification handler: '${workflowName}' in ${repo} failed: ${workflowUrl} with status '${conclusion}'` ) } @@ -142,4 +142,4 @@ async function workflowRunAlertHandler(server, event) { } } -export { workflowRunAlertHandler } +export { workflowRunNotificationHandler } diff --git a/src/listeners/github/message-handler.js b/src/listeners/github/message-handler.js index ced64a8..22cff08 100644 --- a/src/listeners/github/message-handler.js +++ b/src/listeners/github/message-handler.js @@ -1,6 +1,6 @@ import { config } from '~/src/config' -import { workflowRunHandlerV2 } from '~/src/listeners/github/handlers/workflow-run-handler-v2' -import { workflowRunAlertHandler } from '~/src/listeners/github/handlers/workflow-run-alert-handler' +import { workflowRunCreationHandlerV2 } from '~/src/listeners/github/handlers/workflow-run-creation-handler-v2' +import { workflowRunNotificationHandler } from '~/src/listeners/github/handlers/workflow-run-notification-handler' const githubWebhooks = new Set([ config.get('github.repos.appDeployments'), @@ -20,13 +20,13 @@ const shouldProcess = (message, eventType) => { const handle = async (server, message) => { try { if (shouldProcess(message, 'workflow_run')) { - return await workflowRunHandlerV2(server, message) + await workflowRunCreationHandlerV2(server, message) } if (shouldProcess(message, 'workflow_run')) { - return await workflowRunAlertHandler(server, message) + await workflowRunNotificationHandler(server, message) } } catch (error) { - server.logger.error(error, 'Exception in workflow handler') + server.logger.error(error, 'Exception in github events processing handler') } }