Skip to content

Commit

Permalink
Merge pull request #283 from DEFRA/439713
Browse files Browse the repository at this point in the history
Improve logging
  • Loading branch information
chotai authored Sep 26, 2024
2 parents 1b04d67 + 6aaa4f4 commit f3a5cdd
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/listeners/github/handlers/handle-tf-svc-infra-workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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.
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/listeners/github/handlers/handle-triggered-workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -48,15 +48,15 @@ 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
}

// 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'):
Expand All @@ -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 }
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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()
})
Expand All @@ -72,7 +72,7 @@ describe('#workflow-run-handler-v2', () => {
}
}
}
await workflowRunHandlerV2(mockServer, msg)
await workflowRunCreationHandlerV2(mockServer, msg)
expect(handleTriggeredWorkflow).toHaveBeenCalled()
expect(handleTfSvcInfraWorkflow).not.toHaveBeenCalled()
})
Expand All @@ -99,7 +99,7 @@ describe('#workflow-run-handler-v2', () => {
}
}
}
await workflowRunHandlerV2(mockServer, msg)
await workflowRunCreationHandlerV2(mockServer, msg)
expect(handleTriggeredWorkflow).not.toHaveBeenCalled()
expect(handleTfSvcInfraWorkflow).toHaveBeenCalled()
})
Expand Down Expand Up @@ -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()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}'`
)
}

Expand Down Expand Up @@ -142,4 +142,4 @@ async function workflowRunAlertHandler(server, event) {
}
}

export { workflowRunAlertHandler }
export { workflowRunNotificationHandler }
10 changes: 5 additions & 5 deletions src/listeners/github/message-handler.js
Original file line number Diff line number Diff line change
@@ -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'),
Expand All @@ -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')
}
}

Expand Down

0 comments on commit f3a5cdd

Please sign in to comment.