@datadog/datadog-ci 0.17.9 → 0.17.13
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/LICENSE-3rdparty.csv +2 -0
- package/README.md +9 -2
- package/dist/{commands/dependencies/index.d.ts → cli.d.ts} +0 -0
- package/dist/cli.js +34 -0
- package/dist/commands/{dsyms/index.d.ts → dependencies/cli.d.ts} +0 -0
- package/dist/commands/dependencies/{index.js → cli.js} +0 -0
- package/dist/commands/dependencies/upload.d.ts +1 -1
- package/dist/commands/{git-metadata/index.d.ts → dsyms/cli.d.ts} +0 -0
- package/dist/commands/dsyms/{index.js → cli.js} +0 -0
- package/dist/commands/dsyms/upload.d.ts +1 -1
- package/dist/commands/{junit/index.d.ts → git-metadata/cli.d.ts} +0 -0
- package/dist/commands/git-metadata/{index.js → cli.js} +0 -0
- package/dist/commands/git-metadata/upload.d.ts +1 -1
- package/dist/commands/git-metadata/upload.js +6 -1
- package/dist/commands/{lambda/index.d.ts → junit/cli.d.ts} +0 -0
- package/dist/commands/junit/{index.js → cli.js} +0 -0
- package/dist/commands/junit/upload.d.ts +1 -1
- package/dist/commands/junit/upload.js +1 -1
- package/dist/commands/lambda/__tests__/fixtures.d.ts +5 -1
- package/dist/commands/lambda/__tests__/fixtures.js +13 -2
- package/dist/commands/lambda/__tests__/functions/commons.test.js +400 -0
- package/dist/commands/lambda/__tests__/functions/instrument.test.js +229 -117
- package/dist/commands/lambda/__tests__/functions/uninstrument.test.js +80 -7
- package/dist/commands/lambda/__tests__/instrument.test.js +542 -111
- package/dist/commands/{sourcemaps/index.d.ts → lambda/__tests__/prompt.test.d.ts} +0 -0
- package/dist/commands/lambda/__tests__/prompt.test.js +216 -0
- package/dist/commands/lambda/__tests__/uninstrument.test.js +381 -17
- package/dist/commands/{trace/index.d.ts → lambda/cli.d.ts} +0 -0
- package/dist/commands/lambda/{index.js → cli.js} +0 -0
- package/dist/commands/lambda/constants.d.ts +27 -6
- package/dist/commands/lambda/constants.js +63 -6
- package/dist/commands/lambda/functions/commons.d.ts +49 -4
- package/dist/commands/lambda/functions/commons.js +198 -7
- package/dist/commands/lambda/functions/instrument.d.ts +5 -14
- package/dist/commands/lambda/functions/instrument.js +63 -80
- package/dist/commands/lambda/functions/uninstrument.d.ts +3 -2
- package/dist/commands/lambda/functions/uninstrument.js +23 -11
- package/dist/commands/lambda/instrument.d.ts +2 -1
- package/dist/commands/lambda/instrument.js +112 -58
- package/dist/commands/lambda/interfaces.d.ts +4 -1
- package/dist/commands/lambda/loggroup.js +3 -1
- package/dist/commands/lambda/prompt.d.ts +9 -0
- package/dist/commands/lambda/prompt.js +187 -0
- package/dist/commands/lambda/uninstrument.d.ts +2 -0
- package/dist/commands/lambda/uninstrument.js +107 -30
- package/dist/commands/sourcemaps/cli.d.ts +1 -0
- package/dist/commands/sourcemaps/{index.js → cli.js} +0 -0
- package/dist/commands/sourcemaps/upload.d.ts +1 -1
- package/dist/commands/synthetics/__tests__/cli.test.js +36 -13
- package/dist/commands/synthetics/__tests__/fixtures.js +1 -0
- package/dist/commands/synthetics/__tests__/run-test.test.js +48 -2
- package/dist/commands/synthetics/__tests__/utils.test.js +11 -4
- package/dist/commands/synthetics/__tests__/websocket.test.js +3 -3
- package/dist/commands/synthetics/cli.d.ts +1 -26
- package/dist/commands/synthetics/cli.js +2 -227
- package/dist/commands/synthetics/command.d.ts +27 -0
- package/dist/commands/synthetics/command.js +236 -0
- package/dist/commands/synthetics/index.d.ts +5 -1
- package/dist/commands/synthetics/index.js +31 -2
- package/dist/commands/synthetics/interfaces.d.ts +8 -3
- package/dist/commands/synthetics/interfaces.js +7 -3
- package/dist/commands/synthetics/reporters/default.js +5 -1
- package/dist/commands/synthetics/run-test.js +3 -1
- package/dist/commands/synthetics/utils.d.ts +3 -3
- package/dist/commands/synthetics/utils.js +17 -8
- package/dist/commands/trace/api.js +1 -1
- package/dist/commands/trace/cli.d.ts +1 -0
- package/dist/commands/trace/{index.js → cli.js} +0 -0
- package/dist/commands/trace/trace.d.ts +1 -1
- package/dist/helpers/__tests__/ci.test.js +97 -136
- package/dist/helpers/__tests__/user-provided-git.test.js +81 -27
- package/dist/helpers/__tests__/utils.test.js +4 -0
- package/dist/helpers/ci.js +54 -95
- package/dist/helpers/interfaces.d.ts +28 -2
- package/dist/helpers/user-provided-git.d.ts +2 -1
- package/dist/helpers/user-provided-git.js +29 -5
- package/dist/helpers/utils.d.ts +4 -0
- package/dist/helpers/utils.js +18 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +23 -31
- package/package.json +10 -8
|
@@ -34,12 +34,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
34
34
|
// tslint:disable: no-string-literal
|
|
35
35
|
jest.mock('fs');
|
|
36
36
|
jest.mock('aws-sdk');
|
|
37
|
+
jest.mock('../prompt');
|
|
37
38
|
const aws_sdk_1 = require("aws-sdk");
|
|
38
39
|
const chalk_1 = require("chalk");
|
|
39
40
|
const advanced_1 = require("clipanion/lib/advanced");
|
|
40
41
|
const fs = __importStar(require("fs"));
|
|
41
42
|
const path_1 = __importDefault(require("path"));
|
|
43
|
+
const constants_1 = require("../constants");
|
|
42
44
|
const instrument_1 = require("../instrument");
|
|
45
|
+
const prompt_1 = require("../prompt");
|
|
43
46
|
const fixtures_1 = require("./fixtures");
|
|
44
47
|
// tslint:disable-next-line
|
|
45
48
|
const { version } = require(path_1.default.join(__dirname, '../../../../package.json'));
|
|
@@ -89,36 +92,116 @@ describe('lambda', () => {
|
|
|
89
92
|
const output = context.stdout.toString();
|
|
90
93
|
expect(code).toBe(0);
|
|
91
94
|
expect(output).toMatchInlineSnapshot(`
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
95
|
+
"${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.
|
|
96
|
+
\n${chalk_1.bold(chalk_1.yellow('[!]'))} Functions to be updated:
|
|
97
|
+
\t- ${chalk_1.bold('arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world')}\n
|
|
98
|
+
${chalk_1.bold(chalk_1.cyan('[Dry Run] '))}Will apply the following updates:
|
|
99
|
+
UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
|
|
100
|
+
{
|
|
101
|
+
\\"FunctionName\\": \\"arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\\",
|
|
102
|
+
\\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
|
|
103
|
+
\\"Environment\\": {
|
|
104
|
+
\\"Variables\\": {
|
|
105
|
+
\\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
|
|
106
|
+
\\"DD_SITE\\": \\"datadoghq.com\\",
|
|
107
|
+
\\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
|
|
108
|
+
\\"DD_ENV\\": \\"staging\\",
|
|
109
|
+
\\"DD_TAGS\\": \\"layer:api,team:intake\\",
|
|
110
|
+
\\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
|
|
111
|
+
\\"DD_SERVICE\\": \\"middletier\\",
|
|
112
|
+
\\"DD_TRACE_ENABLED\\": \\"true\\",
|
|
113
|
+
\\"DD_VERSION\\": \\"0.2\\",
|
|
114
|
+
\\"DD_FLUSH_TO_LOG\\": \\"true\\",
|
|
115
|
+
\\"DD_LOG_LEVEL\\": \\"debug\\"
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
\\"Layers\\": [
|
|
119
|
+
\\"arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Node12-x:10\\"
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
|
|
123
|
+
{
|
|
124
|
+
\\"dd_sls_ci\\": \\"v${version}\\"
|
|
125
|
+
}
|
|
126
|
+
"
|
|
127
|
+
`);
|
|
128
|
+
}));
|
|
129
|
+
test('prints dry run data for lambda library and extension layers using kebab case args', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
130
|
+
;
|
|
131
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
132
|
+
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
|
|
133
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
134
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
135
|
+
Handler: 'index.handler',
|
|
136
|
+
Runtime: 'nodejs12.x',
|
|
137
|
+
},
|
|
138
|
+
}));
|
|
139
|
+
const cli = fixtures_1.makeCli();
|
|
140
|
+
const context = fixtures_1.createMockContext();
|
|
141
|
+
const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
|
|
142
|
+
process.env.DATADOG_API_KEY = '1234';
|
|
143
|
+
const code = yield cli.run([
|
|
144
|
+
'lambda',
|
|
145
|
+
'instrument',
|
|
146
|
+
'-f',
|
|
147
|
+
functionARN,
|
|
148
|
+
'--dry',
|
|
149
|
+
'--service',
|
|
150
|
+
'middletier',
|
|
151
|
+
'--env',
|
|
152
|
+
'staging',
|
|
153
|
+
'--version',
|
|
154
|
+
'0.2',
|
|
155
|
+
'--extra-tags',
|
|
156
|
+
'layer:api,team:intake',
|
|
157
|
+
'--layer-version',
|
|
158
|
+
'10',
|
|
159
|
+
'--extension-version',
|
|
160
|
+
'5',
|
|
161
|
+
'--merge-xray-traces',
|
|
162
|
+
'true',
|
|
163
|
+
'--flush-metrics-to-logs',
|
|
164
|
+
'false',
|
|
165
|
+
'--log-level',
|
|
166
|
+
'debug',
|
|
167
|
+
], context);
|
|
168
|
+
const output = context.stdout.toString();
|
|
169
|
+
expect(code).toBe(0);
|
|
170
|
+
expect(output).toMatchInlineSnapshot(`
|
|
171
|
+
"${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.
|
|
172
|
+
\n${chalk_1.bold(chalk_1.yellow('[!]'))} Functions to be updated:
|
|
173
|
+
\t- ${chalk_1.bold('arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world')}\n
|
|
174
|
+
${chalk_1.bold(chalk_1.cyan('[Dry Run] '))}Will apply the following updates:
|
|
175
|
+
UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
|
|
176
|
+
{
|
|
177
|
+
\\"FunctionName\\": \\"arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\\",
|
|
178
|
+
\\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
|
|
179
|
+
\\"Environment\\": {
|
|
180
|
+
\\"Variables\\": {
|
|
181
|
+
\\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
|
|
182
|
+
\\"DD_API_KEY\\": \\"1234\\",
|
|
183
|
+
\\"DD_SITE\\": \\"datadoghq.com\\",
|
|
184
|
+
\\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
|
|
185
|
+
\\"DD_ENV\\": \\"staging\\",
|
|
186
|
+
\\"DD_TAGS\\": \\"layer:api,team:intake\\",
|
|
187
|
+
\\"DD_MERGE_XRAY_TRACES\\": \\"true\\",
|
|
188
|
+
\\"DD_SERVICE\\": \\"middletier\\",
|
|
189
|
+
\\"DD_TRACE_ENABLED\\": \\"true\\",
|
|
190
|
+
\\"DD_VERSION\\": \\"0.2\\",
|
|
191
|
+
\\"DD_LOG_LEVEL\\": \\"debug\\"
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
\\"Layers\\": [
|
|
195
|
+
\\"arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Extension:5\\",
|
|
196
|
+
\\"arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Node12-x:10\\"
|
|
197
|
+
]
|
|
198
|
+
}
|
|
199
|
+
TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
|
|
200
|
+
{
|
|
201
|
+
\\"dd_sls_ci\\": \\"v${version}\\"
|
|
202
|
+
}
|
|
203
|
+
"
|
|
204
|
+
`);
|
|
122
205
|
}));
|
|
123
206
|
test('prints dry run data for lambda extension layer', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
124
207
|
;
|
|
@@ -154,36 +237,38 @@ describe('lambda', () => {
|
|
|
154
237
|
const output = context.stdout.toString();
|
|
155
238
|
expect(code).toBe(0);
|
|
156
239
|
expect(output).toMatchInlineSnapshot(`
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
240
|
+
"${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.
|
|
241
|
+
\n${chalk_1.bold(chalk_1.yellow('[!]'))} Functions to be updated:
|
|
242
|
+
\t- ${chalk_1.bold('arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world')}\n
|
|
243
|
+
${chalk_1.bold(chalk_1.cyan('[Dry Run] '))}Will apply the following updates:
|
|
244
|
+
UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
|
|
245
|
+
{
|
|
246
|
+
\\"FunctionName\\": \\"arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\\",
|
|
247
|
+
\\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
|
|
248
|
+
\\"Environment\\": {
|
|
249
|
+
\\"Variables\\": {
|
|
250
|
+
\\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
|
|
251
|
+
\\"DD_API_KEY\\": \\"1234\\",
|
|
252
|
+
\\"DD_SITE\\": \\"datadoghq.com\\",
|
|
253
|
+
\\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
|
|
254
|
+
\\"DD_ENV\\": \\"staging\\",
|
|
255
|
+
\\"DD_TAGS\\": \\"layer:api,team:intake\\",
|
|
256
|
+
\\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
|
|
257
|
+
\\"DD_SERVICE\\": \\"middletier\\",
|
|
258
|
+
\\"DD_TRACE_ENABLED\\": \\"true\\",
|
|
259
|
+
\\"DD_VERSION\\": \\"0.2\\"
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
\\"Layers\\": [
|
|
263
|
+
\\"arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Extension:6\\"
|
|
264
|
+
]
|
|
265
|
+
}
|
|
266
|
+
TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
|
|
267
|
+
{
|
|
268
|
+
\\"dd_sls_ci\\": \\"v${version}\\"
|
|
269
|
+
}
|
|
270
|
+
"
|
|
271
|
+
`);
|
|
187
272
|
}));
|
|
188
273
|
test('instrumenting with source code integrations fails if not run within a git repo', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
189
274
|
;
|
|
@@ -330,36 +415,39 @@ describe('lambda', () => {
|
|
|
330
415
|
], context);
|
|
331
416
|
const output = context.stdout.toString();
|
|
332
417
|
expect(output).toMatchInlineSnapshot(`
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
418
|
+
"${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.
|
|
419
|
+
\n${chalk_1.bold(chalk_1.yellow('[!]'))} Functions to be updated:
|
|
420
|
+
\t- ${chalk_1.bold('arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world')}\n
|
|
421
|
+
Will apply the following updates:
|
|
422
|
+
UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
|
|
423
|
+
{
|
|
424
|
+
\\"FunctionName\\": \\"arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\\",
|
|
425
|
+
\\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
|
|
426
|
+
\\"Environment\\": {
|
|
427
|
+
\\"Variables\\": {
|
|
428
|
+
\\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
|
|
429
|
+
\\"DD_API_KEY\\": \\"1234\\",
|
|
430
|
+
\\"DD_SITE\\": \\"datadoghq.com\\",
|
|
431
|
+
\\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
|
|
432
|
+
\\"DD_ENV\\": \\"dummy\\",
|
|
433
|
+
\\"DD_TAGS\\": \\"git.commit.sha:1be168ff837f043bde17c0314341c84271047b31\\",
|
|
434
|
+
\\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
|
|
435
|
+
\\"DD_SERVICE\\": \\"dummy\\",
|
|
436
|
+
\\"DD_TRACE_ENABLED\\": \\"true\\",
|
|
437
|
+
\\"DD_VERSION\\": \\"0.1\\",
|
|
438
|
+
\\"DD_FLUSH_TO_LOG\\": \\"true\\"
|
|
439
|
+
}
|
|
440
|
+
},
|
|
441
|
+
\\"Layers\\": [
|
|
442
|
+
\\"arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Node12-x:10\\"
|
|
443
|
+
]
|
|
444
|
+
}
|
|
445
|
+
TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
|
|
446
|
+
{
|
|
447
|
+
\\"dd_sls_ci\\": \\"v${version}\\"
|
|
448
|
+
}
|
|
449
|
+
"
|
|
450
|
+
`);
|
|
363
451
|
}));
|
|
364
452
|
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
453
|
;
|
|
@@ -468,7 +556,7 @@ describe('lambda', () => {
|
|
|
468
556
|
const output = context.stdout.toString();
|
|
469
557
|
expect(code).toBe(1);
|
|
470
558
|
expect(output).toMatchInlineSnapshot(`
|
|
471
|
-
"No functions specified for instrumentation.
|
|
559
|
+
"${chalk_1.red('[Error]')} No functions specified for instrumentation.
|
|
472
560
|
"
|
|
473
561
|
`);
|
|
474
562
|
}));
|
|
@@ -486,7 +574,7 @@ describe('lambda', () => {
|
|
|
486
574
|
yield command['execute']();
|
|
487
575
|
const output = command.context.stdout.toString();
|
|
488
576
|
expect(output).toMatchInlineSnapshot(`
|
|
489
|
-
"No functions specified for instrumentation.
|
|
577
|
+
"${chalk_1.red('[Error]')} No functions specified for instrumentation.
|
|
490
578
|
"
|
|
491
579
|
`);
|
|
492
580
|
}));
|
|
@@ -545,7 +633,7 @@ describe('lambda', () => {
|
|
|
545
633
|
const output = context.stdout.toString();
|
|
546
634
|
expect(code).toBe(1);
|
|
547
635
|
expect(output).toMatchInlineSnapshot(`
|
|
548
|
-
"Couldn't fetch
|
|
636
|
+
"${chalk_1.red('[Error]')} Couldn't fetch Lambda functions. Error: Can't instrument arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world, as current State is Failed (must be \\"Active\\") and Last Update Status is Unsuccessful (must be \\"Successful\\")
|
|
549
637
|
"
|
|
550
638
|
`);
|
|
551
639
|
}));
|
|
@@ -576,7 +664,7 @@ describe('lambda', () => {
|
|
|
576
664
|
const output = context.stdout.toString();
|
|
577
665
|
expect(code).toBe(1);
|
|
578
666
|
expect(output).toMatchInlineSnapshot(`
|
|
579
|
-
"\\"extensionVersion\\" and \\"forwarder\\" should not be used at the same time.
|
|
667
|
+
"${chalk_1.red('[Error]')} \\"extensionVersion\\" and \\"forwarder\\" should not be used at the same time.
|
|
580
668
|
"
|
|
581
669
|
`);
|
|
582
670
|
}));
|
|
@@ -617,6 +705,19 @@ describe('lambda', () => {
|
|
|
617
705
|
output = command.context.stdout.toString();
|
|
618
706
|
expect(output).toMatch('"--functions" and "--functions-regex" should not be used at the same time.\n');
|
|
619
707
|
}));
|
|
708
|
+
test('aborts if pattern is set and no default region is specified', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
709
|
+
;
|
|
710
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
711
|
+
process.env = {};
|
|
712
|
+
const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
713
|
+
command['environment'] = 'staging';
|
|
714
|
+
command['service'] = 'middletier';
|
|
715
|
+
command['version'] = '2';
|
|
716
|
+
command['regExPattern'] = 'valid-pattern';
|
|
717
|
+
yield command['execute']();
|
|
718
|
+
const output = command.context.stdout.toString();
|
|
719
|
+
expect(output).toMatch(`${chalk_1.red('[Error]')} No default region specified. Use \`-r\`, \`--region\`.\n`);
|
|
720
|
+
}));
|
|
620
721
|
test('aborts if the regEx pattern is an ARN', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
621
722
|
;
|
|
622
723
|
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
@@ -631,6 +732,320 @@ describe('lambda', () => {
|
|
|
631
732
|
const output = command.context.stdout.toString();
|
|
632
733
|
expect(output).toMatch(`"--functions-regex" isn't meant to be used with ARNs.\n`);
|
|
633
734
|
}));
|
|
735
|
+
test('instrument multiple functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
736
|
+
const node14LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node14-x`;
|
|
737
|
+
const node12LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node12-x`;
|
|
738
|
+
const extensionLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension`;
|
|
739
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
740
|
+
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
|
|
741
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
|
|
742
|
+
FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
|
|
743
|
+
FunctionName: 'lambda-hello-world',
|
|
744
|
+
Handler: 'index.handler',
|
|
745
|
+
Runtime: 'nodejs12.x',
|
|
746
|
+
},
|
|
747
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2': {
|
|
748
|
+
FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
|
|
749
|
+
FunctionName: 'lambda-hello-world-2',
|
|
750
|
+
Handler: 'index.handler',
|
|
751
|
+
Runtime: 'nodejs14.x',
|
|
752
|
+
},
|
|
753
|
+
}, {
|
|
754
|
+
[`${node14LibraryLayer}:1`]: {
|
|
755
|
+
LayerVersionArn: `${node14LibraryLayer}:1`,
|
|
756
|
+
Version: 1,
|
|
757
|
+
},
|
|
758
|
+
[`${node12LibraryLayer}:1`]: {
|
|
759
|
+
LayerVersionArn: `${node12LibraryLayer}:1`,
|
|
760
|
+
Version: 1,
|
|
761
|
+
},
|
|
762
|
+
[`${extensionLayer}:1`]: {
|
|
763
|
+
LayerVersionArn: `${extensionLayer}:1`,
|
|
764
|
+
Version: 1,
|
|
765
|
+
},
|
|
766
|
+
}));
|
|
767
|
+
prompt_1.requestAWSCredentials.mockImplementation(() => {
|
|
768
|
+
process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_1.mockAwsAccessKeyId;
|
|
769
|
+
process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_1.mockAwsSecretAccessKey;
|
|
770
|
+
process.env[constants_1.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
|
|
771
|
+
});
|
|
772
|
+
prompt_1.requestDatadogEnvVars.mockImplementation(() => {
|
|
773
|
+
process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
|
|
774
|
+
process.env[constants_1.CI_API_KEY_ENV_VAR] = fixtures_1.mockDatadogApiKey;
|
|
775
|
+
});
|
|
776
|
+
prompt_1.requestFunctionSelection.mockImplementation(() => [
|
|
777
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
|
|
778
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
|
|
779
|
+
]);
|
|
780
|
+
prompt_1.requestChangesConfirmation.mockImplementation(() => true);
|
|
781
|
+
const cli = fixtures_1.makeCli();
|
|
782
|
+
const context = fixtures_1.createMockContext();
|
|
783
|
+
const code = yield cli.run(['lambda', 'instrument', '-i'], context);
|
|
784
|
+
const output = context.stdout.toString();
|
|
785
|
+
expect(code).toBe(0);
|
|
786
|
+
expect(output).toMatchInlineSnapshot(`
|
|
787
|
+
"${chalk_1.bold(chalk_1.yellow('[!]'))} No existing AWS credentials found, let's set them up!
|
|
788
|
+
${chalk_1.bold(chalk_1.yellow('[!]'))} Configure Datadog settings.
|
|
789
|
+
Fetching Lambda functions, this might take a while.
|
|
790
|
+
${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.'))}
|
|
791
|
+
${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.\n
|
|
792
|
+
${chalk_1.bold(chalk_1.yellow('[!]'))} Functions to be updated:
|
|
793
|
+
\t- ${chalk_1.bold('arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world')}
|
|
794
|
+
\t${chalk_1.bold(chalk_1.yellow('[Warning]'))} At least one latest layer version is being used. Ensure to lock in versions for production applications using \`--layerVersion\` and \`--extensionVersion\`.
|
|
795
|
+
\t- ${chalk_1.bold('arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2')}
|
|
796
|
+
\t${chalk_1.bold(chalk_1.yellow('[Warning]'))} At least one latest layer version is being used. Ensure to lock in versions for production applications using \`--layerVersion\` and \`--extensionVersion\`.\n
|
|
797
|
+
Will apply the following updates:
|
|
798
|
+
UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
|
|
799
|
+
{
|
|
800
|
+
\\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world\\",
|
|
801
|
+
\\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
|
|
802
|
+
\\"Environment\\": {
|
|
803
|
+
\\"Variables\\": {
|
|
804
|
+
\\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
|
|
805
|
+
\\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
|
|
806
|
+
\\"DD_SITE\\": \\"datadoghq.com\\",
|
|
807
|
+
\\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
|
|
808
|
+
\\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
|
|
809
|
+
\\"DD_TRACE_ENABLED\\": \\"true\\",
|
|
810
|
+
\\"DD_FLUSH_TO_LOG\\": \\"true\\"
|
|
811
|
+
}
|
|
812
|
+
},
|
|
813
|
+
\\"Layers\\": [
|
|
814
|
+
\\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
|
|
815
|
+
\\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node12-x:1\\"
|
|
816
|
+
]
|
|
817
|
+
}
|
|
818
|
+
TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
|
|
819
|
+
{
|
|
820
|
+
\\"dd_sls_ci\\": \\"v${version}\\"
|
|
821
|
+
}
|
|
822
|
+
UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
|
|
823
|
+
{
|
|
824
|
+
\\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2\\",
|
|
825
|
+
\\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
|
|
826
|
+
\\"Environment\\": {
|
|
827
|
+
\\"Variables\\": {
|
|
828
|
+
\\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
|
|
829
|
+
\\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
|
|
830
|
+
\\"DD_SITE\\": \\"datadoghq.com\\",
|
|
831
|
+
\\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
|
|
832
|
+
\\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
|
|
833
|
+
\\"DD_TRACE_ENABLED\\": \\"true\\",
|
|
834
|
+
\\"DD_FLUSH_TO_LOG\\": \\"true\\"
|
|
835
|
+
}
|
|
836
|
+
},
|
|
837
|
+
\\"Layers\\": [
|
|
838
|
+
\\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
|
|
839
|
+
\\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node14-x:1\\"
|
|
840
|
+
]
|
|
841
|
+
}
|
|
842
|
+
TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
|
|
843
|
+
{
|
|
844
|
+
\\"dd_sls_ci\\": \\"v${version}\\"
|
|
845
|
+
}
|
|
846
|
+
${chalk_1.yellow('[!]')} Confirmation needed.
|
|
847
|
+
${chalk_1.yellow('[!]')} Instrumenting functions.
|
|
848
|
+
"
|
|
849
|
+
`);
|
|
850
|
+
}));
|
|
851
|
+
test('instrument multiple specified functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
852
|
+
const node14LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node14-x`;
|
|
853
|
+
const node12LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node12-x`;
|
|
854
|
+
const extensionLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension`;
|
|
855
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
856
|
+
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
|
|
857
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
|
|
858
|
+
FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
|
|
859
|
+
FunctionName: 'lambda-hello-world',
|
|
860
|
+
Handler: 'index.handler',
|
|
861
|
+
Runtime: 'nodejs12.x',
|
|
862
|
+
},
|
|
863
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2': {
|
|
864
|
+
FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
|
|
865
|
+
FunctionName: 'lambda-hello-world-2',
|
|
866
|
+
Handler: 'index.handler',
|
|
867
|
+
Runtime: 'nodejs14.x',
|
|
868
|
+
},
|
|
869
|
+
}, {
|
|
870
|
+
[`${node14LibraryLayer}:1`]: {
|
|
871
|
+
LayerVersionArn: `${node14LibraryLayer}:1`,
|
|
872
|
+
Version: 1,
|
|
873
|
+
},
|
|
874
|
+
[`${node12LibraryLayer}:1`]: {
|
|
875
|
+
LayerVersionArn: `${node12LibraryLayer}:1`,
|
|
876
|
+
Version: 1,
|
|
877
|
+
},
|
|
878
|
+
[`${extensionLayer}:1`]: {
|
|
879
|
+
LayerVersionArn: `${extensionLayer}:1`,
|
|
880
|
+
Version: 1,
|
|
881
|
+
},
|
|
882
|
+
}));
|
|
883
|
+
prompt_1.requestAWSCredentials.mockImplementation(() => {
|
|
884
|
+
process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_1.mockAwsAccessKeyId;
|
|
885
|
+
process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_1.mockAwsSecretAccessKey;
|
|
886
|
+
process.env[constants_1.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
|
|
887
|
+
process.env[constants_1.AWS_SESSION_TOKEN_ENV_VAR] = 'some-session-token';
|
|
888
|
+
});
|
|
889
|
+
prompt_1.requestDatadogEnvVars.mockImplementation(() => {
|
|
890
|
+
process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
|
|
891
|
+
process.env[constants_1.CI_API_KEY_ENV_VAR] = fixtures_1.mockDatadogApiKey;
|
|
892
|
+
});
|
|
893
|
+
prompt_1.requestChangesConfirmation.mockImplementation(() => true);
|
|
894
|
+
const cli = fixtures_1.makeCli();
|
|
895
|
+
const context = fixtures_1.createMockContext();
|
|
896
|
+
const code = yield cli.run([
|
|
897
|
+
'lambda',
|
|
898
|
+
'instrument',
|
|
899
|
+
'-i',
|
|
900
|
+
'-f',
|
|
901
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
|
|
902
|
+
'-f',
|
|
903
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
|
|
904
|
+
], context);
|
|
905
|
+
const output = context.stdout.toString();
|
|
906
|
+
expect(code).toBe(0);
|
|
907
|
+
expect(output).toMatchInlineSnapshot(`
|
|
908
|
+
"${chalk_1.bold(chalk_1.yellow('[!]'))} No existing AWS credentials found, let's set them up!
|
|
909
|
+
${chalk_1.bold(chalk_1.yellow('[!]'))} Configure Datadog settings.
|
|
910
|
+
${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.'))}
|
|
911
|
+
${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.\n
|
|
912
|
+
${chalk_1.bold(chalk_1.yellow('[!]'))} Functions to be updated:
|
|
913
|
+
\t- ${chalk_1.bold('arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world')}
|
|
914
|
+
\t${chalk_1.bold(chalk_1.yellow('[Warning]'))} At least one latest layer version is being used. Ensure to lock in versions for production applications using \`--layerVersion\` and \`--extensionVersion\`.
|
|
915
|
+
\t- ${chalk_1.bold('arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2')}
|
|
916
|
+
\t${chalk_1.bold(chalk_1.yellow('[Warning]'))} At least one latest layer version is being used. Ensure to lock in versions for production applications using \`--layerVersion\` and \`--extensionVersion\`.\n
|
|
917
|
+
Will apply the following updates:
|
|
918
|
+
UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
|
|
919
|
+
{
|
|
920
|
+
\\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world\\",
|
|
921
|
+
\\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
|
|
922
|
+
\\"Environment\\": {
|
|
923
|
+
\\"Variables\\": {
|
|
924
|
+
\\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
|
|
925
|
+
\\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
|
|
926
|
+
\\"DD_SITE\\": \\"datadoghq.com\\",
|
|
927
|
+
\\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
|
|
928
|
+
\\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
|
|
929
|
+
\\"DD_TRACE_ENABLED\\": \\"true\\",
|
|
930
|
+
\\"DD_FLUSH_TO_LOG\\": \\"true\\"
|
|
931
|
+
}
|
|
932
|
+
},
|
|
933
|
+
\\"Layers\\": [
|
|
934
|
+
\\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
|
|
935
|
+
\\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node12-x:1\\"
|
|
936
|
+
]
|
|
937
|
+
}
|
|
938
|
+
TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
|
|
939
|
+
{
|
|
940
|
+
\\"dd_sls_ci\\": \\"v${version}\\"
|
|
941
|
+
}
|
|
942
|
+
UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
|
|
943
|
+
{
|
|
944
|
+
\\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2\\",
|
|
945
|
+
\\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
|
|
946
|
+
\\"Environment\\": {
|
|
947
|
+
\\"Variables\\": {
|
|
948
|
+
\\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
|
|
949
|
+
\\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
|
|
950
|
+
\\"DD_SITE\\": \\"datadoghq.com\\",
|
|
951
|
+
\\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
|
|
952
|
+
\\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
|
|
953
|
+
\\"DD_TRACE_ENABLED\\": \\"true\\",
|
|
954
|
+
\\"DD_FLUSH_TO_LOG\\": \\"true\\"
|
|
955
|
+
}
|
|
956
|
+
},
|
|
957
|
+
\\"Layers\\": [
|
|
958
|
+
\\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
|
|
959
|
+
\\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node14-x:1\\"
|
|
960
|
+
]
|
|
961
|
+
}
|
|
962
|
+
TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
|
|
963
|
+
{
|
|
964
|
+
\\"dd_sls_ci\\": \\"v${version}\\"
|
|
965
|
+
}
|
|
966
|
+
${chalk_1.yellow('[!]')} Confirmation needed.
|
|
967
|
+
${chalk_1.yellow('[!]')} Instrumenting functions.
|
|
968
|
+
"
|
|
969
|
+
`);
|
|
970
|
+
}));
|
|
971
|
+
test('aborts if a problem occurs while setting the AWS credentials interactively', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
972
|
+
;
|
|
973
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
974
|
+
prompt_1.requestAWSCredentials.mockImplementation(() => Promise.reject('Unexpected error'));
|
|
975
|
+
const cli = fixtures_1.makeCli();
|
|
976
|
+
const context = fixtures_1.createMockContext();
|
|
977
|
+
const code = yield cli.run(['lambda', 'instrument', '-i'], context);
|
|
978
|
+
const output = context.stdout.toString();
|
|
979
|
+
expect(code).toBe(1);
|
|
980
|
+
expect(output).toMatchInlineSnapshot(`
|
|
981
|
+
"${chalk_1.bold(chalk_1.yellow('[!]'))} No existing AWS credentials found, let's set them up!
|
|
982
|
+
${chalk_1.red('[Error]')} Unexpected error
|
|
983
|
+
"
|
|
984
|
+
`);
|
|
985
|
+
}));
|
|
986
|
+
test('aborts if a problem occurs while setting the Datadog Environment Variables interactively', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
987
|
+
process.env = {
|
|
988
|
+
[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_1.mockAwsAccessKeyId,
|
|
989
|
+
[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_1.mockAwsSecretAccessKey,
|
|
990
|
+
[constants_1.AWS_DEFAULT_REGION_ENV_VAR]: 'sa,-east-1',
|
|
991
|
+
};
|
|
992
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
993
|
+
prompt_1.requestDatadogEnvVars.mockImplementation(() => Promise.reject('Unexpected error'));
|
|
994
|
+
const cli = fixtures_1.makeCli();
|
|
995
|
+
const context = fixtures_1.createMockContext();
|
|
996
|
+
const code = yield cli.run(['lambda', 'instrument', '-i'], context);
|
|
997
|
+
const output = context.stdout.toString();
|
|
998
|
+
expect(code).toBe(1);
|
|
999
|
+
expect(output).toMatchInlineSnapshot(`
|
|
1000
|
+
"${chalk_1.bold(chalk_1.yellow('[!]'))} Configure Datadog settings.
|
|
1001
|
+
${chalk_1.red('[Error]')} Unexpected error
|
|
1002
|
+
"
|
|
1003
|
+
`);
|
|
1004
|
+
}));
|
|
1005
|
+
test('aborts if there are no functions to instrument in the user AWS account', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1006
|
+
process.env = {
|
|
1007
|
+
[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_1.mockAwsAccessKeyId,
|
|
1008
|
+
[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_1.mockAwsSecretAccessKey,
|
|
1009
|
+
[constants_1.AWS_DEFAULT_REGION_ENV_VAR]: 'sa-east-1',
|
|
1010
|
+
[constants_1.CI_SITE_ENV_VAR]: 'datadoghq.com',
|
|
1011
|
+
[constants_1.CI_API_KEY_ENV_VAR]: fixtures_1.mockDatadogApiKey,
|
|
1012
|
+
};
|
|
1013
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
1014
|
+
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
|
|
1015
|
+
const cli = fixtures_1.makeCli();
|
|
1016
|
+
const context = fixtures_1.createMockContext();
|
|
1017
|
+
const code = yield cli.run(['lambda', 'instrument', '-i'], context);
|
|
1018
|
+
const output = context.stdout.toString();
|
|
1019
|
+
expect(code).toBe(1);
|
|
1020
|
+
expect(output).toMatchInlineSnapshot(`
|
|
1021
|
+
"Fetching Lambda functions, this might take a while.
|
|
1022
|
+
${chalk_1.red('[Error]')} Couldn't find any Lambda functions in the specified region.
|
|
1023
|
+
"
|
|
1024
|
+
`);
|
|
1025
|
+
}));
|
|
1026
|
+
test('aborts early when the aws-sdk throws an error while instrumenting interactively', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1027
|
+
process.env = {
|
|
1028
|
+
[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_1.mockAwsAccessKeyId,
|
|
1029
|
+
[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_1.mockAwsSecretAccessKey,
|
|
1030
|
+
[constants_1.AWS_DEFAULT_REGION_ENV_VAR]: 'sa-east-1',
|
|
1031
|
+
[constants_1.CI_SITE_ENV_VAR]: 'datadoghq.com',
|
|
1032
|
+
[constants_1.CI_API_KEY_ENV_VAR]: fixtures_1.mockDatadogApiKey,
|
|
1033
|
+
};
|
|
1034
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
1035
|
+
aws_sdk_1.Lambda.mockImplementation(() => ({
|
|
1036
|
+
listFunctions: jest.fn().mockImplementation(() => ({ promise: () => Promise.reject('Lambda failed') })),
|
|
1037
|
+
}));
|
|
1038
|
+
const cli = fixtures_1.makeCli();
|
|
1039
|
+
const context = fixtures_1.createMockContext();
|
|
1040
|
+
const code = yield cli.run(['lambda', 'instrument', '-i'], context);
|
|
1041
|
+
const output = context.stdout.toString();
|
|
1042
|
+
expect(code).toBe(1);
|
|
1043
|
+
expect(output).toMatchInlineSnapshot(`
|
|
1044
|
+
"Fetching Lambda functions, this might take a while.
|
|
1045
|
+
${chalk_1.red('[Error]')} Couldn't fetch Lambda functions. Error: Max retry count exceeded.
|
|
1046
|
+
"
|
|
1047
|
+
`);
|
|
1048
|
+
}));
|
|
634
1049
|
});
|
|
635
1050
|
describe('getSettings', () => {
|
|
636
1051
|
test('uses config file settings', () => {
|
|
@@ -645,14 +1060,20 @@ describe('lambda', () => {
|
|
|
645
1060
|
command['config']['tracing'] = 'false';
|
|
646
1061
|
command['config']['logLevel'] = 'debug';
|
|
647
1062
|
expect(command['getSettings']()).toEqual({
|
|
1063
|
+
captureLambdaPayload: false,
|
|
1064
|
+
environment: undefined,
|
|
648
1065
|
extensionVersion: 6,
|
|
1066
|
+
extraTags: undefined,
|
|
649
1067
|
flushMetricsToLogs: false,
|
|
650
1068
|
forwarderARN: 'my-forwarder',
|
|
1069
|
+
interactive: false,
|
|
651
1070
|
layerAWSAccount: 'another-account',
|
|
652
1071
|
layerVersion: 2,
|
|
653
1072
|
logLevel: 'debug',
|
|
654
1073
|
mergeXrayTraces: false,
|
|
1074
|
+
service: undefined,
|
|
655
1075
|
tracingEnabled: false,
|
|
1076
|
+
version: undefined,
|
|
656
1077
|
});
|
|
657
1078
|
});
|
|
658
1079
|
test('prefers command line arguments over config file', () => {
|
|
@@ -673,8 +1094,10 @@ describe('lambda', () => {
|
|
|
673
1094
|
command['logLevel'] = 'debug';
|
|
674
1095
|
command['config']['logLevel'] = 'info';
|
|
675
1096
|
expect(command['getSettings']()).toEqual({
|
|
1097
|
+
captureLambdaPayload: false,
|
|
676
1098
|
flushMetricsToLogs: false,
|
|
677
1099
|
forwarderARN: 'my-forwarder',
|
|
1100
|
+
interactive: false,
|
|
678
1101
|
layerAWSAccount: 'my-account',
|
|
679
1102
|
layerVersion: 1,
|
|
680
1103
|
logLevel: 'debug',
|
|
@@ -704,30 +1127,37 @@ describe('lambda', () => {
|
|
|
704
1127
|
process.env = {};
|
|
705
1128
|
const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
706
1129
|
const validSettings = {
|
|
1130
|
+
captureLambdaPayload: true,
|
|
707
1131
|
extensionVersion: undefined,
|
|
708
1132
|
flushMetricsToLogs: false,
|
|
709
1133
|
forwarderARN: undefined,
|
|
1134
|
+
interactive: false,
|
|
710
1135
|
layerAWSAccount: undefined,
|
|
711
1136
|
layerVersion: undefined,
|
|
712
1137
|
logLevel: undefined,
|
|
713
1138
|
mergeXrayTraces: false,
|
|
714
1139
|
tracingEnabled: true,
|
|
715
1140
|
};
|
|
1141
|
+
command['config']['captureLambdaPayload'] = 'truE';
|
|
716
1142
|
command['config']['flushMetricsToLogs'] = 'False';
|
|
717
1143
|
command['config']['mergeXrayTraces'] = 'falSE';
|
|
718
1144
|
command['config']['tracing'] = 'TRUE';
|
|
719
1145
|
expect(command['getSettings']()).toEqual(validSettings);
|
|
1146
|
+
command['config']['captureLambdaPayload'] = 'true';
|
|
720
1147
|
command['config']['flushMetricsToLogs'] = 'false';
|
|
721
1148
|
command['config']['mergeXrayTraces'] = 'false';
|
|
722
1149
|
command['config']['tracing'] = 'true';
|
|
723
1150
|
expect(command['getSettings']()).toEqual(validSettings);
|
|
1151
|
+
validSettings.captureLambdaPayload = false;
|
|
724
1152
|
validSettings.flushMetricsToLogs = true;
|
|
725
1153
|
validSettings.mergeXrayTraces = true;
|
|
726
1154
|
validSettings.tracingEnabled = false;
|
|
1155
|
+
command['captureLambdaPayload'] = 'faLSE';
|
|
727
1156
|
command['flushMetricsToLogs'] = 'truE';
|
|
728
1157
|
command['mergeXrayTraces'] = 'TRUe';
|
|
729
1158
|
command['tracing'] = 'FALSE';
|
|
730
1159
|
expect(command['getSettings']()).toEqual(validSettings);
|
|
1160
|
+
command['captureLambdaPayload'] = 'false';
|
|
731
1161
|
command['flushMetricsToLogs'] = 'true';
|
|
732
1162
|
command['mergeXrayTraces'] = 'true';
|
|
733
1163
|
command['tracing'] = 'false';
|
|
@@ -807,7 +1237,6 @@ describe('lambda', () => {
|
|
|
807
1237
|
{
|
|
808
1238
|
functionARN: 'my-func',
|
|
809
1239
|
lambdaConfig: {},
|
|
810
|
-
lambdaLibraryLayerArn: 'my-layer',
|
|
811
1240
|
logGroupConfiguration: {
|
|
812
1241
|
createLogGroupRequest: { logGroupName: 'my-log-group' },
|
|
813
1242
|
deleteSubscriptionFilterRequest: { filterName: 'my-filter' },
|
|
@@ -818,22 +1247,24 @@ describe('lambda', () => {
|
|
|
818
1247
|
]);
|
|
819
1248
|
const output = command.context.stdout.toString();
|
|
820
1249
|
expect(output).toMatchInlineSnapshot(`
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
1250
|
+
"${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.
|
|
1251
|
+
\n${chalk_1.bold(chalk_1.yellow('[!]'))} Functions to be updated:
|
|
1252
|
+
\t- ${chalk_1.bold('my-func')}\n
|
|
1253
|
+
Will apply the following updates:
|
|
1254
|
+
CreateLogGroup -> my-log-group
|
|
1255
|
+
{
|
|
1256
|
+
\\"logGroupName\\": \\"my-log-group\\"
|
|
1257
|
+
}
|
|
1258
|
+
DeleteSubscriptionFilter -> my-log-group
|
|
1259
|
+
{
|
|
1260
|
+
\\"filterName\\": \\"my-filter\\"
|
|
1261
|
+
}
|
|
1262
|
+
PutSubscriptionFilter -> my-log-group
|
|
1263
|
+
{
|
|
1264
|
+
\\"filterName\\": \\"my-filter\\"
|
|
1265
|
+
}
|
|
1266
|
+
"
|
|
1267
|
+
`);
|
|
837
1268
|
});
|
|
838
1269
|
});
|
|
839
1270
|
});
|