Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/late-suits-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@seek/aws-codedeploy-infra': patch
---

Include `ddsource` in hook logs
2 changes: 1 addition & 1 deletion packages/hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ This may be used when a build needs to be expedited in a disaster recovery scena
```typescript
import { Env } from 'skuba-dive';
import Router from '@koa/router';
import logger from '@seek/logger';
import { createLogger } from '@seek/logger';

const config = {
skipHook: Env.boolean('SKIP_SMOKE', { default: false }),
Expand Down
46 changes: 26 additions & 20 deletions packages/hooks/src/smokeTest/koa.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import createLogger from '@seek/logger';
import { createDestination, createLogger } from '@seek/logger';
import Koa from 'koa';
import { agent } from 'supertest';

import { koaMiddleware } from './koa.js';

const onError = jest.fn();
const write = jest.fn();

const stdout = () => write.mock.calls.flat().join('').trim();
const { destination, stdoutMock } = createDestination({ mock: true });

afterEach(jest.clearAllMocks);
afterEach(stdoutMock.clear);

const logger = createLogger(
{ serializers: { err: (err) => String(err) }, timestamp: false },
{ write: (msg) => write(msg) },
destination,
);

type Options = {
Expand Down Expand Up @@ -46,7 +46,7 @@ it.each`
}).expect(200, 'Smoke test succeeded');

expect(onError).not.toHaveBeenCalled();
expect(stdout()).toBeFalsy();
expect(stdoutMock.calls).toHaveLength(0);
},
);

Expand All @@ -64,9 +64,10 @@ it.each`
}).expect(200, 'Smoke test skipped');

expect(onError).not.toHaveBeenCalled();
expect(stdout()).toBe(
'{"level":30,"msg":"Smoke test succeeded in background"}',
);
expect(stdoutMock.onlyCall()).toStrictEqual({
level: 30,
msg: 'Smoke test succeeded in background',
});
},
);

Expand All @@ -86,9 +87,11 @@ it.each`
}).expect(200, 'Smoke test skipped');

expect(onError).not.toHaveBeenCalled();
expect(stdout()).toBe(
'{"level":40,"err":"Error: Badness!","msg":"Smoke test failed in background"}',
);
expect(stdoutMock.onlyCall()).toStrictEqual({
level: 40,
err: 'Error: Badness!',
msg: 'Smoke test failed in background',
});
},
);

Expand All @@ -106,9 +109,11 @@ it.each`
}).expect(200, 'Smoke test skipped');

expect(onError).not.toHaveBeenCalled();
expect(stdout()).toBe(
'{"level":40,"err":"Error: Badness!","msg":"Smoke test failed in background"}',
);
expect(stdoutMock.onlyCall()).toStrictEqual({
level: 40,
err: 'Error: Badness!',
msg: 'Smoke test failed in background',
});
},
);

Expand All @@ -130,7 +135,7 @@ it.each`
}).expect(500, 'Internal Server Error');

expect(onError).toHaveBeenCalledTimes(1);
expect(stdout()).toBeFalsy();
expect(stdoutMock.calls).toHaveLength(0);
},
);

Expand All @@ -150,7 +155,7 @@ it.each`
}).expect(500, 'Internal Server Error');

expect(onError).toHaveBeenCalledTimes(1);
expect(stdout()).toBeFalsy();
expect(stdoutMock.calls).toHaveLength(0);
},
);

Expand All @@ -164,9 +169,10 @@ it('passes no arguments to the smoke test function asynchronously', async () =>
}).expect(200, 'Smoke test skipped');

expect(onError).not.toHaveBeenCalled();
expect(stdout()).toBe(
'{"level":30,"msg":"Smoke test succeeded in background"}',
);
expect(stdoutMock.onlyCall()).toStrictEqual({
level: 30,
msg: 'Smoke test succeeded in background',
});

expect(smokeTest).toHaveBeenCalledTimes(1);
expect(smokeTest).toHaveBeenLastCalledWith();
Expand All @@ -182,7 +188,7 @@ it('passes no arguments to the smoke test function synchronously', async () => {
}).expect(200, 'Smoke test succeeded');

expect(onError).not.toHaveBeenCalled();
expect(stdout()).toBe('');
expect(stdoutMock.calls).toHaveLength(0);

expect(smokeTest).toHaveBeenCalledTimes(1);
expect(smokeTest).toHaveBeenLastCalledWith();
Expand Down
2 changes: 1 addition & 1 deletion packages/infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"codegen": "skuba node cli/codegen"
},
"dependencies": {
"@seek/logger": "^11.0.0",
"@seek/logger": "^11.1.0",
"@types/aws-lambda": "^8.10.130",
"aws-cdk-lib": "^2.189.1",
"constructs": "^10.3.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`returns expected CloudFormation stack 1`] = `
{
Expand Down
13 changes: 6 additions & 7 deletions packages/infra/src/handlers/framework/logging.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import createLogger from '@seek/logger';
import { createDestination, createLogger } from '@seek/logger';

import { config } from '../config.js';

import { getContext } from './context.js';

export const testLogs: unknown[] = [];
const { destination, stdoutMock } = createDestination({
mock: config.environment === 'test' ? { redact: [], remove: [] } : false,
});

const testDestination = {
write: (data: string) => testLogs.push(JSON.parse(data)),
};
export { stdoutMock };

export const logger = createLogger(
{
Expand All @@ -26,6 +26,5 @@ export const logger = createLogger(
transport:
config.environment === 'local' ? { target: 'pino-pretty' } : undefined,
},

config.environment === 'test' ? testDestination : undefined,
destination,
);
18 changes: 12 additions & 6 deletions packages/infra/src/handlers/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@aws-sdk/client-codedeploy';
import { mockClient } from 'aws-sdk-client-mock';

import { testLogs } from './framework/logging.js';
import { stdoutMock } from './framework/logging.js';
import { getDeploymentInfo, process } from './process/process.js';

import { handler } from './index.js';
Expand All @@ -30,7 +30,7 @@ afterEach(() => {
codeDeploy.reset();
getDeploymentInfoMock.mockReset();
processMock.mockReset();
testLogs.length = 0;
stdoutMock.clear();
});

describe('handler', () => {
Expand Down Expand Up @@ -66,10 +66,11 @@ describe('handler', () => {
},
);

expect(testLogs).toStrictEqual([
expect(stdoutMock.calls).toStrictEqual([
{
applicationName: 'beep',
awsRequestId: context.awsRequestId,
ddsource: 'nodejs',
deploymentId: 'mock-deployment-id',
level: 30,
msg: 'Reported lifecycle event status',
Expand Down Expand Up @@ -112,10 +113,11 @@ describe('handler', () => {
},
);

expect(testLogs).toStrictEqual([
expect(stdoutMock.calls).toStrictEqual([
{
applicationName: 'beep',
awsRequestId: context.awsRequestId,
ddsource: 'nodejs',
deploymentId: 'mock-deployment-id',
err: {
message: err.message,
Expand All @@ -133,6 +135,7 @@ describe('handler', () => {
{
applicationName: 'beep',
awsRequestId: context.awsRequestId,
ddsource: 'nodejs',
deploymentId: 'mock-deployment-id',
level: 30,
msg: 'Reported lifecycle event status',
Expand Down Expand Up @@ -170,10 +173,11 @@ describe('handler', () => {
},
);

expect(testLogs).toStrictEqual([
expect(stdoutMock.calls).toStrictEqual([
{
applicationName: 'beep',
awsRequestId: context.awsRequestId,
ddsource: 'nodejs',
deploymentId: 'mock-deployment-id',
err: expect.objectContaining({ message: err.message }),
level: 50,
Expand Down Expand Up @@ -215,10 +219,11 @@ describe('handler', () => {
},
);

expect(testLogs).toStrictEqual([
expect(stdoutMock.calls).toStrictEqual([
{
applicationName: 'beep',
awsRequestId: context.awsRequestId,
ddsource: 'nodejs',
deploymentId: 'mock-deployment-id',
err: expect.objectContaining({ message: processError.message }),
level: 50,
Expand All @@ -231,6 +236,7 @@ describe('handler', () => {
{
applicationName: 'beep',
awsRequestId: context.awsRequestId,
ddsource: 'nodejs',
deploymentId: 'mock-deployment-id',
err: expect.objectContaining({ message: reportError.message }),
level: 50,
Expand Down
Loading