@datadog/datadog-ci 0.17.8 → 0.17.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/lambda/__tests__/fixtures.d.ts +42 -0
- package/dist/commands/lambda/__tests__/fixtures.js +73 -0
- package/dist/commands/lambda/__tests__/{function.test.d.ts → functions/commons.test.d.ts} +0 -0
- package/dist/commands/lambda/__tests__/functions/commons.test.js +171 -0
- package/dist/commands/lambda/__tests__/functions/instrument.test.d.ts +1 -0
- package/dist/commands/lambda/__tests__/{function.test.js → functions/instrument.test.js} +355 -417
- package/dist/commands/lambda/__tests__/functions/uninstrument.test.d.ts +1 -0
- package/dist/commands/lambda/__tests__/functions/uninstrument.test.js +298 -0
- package/dist/commands/lambda/__tests__/instrument.test.js +270 -163
- package/dist/commands/lambda/__tests__/loggroup.test.js +98 -34
- package/dist/commands/lambda/__tests__/tags.test.js +107 -31
- package/dist/commands/lambda/__tests__/uninstrument.test.d.ts +1 -0
- package/dist/commands/lambda/__tests__/uninstrument.test.js +223 -0
- package/dist/commands/lambda/constants.d.ts +1 -0
- package/dist/commands/lambda/constants.js +2 -1
- package/dist/commands/lambda/functions/commons.d.ts +71 -0
- package/dist/commands/lambda/functions/commons.js +170 -0
- package/dist/commands/lambda/functions/instrument.d.ts +16 -0
- package/dist/commands/lambda/{function.js → functions/instrument.js} +42 -102
- package/dist/commands/lambda/functions/uninstrument.d.ts +6 -0
- package/dist/commands/lambda/functions/uninstrument.js +110 -0
- package/dist/commands/lambda/index.js +2 -1
- package/dist/commands/lambda/instrument.d.ts +4 -3
- package/dist/commands/lambda/instrument.js +85 -40
- package/dist/commands/lambda/interfaces.d.ts +54 -0
- package/dist/commands/lambda/loggroup.d.ts +4 -7
- package/dist/commands/lambda/loggroup.js +27 -4
- package/dist/commands/lambda/tags.d.ts +3 -4
- package/dist/commands/lambda/tags.js +19 -3
- package/dist/commands/lambda/uninstrument.d.ts +11 -0
- package/dist/commands/lambda/uninstrument.js +127 -0
- package/dist/helpers/__tests__/ci.test.js +23 -0
- package/dist/helpers/ci.js +13 -6
- package/package.json +1 -1
- package/dist/commands/lambda/function.d.ts +0 -43
|
@@ -35,43 +35,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
35
35
|
jest.mock('fs');
|
|
36
36
|
jest.mock('aws-sdk');
|
|
37
37
|
const aws_sdk_1 = require("aws-sdk");
|
|
38
|
-
const
|
|
38
|
+
const chalk_1 = require("chalk");
|
|
39
39
|
const advanced_1 = require("clipanion/lib/advanced");
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
40
41
|
const path_1 = __importDefault(require("path"));
|
|
41
|
-
const constants_1 = require("../constants");
|
|
42
42
|
const instrument_1 = require("../instrument");
|
|
43
|
+
const fixtures_1 = require("./fixtures");
|
|
43
44
|
// tslint:disable-next-line
|
|
44
45
|
const { version } = require(path_1.default.join(__dirname, '../../../../package.json'));
|
|
45
46
|
describe('lambda', () => {
|
|
46
|
-
const createMockContext = () => {
|
|
47
|
-
let data = '';
|
|
48
|
-
return {
|
|
49
|
-
stdout: {
|
|
50
|
-
toString: () => data,
|
|
51
|
-
write: (input) => {
|
|
52
|
-
data += input;
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
const createCommand = () => {
|
|
58
|
-
const command = new instrument_1.InstrumentCommand();
|
|
59
|
-
command.context = createMockContext();
|
|
60
|
-
return command;
|
|
61
|
-
};
|
|
62
|
-
const makeCli = () => {
|
|
63
|
-
const cli = new advanced_1.Cli();
|
|
64
|
-
cli.register(instrument_1.InstrumentCommand);
|
|
65
|
-
return cli;
|
|
66
|
-
};
|
|
67
|
-
const makeMockLambda = (functionConfigs) => ({
|
|
68
|
-
getFunction: jest.fn().mockImplementation(({ FunctionName }) => ({
|
|
69
|
-
promise: () => Promise.resolve({ Configuration: functionConfigs[FunctionName] }),
|
|
70
|
-
})),
|
|
71
|
-
listTags: jest.fn().mockImplementation(() => ({ promise: () => Promise.resolve({ Tags: {} }) })),
|
|
72
|
-
tagResource: jest.fn().mockImplementation(() => ({ promise: () => Promise.resolve({}) })),
|
|
73
|
-
updateFunctionConfiguration: jest.fn().mockImplementation(() => ({ promise: () => Promise.resolve() })),
|
|
74
|
-
});
|
|
75
47
|
describe('instrument', () => {
|
|
76
48
|
describe('execute', () => {
|
|
77
49
|
const OLD_ENV = process.env;
|
|
@@ -85,15 +57,15 @@ describe('lambda', () => {
|
|
|
85
57
|
test('prints dry run data for lambda library layer', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
58
|
;
|
|
87
59
|
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
88
|
-
aws_sdk_1.Lambda.mockImplementation(() => makeMockLambda({
|
|
60
|
+
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
|
|
89
61
|
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
90
62
|
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
91
63
|
Handler: 'index.handler',
|
|
92
64
|
Runtime: 'nodejs12.x',
|
|
93
65
|
},
|
|
94
66
|
}));
|
|
95
|
-
const cli = makeCli();
|
|
96
|
-
const context = createMockContext();
|
|
67
|
+
const cli = fixtures_1.makeCli();
|
|
68
|
+
const context = fixtures_1.createMockContext();
|
|
97
69
|
const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
|
|
98
70
|
const code = yield cli.run([
|
|
99
71
|
'lambda',
|
|
@@ -117,7 +89,8 @@ describe('lambda', () => {
|
|
|
117
89
|
const output = context.stdout.toString();
|
|
118
90
|
expect(code).toBe(0);
|
|
119
91
|
expect(output).toMatchInlineSnapshot(`
|
|
120
|
-
"[
|
|
92
|
+
"${chalk_1.bold(chalk_1.yellow('[Warning]'))} Instrument your ${chalk_1.hex('#FF9900').bold('Lambda')} functions in a dev or staging environment first. Should the instrumentation result be unsatisfactory, run \`${chalk_1.bold('uninstrument')}\` with the same arguments to revert the changes.
|
|
93
|
+
${chalk_1.bold(chalk_1.cyan('[Dry Run] '))}Will apply the following updates:
|
|
121
94
|
UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
|
|
122
95
|
{
|
|
123
96
|
\\"FunctionName\\": \\"arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\\",
|
|
@@ -150,15 +123,15 @@ describe('lambda', () => {
|
|
|
150
123
|
test('prints dry run data for lambda extension layer', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
151
124
|
;
|
|
152
125
|
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
153
|
-
aws_sdk_1.Lambda.mockImplementation(() => makeMockLambda({
|
|
126
|
+
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
|
|
154
127
|
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
155
128
|
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
156
129
|
Handler: 'index.handler',
|
|
157
130
|
Runtime: 'nodejs12.x',
|
|
158
131
|
},
|
|
159
132
|
}));
|
|
160
|
-
const cli = makeCli();
|
|
161
|
-
const context = createMockContext();
|
|
133
|
+
const cli = fixtures_1.makeCli();
|
|
134
|
+
const context = fixtures_1.createMockContext();
|
|
162
135
|
const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
|
|
163
136
|
process.env.DATADOG_API_KEY = '1234';
|
|
164
137
|
const code = yield cli.run([
|
|
@@ -181,7 +154,8 @@ describe('lambda', () => {
|
|
|
181
154
|
const output = context.stdout.toString();
|
|
182
155
|
expect(code).toBe(0);
|
|
183
156
|
expect(output).toMatchInlineSnapshot(`
|
|
184
|
-
"[
|
|
157
|
+
"${chalk_1.bold(chalk_1.yellow('[Warning]'))} Instrument your ${chalk_1.hex('#FF9900').bold('Lambda')} functions in a dev or staging environment first. Should the instrumentation result be unsatisfactory, run \`${chalk_1.bold('uninstrument')}\` with the same arguments to revert the changes.
|
|
158
|
+
${chalk_1.bold(chalk_1.cyan('[Dry Run] '))}Will apply the following updates:
|
|
185
159
|
UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
|
|
186
160
|
{
|
|
187
161
|
\\"FunctionName\\": \\"arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\\",
|
|
@@ -211,10 +185,225 @@ describe('lambda', () => {
|
|
|
211
185
|
"
|
|
212
186
|
`);
|
|
213
187
|
}));
|
|
188
|
+
test('instrumenting with source code integrations fails if not run within a git repo', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
189
|
+
;
|
|
190
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
191
|
+
const lambda = fixtures_1.makeMockLambda({
|
|
192
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
193
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
194
|
+
Handler: 'index.handler',
|
|
195
|
+
Runtime: 'nodejs12.x',
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
aws_sdk_1.Lambda.mockImplementation(() => lambda);
|
|
199
|
+
process.env.DATADOG_API_KEY = '1234';
|
|
200
|
+
const cli = fixtures_1.makeCli();
|
|
201
|
+
const context = fixtures_1.createMockContext();
|
|
202
|
+
yield cli.run([
|
|
203
|
+
'lambda',
|
|
204
|
+
'instrument',
|
|
205
|
+
'--function',
|
|
206
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
207
|
+
'--layerVersion',
|
|
208
|
+
'10',
|
|
209
|
+
'-s',
|
|
210
|
+
'--service',
|
|
211
|
+
'dummy',
|
|
212
|
+
'--env',
|
|
213
|
+
'dummy',
|
|
214
|
+
'--version',
|
|
215
|
+
'0.1',
|
|
216
|
+
], context);
|
|
217
|
+
const output = context.stdout.toString();
|
|
218
|
+
expect(output).toMatch(/.*Make sure the command is running within your git repository\..*/i);
|
|
219
|
+
}));
|
|
220
|
+
test('instrumenting with source code integrations fails if DATADOG_API_KEY is not provided', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
221
|
+
;
|
|
222
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
223
|
+
const lambda = fixtures_1.makeMockLambda({
|
|
224
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
225
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
226
|
+
Handler: 'index.handler',
|
|
227
|
+
Runtime: 'nodejs12.x',
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
aws_sdk_1.Lambda.mockImplementation(() => lambda);
|
|
231
|
+
const cli = fixtures_1.makeCli();
|
|
232
|
+
const context = fixtures_1.createMockContext();
|
|
233
|
+
yield cli.run([
|
|
234
|
+
'lambda',
|
|
235
|
+
'instrument',
|
|
236
|
+
'--function',
|
|
237
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
238
|
+
'--layerVersion',
|
|
239
|
+
'10',
|
|
240
|
+
'-s',
|
|
241
|
+
'--service',
|
|
242
|
+
'dummy',
|
|
243
|
+
'--env',
|
|
244
|
+
'dummy',
|
|
245
|
+
'--version',
|
|
246
|
+
'0.1',
|
|
247
|
+
], context);
|
|
248
|
+
const output = context.stdout.toString();
|
|
249
|
+
expect(output).toMatch(/.*Missing DATADOG_API_KEY in your environment.*/i);
|
|
250
|
+
}));
|
|
251
|
+
test('ensure the instrument command ran from a dirty git repo fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
252
|
+
;
|
|
253
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
254
|
+
const lambda = fixtures_1.makeMockLambda({
|
|
255
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
256
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
257
|
+
Handler: 'index.handler',
|
|
258
|
+
Runtime: 'nodejs12.x',
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
aws_sdk_1.Lambda.mockImplementation(() => lambda);
|
|
262
|
+
process.env.DATADOG_API_KEY = '1234';
|
|
263
|
+
const context = fixtures_1.createMockContext();
|
|
264
|
+
const instrumentCommand = instrument_1.InstrumentCommand;
|
|
265
|
+
const mockGitStatus = jest.spyOn(instrumentCommand.prototype, 'getCurrentGitStatus');
|
|
266
|
+
mockGitStatus.mockImplementation(() => ({
|
|
267
|
+
ahead: 0,
|
|
268
|
+
isClean: false,
|
|
269
|
+
}));
|
|
270
|
+
const cli = new advanced_1.Cli();
|
|
271
|
+
cli.register(instrumentCommand);
|
|
272
|
+
yield cli.run([
|
|
273
|
+
'lambda',
|
|
274
|
+
'instrument',
|
|
275
|
+
'--function',
|
|
276
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
277
|
+
'--layerVersion',
|
|
278
|
+
'10',
|
|
279
|
+
'-s',
|
|
280
|
+
'--service',
|
|
281
|
+
'dummy',
|
|
282
|
+
'--env',
|
|
283
|
+
'dummy',
|
|
284
|
+
'--version',
|
|
285
|
+
'0.1',
|
|
286
|
+
], context);
|
|
287
|
+
const output = context.stdout.toString();
|
|
288
|
+
expect(output).toMatch('Error: Local git repository is dirty');
|
|
289
|
+
}));
|
|
290
|
+
test('ensure source code integration flag works from a clean repo', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
291
|
+
;
|
|
292
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
293
|
+
const lambda = fixtures_1.makeMockLambda({
|
|
294
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
295
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
296
|
+
Handler: 'index.handler',
|
|
297
|
+
Runtime: 'nodejs12.x',
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
aws_sdk_1.Lambda.mockImplementation(() => lambda);
|
|
301
|
+
process.env.DATADOG_API_KEY = '1234';
|
|
302
|
+
const context = fixtures_1.createMockContext();
|
|
303
|
+
const instrumentCommand = instrument_1.InstrumentCommand;
|
|
304
|
+
const mockGitStatus = jest.spyOn(instrumentCommand.prototype, 'getCurrentGitStatus');
|
|
305
|
+
mockGitStatus.mockImplementation(() => ({
|
|
306
|
+
ahead: 0,
|
|
307
|
+
hash: '1be168ff837f043bde17c0314341c84271047b31',
|
|
308
|
+
isClean: true,
|
|
309
|
+
}));
|
|
310
|
+
const mockUploadFunction = jest.spyOn(instrumentCommand.prototype, 'uploadGitData');
|
|
311
|
+
mockUploadFunction.mockImplementation(() => {
|
|
312
|
+
return;
|
|
313
|
+
});
|
|
314
|
+
const cli = new advanced_1.Cli();
|
|
315
|
+
cli.register(instrumentCommand);
|
|
316
|
+
yield cli.run([
|
|
317
|
+
'lambda',
|
|
318
|
+
'instrument',
|
|
319
|
+
'--function',
|
|
320
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
321
|
+
'--layerVersion',
|
|
322
|
+
'10',
|
|
323
|
+
'-s',
|
|
324
|
+
'--service',
|
|
325
|
+
'dummy',
|
|
326
|
+
'--env',
|
|
327
|
+
'dummy',
|
|
328
|
+
'--version',
|
|
329
|
+
'0.1',
|
|
330
|
+
], context);
|
|
331
|
+
const output = context.stdout.toString();
|
|
332
|
+
expect(output).toMatchInlineSnapshot(`
|
|
333
|
+
"${chalk_1.bold(chalk_1.yellow('[Warning]'))} Instrument your ${chalk_1.hex('#FF9900').bold('Lambda')} functions in a dev or staging environment first. Should the instrumentation result be unsatisfactory, run \`${chalk_1.bold('uninstrument')}\` with the same arguments to revert the changes.
|
|
334
|
+
Will apply the following updates:
|
|
335
|
+
UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
|
|
336
|
+
{
|
|
337
|
+
\\"FunctionName\\": \\"arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\\",
|
|
338
|
+
\\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
|
|
339
|
+
\\"Environment\\": {
|
|
340
|
+
\\"Variables\\": {
|
|
341
|
+
\\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
|
|
342
|
+
\\"DD_API_KEY\\": \\"1234\\",
|
|
343
|
+
\\"DD_SITE\\": \\"datadoghq.com\\",
|
|
344
|
+
\\"DD_ENV\\": \\"dummy\\",
|
|
345
|
+
\\"DD_TAGS\\": \\"git.commit.sha:1be168ff837f043bde17c0314341c84271047b31\\",
|
|
346
|
+
\\"DD_FLUSH_TO_LOG\\": \\"true\\",
|
|
347
|
+
\\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
|
|
348
|
+
\\"DD_SERVICE\\": \\"dummy\\",
|
|
349
|
+
\\"DD_TRACE_ENABLED\\": \\"true\\",
|
|
350
|
+
\\"DD_VERSION\\": \\"0.1\\"
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
\\"Layers\\": [
|
|
354
|
+
\\"arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Node12-x:10\\"
|
|
355
|
+
]
|
|
356
|
+
}
|
|
357
|
+
TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
|
|
358
|
+
{
|
|
359
|
+
\\"dd_sls_ci\\": \\"v${version}\\"
|
|
360
|
+
}
|
|
361
|
+
"
|
|
362
|
+
`);
|
|
363
|
+
}));
|
|
364
|
+
test('ensure the instrument command ran from a local git repo ahead of the origin fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
365
|
+
;
|
|
366
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
367
|
+
const lambda = fixtures_1.makeMockLambda({
|
|
368
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
369
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
370
|
+
Handler: 'index.handler',
|
|
371
|
+
Runtime: 'nodejs12.x',
|
|
372
|
+
},
|
|
373
|
+
});
|
|
374
|
+
aws_sdk_1.Lambda.mockImplementation(() => lambda);
|
|
375
|
+
process.env.DATADOG_API_KEY = '1234';
|
|
376
|
+
const context = fixtures_1.createMockContext();
|
|
377
|
+
const instrumentCommand = instrument_1.InstrumentCommand;
|
|
378
|
+
const mockGitStatus = jest.spyOn(instrumentCommand.prototype, 'getCurrentGitStatus');
|
|
379
|
+
mockGitStatus.mockImplementation(() => ({
|
|
380
|
+
ahead: 1,
|
|
381
|
+
isClean: true,
|
|
382
|
+
}));
|
|
383
|
+
const cli = new advanced_1.Cli();
|
|
384
|
+
cli.register(instrumentCommand);
|
|
385
|
+
yield cli.run([
|
|
386
|
+
'lambda',
|
|
387
|
+
'instrument',
|
|
388
|
+
'--function',
|
|
389
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
390
|
+
'--layerVersion',
|
|
391
|
+
'10',
|
|
392
|
+
'-s',
|
|
393
|
+
'--service',
|
|
394
|
+
'dummy',
|
|
395
|
+
'--env',
|
|
396
|
+
'dummy',
|
|
397
|
+
'--version',
|
|
398
|
+
'0.1',
|
|
399
|
+
], context);
|
|
400
|
+
const output = context.stdout.toString();
|
|
401
|
+
expect(output).toMatch('Error: Local changes have not been pushed remotely. Aborting git upload.');
|
|
402
|
+
}));
|
|
214
403
|
test('runs function update command for lambda library layer', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
215
404
|
;
|
|
216
405
|
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
217
|
-
const lambda = makeMockLambda({
|
|
406
|
+
const lambda = fixtures_1.makeMockLambda({
|
|
218
407
|
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
219
408
|
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
220
409
|
Handler: 'index.handler',
|
|
@@ -222,8 +411,8 @@ describe('lambda', () => {
|
|
|
222
411
|
},
|
|
223
412
|
});
|
|
224
413
|
aws_sdk_1.Lambda.mockImplementation(() => lambda);
|
|
225
|
-
const cli = makeCli();
|
|
226
|
-
const context = createMockContext();
|
|
414
|
+
const cli = fixtures_1.makeCli();
|
|
415
|
+
const context = fixtures_1.createMockContext();
|
|
227
416
|
yield cli.run([
|
|
228
417
|
'lambda',
|
|
229
418
|
'instrument',
|
|
@@ -237,7 +426,7 @@ describe('lambda', () => {
|
|
|
237
426
|
test('runs function update command for lambda extension layer', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
238
427
|
;
|
|
239
428
|
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
240
|
-
const lambda = makeMockLambda({
|
|
429
|
+
const lambda = fixtures_1.makeMockLambda({
|
|
241
430
|
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
242
431
|
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
243
432
|
Handler: 'index.handler',
|
|
@@ -245,8 +434,8 @@ describe('lambda', () => {
|
|
|
245
434
|
},
|
|
246
435
|
});
|
|
247
436
|
aws_sdk_1.Lambda.mockImplementation(() => lambda);
|
|
248
|
-
const cli = makeCli();
|
|
249
|
-
const context = createMockContext();
|
|
437
|
+
const cli = fixtures_1.makeCli();
|
|
438
|
+
const context = fixtures_1.createMockContext();
|
|
250
439
|
process.env.DATADOG_API_KEY = '1234';
|
|
251
440
|
yield cli.run([
|
|
252
441
|
'lambda',
|
|
@@ -261,9 +450,9 @@ describe('lambda', () => {
|
|
|
261
450
|
test('aborts early when no functions are specified', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
262
451
|
;
|
|
263
452
|
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
264
|
-
aws_sdk_1.Lambda.mockImplementation(() => makeMockLambda({}));
|
|
265
|
-
const cli = makeCli();
|
|
266
|
-
const context = createMockContext();
|
|
453
|
+
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
|
|
454
|
+
const cli = fixtures_1.makeCli();
|
|
455
|
+
const context = fixtures_1.createMockContext();
|
|
267
456
|
const code = yield cli.run([
|
|
268
457
|
'lambda',
|
|
269
458
|
'instrument',
|
|
@@ -287,7 +476,7 @@ describe('lambda', () => {
|
|
|
287
476
|
;
|
|
288
477
|
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
289
478
|
process.env = {};
|
|
290
|
-
const command = createCommand();
|
|
479
|
+
const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
291
480
|
command['config']['layerVersion'] = '60';
|
|
292
481
|
command['config']['extensionVersion'] = '10';
|
|
293
482
|
command['config']['region'] = 'ap-southeast-1';
|
|
@@ -304,9 +493,9 @@ describe('lambda', () => {
|
|
|
304
493
|
test("aborts early when function regions can't be found", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
305
494
|
;
|
|
306
495
|
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
307
|
-
aws_sdk_1.Lambda.mockImplementation(() => makeMockLambda({}));
|
|
308
|
-
const cli = makeCli();
|
|
309
|
-
const context = createMockContext();
|
|
496
|
+
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
|
|
497
|
+
const cli = fixtures_1.makeCli();
|
|
498
|
+
const context = fixtures_1.createMockContext();
|
|
310
499
|
const code = yield cli.run([
|
|
311
500
|
'lambda',
|
|
312
501
|
'instrument',
|
|
@@ -323,15 +512,12 @@ describe('lambda', () => {
|
|
|
323
512
|
], context);
|
|
324
513
|
const output = context.stdout.toString();
|
|
325
514
|
expect(code).toBe(1);
|
|
326
|
-
expect(output).
|
|
327
|
-
"'No default region specified for [\\"my-func\\"]. Use -r,--region, or use a full functionARN
|
|
328
|
-
"
|
|
329
|
-
`);
|
|
515
|
+
expect(output).toMatch(`Couldn't group functions. Error: No default region specified for ["my-func"]. Use -r, --region, or use a full functionARN\n`);
|
|
330
516
|
}));
|
|
331
517
|
test('aborts if a function is not in an Active state with LastUpdateStatus Successful', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
332
518
|
;
|
|
333
519
|
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
334
|
-
aws_sdk_1.Lambda.mockImplementation(() => makeMockLambda({
|
|
520
|
+
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
|
|
335
521
|
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
336
522
|
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
337
523
|
Handler: 'index.handler',
|
|
@@ -340,8 +526,8 @@ describe('lambda', () => {
|
|
|
340
526
|
State: 'Failed',
|
|
341
527
|
},
|
|
342
528
|
}));
|
|
343
|
-
const cli = makeCli();
|
|
344
|
-
const context = createMockContext();
|
|
529
|
+
const cli = fixtures_1.makeCli();
|
|
530
|
+
const context = fixtures_1.createMockContext();
|
|
345
531
|
const code = yield cli.run([
|
|
346
532
|
'lambda',
|
|
347
533
|
'instrument',
|
|
@@ -366,9 +552,9 @@ describe('lambda', () => {
|
|
|
366
552
|
test('aborts early when extensionVersion and forwarder are set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
367
553
|
;
|
|
368
554
|
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
369
|
-
aws_sdk_1.Lambda.mockImplementation(() => makeMockLambda({}));
|
|
370
|
-
const cli = makeCli();
|
|
371
|
-
const context = createMockContext();
|
|
555
|
+
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
|
|
556
|
+
const cli = fixtures_1.makeCli();
|
|
557
|
+
const context = fixtures_1.createMockContext();
|
|
372
558
|
const code = yield cli.run([
|
|
373
559
|
'lambda',
|
|
374
560
|
'instrument',
|
|
@@ -398,7 +584,7 @@ describe('lambda', () => {
|
|
|
398
584
|
;
|
|
399
585
|
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
400
586
|
process.env = {};
|
|
401
|
-
const command = createCommand();
|
|
587
|
+
const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
402
588
|
command['config']['layerVersion'] = '60';
|
|
403
589
|
command['config']['extensionVersion'] = '10';
|
|
404
590
|
command['config']['region'] = 'ap-southeast-1';
|
|
@@ -410,7 +596,7 @@ describe('lambda', () => {
|
|
|
410
596
|
;
|
|
411
597
|
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
412
598
|
process.env = {};
|
|
413
|
-
let command = createCommand();
|
|
599
|
+
let command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
414
600
|
command['config']['environment'] = 'staging';
|
|
415
601
|
command['config']['service'] = 'middletier';
|
|
416
602
|
command['config']['version'] = '2';
|
|
@@ -420,7 +606,7 @@ describe('lambda', () => {
|
|
|
420
606
|
yield command['execute']();
|
|
421
607
|
let output = command.context.stdout.toString();
|
|
422
608
|
expect(output).toMatch('Functions in config file and "--functions-regex" should not be used at the same time.\n');
|
|
423
|
-
command = createCommand();
|
|
609
|
+
command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
424
610
|
command['environment'] = 'staging';
|
|
425
611
|
command['service'] = 'middletier';
|
|
426
612
|
command['version'] = '2';
|
|
@@ -435,7 +621,7 @@ describe('lambda', () => {
|
|
|
435
621
|
;
|
|
436
622
|
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
437
623
|
process.env = {};
|
|
438
|
-
const command = createCommand();
|
|
624
|
+
const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
439
625
|
command['environment'] = 'staging';
|
|
440
626
|
command['service'] = 'middletier';
|
|
441
627
|
command['version'] = '2';
|
|
@@ -449,7 +635,7 @@ describe('lambda', () => {
|
|
|
449
635
|
describe('getSettings', () => {
|
|
450
636
|
test('uses config file settings', () => {
|
|
451
637
|
process.env = {};
|
|
452
|
-
const command = createCommand();
|
|
638
|
+
const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
453
639
|
command['config']['flushMetricsToLogs'] = 'false';
|
|
454
640
|
command['config']['forwarder'] = 'my-forwarder';
|
|
455
641
|
command['config']['layerVersion'] = '2';
|
|
@@ -471,7 +657,7 @@ describe('lambda', () => {
|
|
|
471
657
|
});
|
|
472
658
|
test('prefers command line arguments over config file', () => {
|
|
473
659
|
process.env = {};
|
|
474
|
-
const command = createCommand();
|
|
660
|
+
const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
475
661
|
command['forwarder'] = 'my-forwarder';
|
|
476
662
|
command['config']['forwarder'] = 'another-forwarder';
|
|
477
663
|
command['layerVersion'] = '1';
|
|
@@ -498,7 +684,7 @@ describe('lambda', () => {
|
|
|
498
684
|
});
|
|
499
685
|
test("returns undefined when layer version can't be parsed", () => {
|
|
500
686
|
process.env = {};
|
|
501
|
-
const command = createCommand();
|
|
687
|
+
const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
502
688
|
command.context = {
|
|
503
689
|
stdout: { write: jest.fn() },
|
|
504
690
|
};
|
|
@@ -507,7 +693,7 @@ describe('lambda', () => {
|
|
|
507
693
|
});
|
|
508
694
|
test("returns undefined when extension version can't be parsed", () => {
|
|
509
695
|
process.env = {};
|
|
510
|
-
const command = createCommand();
|
|
696
|
+
const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
511
697
|
command.context = {
|
|
512
698
|
stdout: { write: jest.fn() },
|
|
513
699
|
};
|
|
@@ -516,7 +702,7 @@ describe('lambda', () => {
|
|
|
516
702
|
});
|
|
517
703
|
test('converts string boolean from command line and config file correctly', () => {
|
|
518
704
|
process.env = {};
|
|
519
|
-
const command = createCommand();
|
|
705
|
+
const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
520
706
|
const validSettings = {
|
|
521
707
|
extensionVersion: undefined,
|
|
522
708
|
flushMetricsToLogs: false,
|
|
@@ -555,12 +741,12 @@ describe('lambda', () => {
|
|
|
555
741
|
'tracing',
|
|
556
742
|
];
|
|
557
743
|
for (const option of stringBooleans) {
|
|
558
|
-
let command = createCommand();
|
|
744
|
+
let command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
559
745
|
command['config'][option] = 'NotBoolean';
|
|
560
746
|
command['getSettings']();
|
|
561
747
|
let output = command.context.stdout.toString();
|
|
562
748
|
expect(output).toMatch(`Invalid boolean specified for ${option}.\n`);
|
|
563
|
-
command = createCommand();
|
|
749
|
+
command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
564
750
|
command[option] = 'NotBoolean';
|
|
565
751
|
command['getSettings']();
|
|
566
752
|
output = command.context.stdout.toString();
|
|
@@ -571,26 +757,26 @@ describe('lambda', () => {
|
|
|
571
757
|
;
|
|
572
758
|
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
573
759
|
process.env = {};
|
|
574
|
-
let command = createCommand();
|
|
760
|
+
let command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
575
761
|
command['config']['region'] = 'ap-southeast-1';
|
|
576
762
|
command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
|
|
577
763
|
yield command['getSettings']();
|
|
578
764
|
let output = command.context.stdout.toString();
|
|
579
|
-
expect(output).toMatch('Warning
|
|
580
|
-
command = createCommand();
|
|
765
|
+
expect(output).toMatch(`${chalk_1.bold(chalk_1.yellow('[Warning]'))} The environment, service and version tags have not been configured. Learn more about Datadog unified service tagging: ${chalk_1.underline(chalk_1.blueBright('https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/#serverless-environment.'))}\n`);
|
|
766
|
+
command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
581
767
|
command['config']['region'] = 'ap-southeast-1';
|
|
582
768
|
command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
|
|
583
769
|
command['config']['environment'] = 'b';
|
|
584
770
|
command['config']['service'] = 'middletier';
|
|
585
771
|
yield command['getSettings']();
|
|
586
772
|
output = command.context.stdout.toString();
|
|
587
|
-
expect(output).toMatch('Warning
|
|
773
|
+
expect(output).toMatch(`${chalk_1.bold(chalk_1.yellow('[Warning]'))} The version tag has not been configured. Learn more about Datadog unified service tagging: ${chalk_1.underline(chalk_1.blueBright('https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/#serverless-environment.'))}\n`);
|
|
588
774
|
}));
|
|
589
775
|
test('aborts early if extraTags do not comply with expected key:value list', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
590
776
|
;
|
|
591
777
|
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
592
778
|
process.env = {};
|
|
593
|
-
const command = createCommand();
|
|
779
|
+
const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
594
780
|
command['config']['region'] = 'ap-southeast-1';
|
|
595
781
|
command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
|
|
596
782
|
command['config']['service'] = 'middletier';
|
|
@@ -602,83 +788,21 @@ describe('lambda', () => {
|
|
|
602
788
|
expect(output).toMatch('Extra tags do not comply with the <key>:<value> array.\n');
|
|
603
789
|
}));
|
|
604
790
|
});
|
|
605
|
-
describe('collectFunctionsByRegion', () => {
|
|
606
|
-
test('groups functions with region read from arn', () => {
|
|
607
|
-
process.env = {};
|
|
608
|
-
const command = createCommand();
|
|
609
|
-
command['functions'] = [
|
|
610
|
-
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
611
|
-
'arn:aws:lambda:us-east-1:123456789012:function:another',
|
|
612
|
-
'arn:aws:lambda:us-east-2:123456789012:function:third-func',
|
|
613
|
-
];
|
|
614
|
-
expect(command['collectFunctionsByRegion']()).toEqual({
|
|
615
|
-
'us-east-1': [
|
|
616
|
-
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
617
|
-
'arn:aws:lambda:us-east-1:123456789012:function:another',
|
|
618
|
-
],
|
|
619
|
-
'us-east-2': ['arn:aws:lambda:us-east-2:123456789012:function:third-func'],
|
|
620
|
-
});
|
|
621
|
-
});
|
|
622
|
-
test('groups functions in the config object', () => {
|
|
623
|
-
process.env = {};
|
|
624
|
-
const command = createCommand();
|
|
625
|
-
command['config'].functions = [
|
|
626
|
-
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
627
|
-
'arn:aws:lambda:us-east-1:123456789012:function:another',
|
|
628
|
-
'arn:aws:lambda:us-east-2:123456789012:function:third-func',
|
|
629
|
-
];
|
|
630
|
-
expect(command['collectFunctionsByRegion']()).toEqual({
|
|
631
|
-
'us-east-1': [
|
|
632
|
-
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
633
|
-
'arn:aws:lambda:us-east-1:123456789012:function:another',
|
|
634
|
-
],
|
|
635
|
-
'us-east-2': ['arn:aws:lambda:us-east-2:123456789012:function:third-func'],
|
|
636
|
-
});
|
|
637
|
-
});
|
|
638
|
-
test('uses default region for functions not in arn format', () => {
|
|
639
|
-
process.env = {};
|
|
640
|
-
const command = createCommand();
|
|
641
|
-
command['functions'] = [
|
|
642
|
-
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
643
|
-
'arn:aws:lambda:*:123456789012:function:func-with-wildcard',
|
|
644
|
-
'func-without-region',
|
|
645
|
-
'arn:aws:lambda:us-east-2:123456789012:function:third-func',
|
|
646
|
-
];
|
|
647
|
-
command['region'] = 'ap-south-1';
|
|
648
|
-
expect(command['collectFunctionsByRegion']()).toEqual({
|
|
649
|
-
'ap-south-1': ['arn:aws:lambda:*:123456789012:function:func-with-wildcard', 'func-without-region'],
|
|
650
|
-
'us-east-1': ['arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world'],
|
|
651
|
-
'us-east-2': ['arn:aws:lambda:us-east-2:123456789012:function:third-func'],
|
|
652
|
-
});
|
|
653
|
-
});
|
|
654
|
-
test('fails to collect when there are regionless functions and no default region is set', () => {
|
|
655
|
-
process.env = {};
|
|
656
|
-
const command = createCommand();
|
|
657
|
-
command['functions'] = [
|
|
658
|
-
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
659
|
-
'arn:aws:lambda:*:123456789012:function:func-with-wildcard',
|
|
660
|
-
'func-without-region',
|
|
661
|
-
'arn:aws:lambda:us-east-2:123456789012:function:third-func',
|
|
662
|
-
];
|
|
663
|
-
command['region'] = undefined;
|
|
664
|
-
command['config']['region'] = undefined;
|
|
665
|
-
expect(command['collectFunctionsByRegion']()).toBeUndefined();
|
|
666
|
-
});
|
|
667
|
-
});
|
|
668
791
|
describe('printPlannedActions', () => {
|
|
669
792
|
test('prints no output when list is empty', () => {
|
|
670
793
|
process.env = {};
|
|
671
|
-
const command = createCommand();
|
|
794
|
+
const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
672
795
|
command['printPlannedActions']([]);
|
|
673
796
|
const output = command.context.stdout.toString();
|
|
674
797
|
expect(output).toMatchInlineSnapshot(`
|
|
675
|
-
"
|
|
798
|
+
"
|
|
799
|
+
No updates will be applied
|
|
676
800
|
"
|
|
677
801
|
`);
|
|
678
802
|
});
|
|
679
803
|
test('prints log group actions', () => {
|
|
680
804
|
process.env = {};
|
|
681
|
-
const command = createCommand();
|
|
805
|
+
const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
682
806
|
command['printPlannedActions']([
|
|
683
807
|
{
|
|
684
808
|
functionARN: 'my-func',
|
|
@@ -694,7 +818,8 @@ describe('lambda', () => {
|
|
|
694
818
|
]);
|
|
695
819
|
const output = command.context.stdout.toString();
|
|
696
820
|
expect(output).toMatchInlineSnapshot(`
|
|
697
|
-
"
|
|
821
|
+
"${chalk_1.bold(chalk_1.yellow('[Warning]'))} Instrument your ${chalk_1.hex('#FF9900').bold('Lambda')} functions in a dev or staging environment first. Should the instrumentation result be unsatisfactory, run \`${chalk_1.bold('uninstrument')}\` with the same arguments to revert the changes.
|
|
822
|
+
Will apply the following updates:
|
|
698
823
|
CreateLogGroup -> my-log-group
|
|
699
824
|
{
|
|
700
825
|
\\"logGroupName\\": \\"my-log-group\\"
|
|
@@ -711,23 +836,5 @@ describe('lambda', () => {
|
|
|
711
836
|
`);
|
|
712
837
|
});
|
|
713
838
|
});
|
|
714
|
-
describe('sentenceMatchesRegEx', () => {
|
|
715
|
-
const tags = [
|
|
716
|
-
['not-complying:regex-should-fail', false],
|
|
717
|
-
['1first-char-is-number:should-fail', false],
|
|
718
|
-
['_also-not-complying:should-fail', false],
|
|
719
|
-
['complying_tag:accepted/with/slashes.and.dots,but-empty-tag', false],
|
|
720
|
-
['also_complying:success,1but_is_illegal:should-fail', false],
|
|
721
|
-
['this:complies,also_this_one:yes,numb3r_in_name:should-succeed,dots:al.lo.wed', true],
|
|
722
|
-
['complying_ip_address_4:192.342.3134.231', true],
|
|
723
|
-
['complying:alone', true],
|
|
724
|
-
['one_divided_by_two:1/2,one_divided_by_four:0.25,three_minus_one_half:3-1/2', true],
|
|
725
|
-
['this_is_a_valid_t4g:yes/it.is-42', true],
|
|
726
|
-
];
|
|
727
|
-
test.each(tags)('check if the tags match the expected result from the regex', (tag, expectedResult) => {
|
|
728
|
-
const result = !!instrument_1.sentenceMatchesRegEx(tag, constants_1.EXTRA_TAGS_REG_EXP);
|
|
729
|
-
expect(result).toEqual(expectedResult);
|
|
730
|
-
});
|
|
731
|
-
});
|
|
732
839
|
});
|
|
733
840
|
});
|