Skip to content

Commit 63ba32c

Browse files
Include ddsource in hook logs (#166)
* deps: lock file maintenance * Include `ddsource` in hook logs * Commit lock file --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Ryan Ling <[email protected]>
1 parent cb0763b commit 63ba32c

File tree

8 files changed

+533
-523
lines changed

8 files changed

+533
-523
lines changed

.changeset/late-suits-add.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@seek/aws-codedeploy-infra': patch
3+
---
4+
5+
Include `ddsource` in hook logs

packages/hooks/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ This may be used when a build needs to be expedited in a disaster recovery scena
136136
```typescript
137137
import { Env } from 'skuba-dive';
138138
import Router from '@koa/router';
139-
import logger from '@seek/logger';
139+
import { createLogger } from '@seek/logger';
140140
141141
const config = {
142142
skipHook: Env.boolean('SKIP_SMOKE', { default: false }),

packages/hooks/src/smokeTest/koa.test.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import createLogger from '@seek/logger';
1+
import { createDestination, createLogger } from '@seek/logger';
22
import Koa from 'koa';
33
import { agent } from 'supertest';
44

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

77
const onError = jest.fn();
8-
const write = jest.fn();
98

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

1211
afterEach(jest.clearAllMocks);
12+
afterEach(stdoutMock.clear);
1313

1414
const logger = createLogger(
1515
{ serializers: { err: (err) => String(err) }, timestamp: false },
16-
{ write: (msg) => write(msg) },
16+
destination,
1717
);
1818

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

4848
expect(onError).not.toHaveBeenCalled();
49-
expect(stdout()).toBeFalsy();
49+
expect(stdoutMock.calls).toHaveLength(0);
5050
},
5151
);
5252

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

6666
expect(onError).not.toHaveBeenCalled();
67-
expect(stdout()).toBe(
68-
'{"level":30,"msg":"Smoke test succeeded in background"}',
69-
);
67+
expect(stdoutMock.onlyCall()).toStrictEqual({
68+
level: 30,
69+
msg: 'Smoke test succeeded in background',
70+
});
7071
},
7172
);
7273

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

8889
expect(onError).not.toHaveBeenCalled();
89-
expect(stdout()).toBe(
90-
'{"level":40,"err":"Error: Badness!","msg":"Smoke test failed in background"}',
91-
);
90+
expect(stdoutMock.onlyCall()).toStrictEqual({
91+
level: 40,
92+
err: 'Error: Badness!',
93+
msg: 'Smoke test failed in background',
94+
});
9295
},
9396
);
9497

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

108111
expect(onError).not.toHaveBeenCalled();
109-
expect(stdout()).toBe(
110-
'{"level":40,"err":"Error: Badness!","msg":"Smoke test failed in background"}',
111-
);
112+
expect(stdoutMock.onlyCall()).toStrictEqual({
113+
level: 40,
114+
err: 'Error: Badness!',
115+
msg: 'Smoke test failed in background',
116+
});
112117
},
113118
);
114119

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

132137
expect(onError).toHaveBeenCalledTimes(1);
133-
expect(stdout()).toBeFalsy();
138+
expect(stdoutMock.calls).toHaveLength(0);
134139
},
135140
);
136141

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

152157
expect(onError).toHaveBeenCalledTimes(1);
153-
expect(stdout()).toBeFalsy();
158+
expect(stdoutMock.calls).toHaveLength(0);
154159
},
155160
);
156161

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

166171
expect(onError).not.toHaveBeenCalled();
167-
expect(stdout()).toBe(
168-
'{"level":30,"msg":"Smoke test succeeded in background"}',
169-
);
172+
expect(stdoutMock.onlyCall()).toStrictEqual({
173+
level: 30,
174+
msg: 'Smoke test succeeded in background',
175+
});
170176

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

184190
expect(onError).not.toHaveBeenCalled();
185-
expect(stdout()).toBe('');
191+
expect(stdoutMock.calls).toHaveLength(0);
186192

187193
expect(smokeTest).toHaveBeenCalledTimes(1);
188194
expect(smokeTest).toHaveBeenLastCalledWith();

packages/infra/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"codegen": "skuba node cli/codegen"
2828
},
2929
"dependencies": {
30-
"@seek/logger": "^11.0.0",
30+
"@seek/logger": "^11.1.0",
3131
"@types/aws-lambda": "^8.10.130",
3232
"aws-cdk-lib": "^2.189.1",
3333
"constructs": "^10.3.0",

packages/infra/src/constructs/__snapshots__/stack.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`returns expected CloudFormation stack 1`] = `
44
{

packages/infra/src/handlers/framework/logging.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import createLogger from '@seek/logger';
1+
import { createDestination, createLogger } from '@seek/logger';
22

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

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

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

9-
const testDestination = {
10-
write: (data: string) => testLogs.push(JSON.parse(data)),
11-
};
11+
export { stdoutMock };
1212

1313
export const logger = createLogger(
1414
{
@@ -26,6 +26,5 @@ export const logger = createLogger(
2626
transport:
2727
config.environment === 'local' ? { target: 'pino-pretty' } : undefined,
2828
},
29-
30-
config.environment === 'test' ? testDestination : undefined,
29+
destination,
3130
);

packages/infra/src/handlers/index.test.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from '@aws-sdk/client-codedeploy';
1010
import { mockClient } from 'aws-sdk-client-mock';
1111

12-
import { testLogs } from './framework/logging.js';
12+
import { stdoutMock } from './framework/logging.js';
1313
import { getDeploymentInfo, process } from './process/process.js';
1414

1515
import { handler } from './index.js';
@@ -30,7 +30,7 @@ afterEach(() => {
3030
codeDeploy.reset();
3131
getDeploymentInfoMock.mockReset();
3232
processMock.mockReset();
33-
testLogs.length = 0;
33+
stdoutMock.clear();
3434
});
3535

3636
describe('handler', () => {
@@ -66,10 +66,11 @@ describe('handler', () => {
6666
},
6767
);
6868

69-
expect(testLogs).toStrictEqual([
69+
expect(stdoutMock.calls).toStrictEqual([
7070
{
7171
applicationName: 'beep',
7272
awsRequestId: context.awsRequestId,
73+
ddsource: 'nodejs',
7374
deploymentId: 'mock-deployment-id',
7475
level: 30,
7576
msg: 'Reported lifecycle event status',
@@ -112,10 +113,11 @@ describe('handler', () => {
112113
},
113114
);
114115

115-
expect(testLogs).toStrictEqual([
116+
expect(stdoutMock.calls).toStrictEqual([
116117
{
117118
applicationName: 'beep',
118119
awsRequestId: context.awsRequestId,
120+
ddsource: 'nodejs',
119121
deploymentId: 'mock-deployment-id',
120122
err: {
121123
message: err.message,
@@ -133,6 +135,7 @@ describe('handler', () => {
133135
{
134136
applicationName: 'beep',
135137
awsRequestId: context.awsRequestId,
138+
ddsource: 'nodejs',
136139
deploymentId: 'mock-deployment-id',
137140
level: 30,
138141
msg: 'Reported lifecycle event status',
@@ -170,10 +173,11 @@ describe('handler', () => {
170173
},
171174
);
172175

173-
expect(testLogs).toStrictEqual([
176+
expect(stdoutMock.calls).toStrictEqual([
174177
{
175178
applicationName: 'beep',
176179
awsRequestId: context.awsRequestId,
180+
ddsource: 'nodejs',
177181
deploymentId: 'mock-deployment-id',
178182
err: expect.objectContaining({ message: err.message }),
179183
level: 50,
@@ -215,10 +219,11 @@ describe('handler', () => {
215219
},
216220
);
217221

218-
expect(testLogs).toStrictEqual([
222+
expect(stdoutMock.calls).toStrictEqual([
219223
{
220224
applicationName: 'beep',
221225
awsRequestId: context.awsRequestId,
226+
ddsource: 'nodejs',
222227
deploymentId: 'mock-deployment-id',
223228
err: expect.objectContaining({ message: processError.message }),
224229
level: 50,
@@ -231,6 +236,7 @@ describe('handler', () => {
231236
{
232237
applicationName: 'beep',
233238
awsRequestId: context.awsRequestId,
239+
ddsource: 'nodejs',
234240
deploymentId: 'mock-deployment-id',
235241
err: expect.objectContaining({ message: reportError.message }),
236242
level: 50,

0 commit comments

Comments
 (0)