@datadog/datadog-ci 2.4.0 ā 2.4.1
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 +1 -0
- package/dist/commands/lambda/__tests__/functions/commons.test.js +97 -2
- package/dist/commands/lambda/__tests__/functions/commons.test.js.map +1 -1
- package/dist/commands/lambda/__tests__/instrument.test.js +174 -394
- package/dist/commands/lambda/__tests__/instrument.test.js.map +1 -1
- package/dist/commands/lambda/__tests__/loggroup.test.js +68 -2
- package/dist/commands/lambda/__tests__/loggroup.test.js.map +1 -1
- package/dist/commands/lambda/__tests__/uninstrument.test.js +615 -551
- package/dist/commands/lambda/__tests__/uninstrument.test.js.map +1 -1
- package/dist/commands/lambda/functions/commons.d.ts +4 -2
- package/dist/commands/lambda/functions/commons.js +71 -12
- package/dist/commands/lambda/functions/commons.js.map +1 -1
- package/dist/commands/lambda/instrument.d.ts +2 -0
- package/dist/commands/lambda/instrument.js +27 -12
- package/dist/commands/lambda/instrument.js.map +1 -1
- package/dist/commands/lambda/interfaces.d.ts +6 -0
- package/dist/commands/lambda/loggroup.js +7 -1
- package/dist/commands/lambda/loggroup.js.map +1 -1
- package/dist/commands/lambda/renderer.d.ts +74 -2
- package/dist/commands/lambda/renderer.js +98 -5
- package/dist/commands/lambda/renderer.js.map +1 -1
- package/dist/commands/lambda/uninstrument.js +13 -17
- package/dist/commands/lambda/uninstrument.js.map +1 -1
- package/dist/commands/synthetics/index.d.ts +1 -0
- package/dist/commands/synthetics/index.js +3 -1
- package/dist/commands/synthetics/index.js.map +1 -1
- package/dist/helpers/__tests__/user-provided-git.test.js +2 -1
- package/dist/helpers/__tests__/user-provided-git.test.js.map +1 -1
- package/dist/helpers/ci.js +27 -29
- package/dist/helpers/ci.js.map +1 -1
- package/dist/helpers/user-provided-git.js +0 -3
- package/dist/helpers/user-provided-git.js.map +1 -1
- package/dist/helpers/utils.d.ts +1 -1
- package/dist/helpers/utils.js +1 -1
- package/dist/helpers/utils.js.map +1 -1
- package/package.json +5 -3
|
@@ -38,577 +38,641 @@ const constants_1 = require("../constants");
|
|
|
38
38
|
const prompt_1 = require("../prompt");
|
|
39
39
|
const uninstrument_1 = require("../uninstrument");
|
|
40
40
|
const fixtures_1 = require("./fixtures");
|
|
41
|
-
describe('
|
|
42
|
-
describe('
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
41
|
+
describe('lambda', () => {
|
|
42
|
+
describe('uninstrument', () => {
|
|
43
|
+
describe('execute', () => {
|
|
44
|
+
const OLD_ENV = process.env;
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
jest.resetModules();
|
|
47
|
+
process.env = {};
|
|
48
|
+
});
|
|
49
|
+
afterAll(() => {
|
|
50
|
+
process.env = OLD_ENV;
|
|
51
|
+
});
|
|
52
|
+
test('prints dry run data for a valid uninstrumentation', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
;
|
|
54
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
55
|
+
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
|
|
56
|
+
'arn:aws:lambda:us-east-1:000000000000:function:uninstrument': {
|
|
57
|
+
Architectures: ['x86_64'],
|
|
58
|
+
Environment: {
|
|
59
|
+
Variables: {
|
|
60
|
+
[constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
|
|
61
|
+
[constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
|
|
62
|
+
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
|
|
63
|
+
[constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
|
|
64
|
+
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
65
|
+
[constants_1.SERVICE_ENV_VAR]: 'middletier',
|
|
66
|
+
[constants_1.SITE_ENV_VAR]: 'datadoghq.com',
|
|
67
|
+
[constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
|
|
68
|
+
[constants_1.VERSION_ENV_VAR]: '0.2',
|
|
69
|
+
USER_VARIABLE: 'shouldnt be deleted by uninstrumentation',
|
|
70
|
+
},
|
|
69
71
|
},
|
|
72
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument',
|
|
73
|
+
Handler: 'datadog_lambda.handler.handler',
|
|
74
|
+
Layers: [
|
|
75
|
+
{
|
|
76
|
+
Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
|
|
77
|
+
CodeSize: 0,
|
|
78
|
+
SigningJobArn: 'some-signing-job-arn',
|
|
79
|
+
SigningProfileVersionArn: 'some-signing-profile',
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python38:49',
|
|
83
|
+
CodeSize: 0,
|
|
84
|
+
SigningJobArn: 'some-signing-job-arn',
|
|
85
|
+
SigningProfileVersionArn: 'some-signing-profile',
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
Runtime: 'python3.8',
|
|
70
89
|
},
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
90
|
+
}));
|
|
91
|
+
const cli = fixtures_1.makeCli();
|
|
92
|
+
const context = fixtures_1.createMockContext();
|
|
93
|
+
const functionARN = 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument';
|
|
94
|
+
process.env.DATADOG_API_KEY = '1234';
|
|
95
|
+
const code = yield cli.run(['lambda', 'uninstrument', '-f', functionARN, '-r', 'us-east-1', '-d'], context);
|
|
96
|
+
const output = context.stdout.toString();
|
|
97
|
+
expect(code).toBe(0);
|
|
98
|
+
expect(output).toMatchInlineSnapshot(`
|
|
99
|
+
"
|
|
100
|
+
[Dry Run] š¶ Uninstrumenting Lambda function
|
|
101
|
+
|
|
102
|
+
[!] Functions to be updated:
|
|
103
|
+
- arn:aws:lambda:us-east-1:000000000000:function:uninstrument
|
|
104
|
+
|
|
105
|
+
[Dry Run] Will apply the following updates:
|
|
106
|
+
UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:000000000000:function:uninstrument
|
|
107
|
+
{
|
|
108
|
+
\\"FunctionName\\": \\"arn:aws:lambda:us-east-1:000000000000:function:uninstrument\\",
|
|
109
|
+
\\"Handler\\": \\"lambda_function.lambda_handler\\",
|
|
110
|
+
\\"Environment\\": {
|
|
111
|
+
\\"Variables\\": {
|
|
112
|
+
\\"USER_VARIABLE\\": \\"shouldnt be deleted by uninstrumentation\\"
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
\\"Layers\\": []
|
|
116
|
+
}
|
|
117
|
+
"
|
|
118
|
+
`);
|
|
89
119
|
}));
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
[
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
\\"USER_VARIABLE\\": \\"shouldnt be deleted by uninstrumentation\\"
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
\\"Layers\\": []
|
|
112
|
-
}
|
|
113
|
-
"
|
|
114
|
-
`);
|
|
115
|
-
}));
|
|
116
|
-
test('runs function update command for valid uninstrumentation', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
-
;
|
|
118
|
-
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
119
|
-
const lambda = fixtures_1.makeMockLambda({
|
|
120
|
-
'arn:aws:lambda:us-east-1:000000000000:function:uninstrument': {
|
|
121
|
-
Environment: {
|
|
122
|
-
Variables: {
|
|
123
|
-
[constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
|
|
124
|
-
[constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
|
|
125
|
-
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
|
|
126
|
-
[constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
|
|
127
|
-
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
128
|
-
[constants_1.SERVICE_ENV_VAR]: 'middletier',
|
|
129
|
-
[constants_1.SITE_ENV_VAR]: 'datadoghq.com',
|
|
130
|
-
[constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
|
|
131
|
-
[constants_1.VERSION_ENV_VAR]: '0.2',
|
|
132
|
-
USER_VARIABLE: 'shouldnt be deleted by uninstrumentation',
|
|
120
|
+
test('runs function update command for valid uninstrumentation', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
121
|
+
;
|
|
122
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
123
|
+
const lambda = fixtures_1.makeMockLambda({
|
|
124
|
+
'arn:aws:lambda:us-east-1:000000000000:function:uninstrument': {
|
|
125
|
+
Environment: {
|
|
126
|
+
Variables: {
|
|
127
|
+
[constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
|
|
128
|
+
[constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
|
|
129
|
+
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
|
|
130
|
+
[constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
|
|
131
|
+
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
132
|
+
[constants_1.SERVICE_ENV_VAR]: 'middletier',
|
|
133
|
+
[constants_1.SITE_ENV_VAR]: 'datadoghq.com',
|
|
134
|
+
[constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
|
|
135
|
+
[constants_1.VERSION_ENV_VAR]: '0.2',
|
|
136
|
+
USER_VARIABLE: 'shouldnt be deleted by uninstrumentation',
|
|
137
|
+
},
|
|
133
138
|
},
|
|
139
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument',
|
|
140
|
+
Handler: 'datadog_lambda.handler.handler',
|
|
141
|
+
Layers: [
|
|
142
|
+
{
|
|
143
|
+
Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
|
|
144
|
+
CodeSize: 0,
|
|
145
|
+
SigningJobArn: 'some-signing-job-arn',
|
|
146
|
+
SigningProfileVersionArn: 'some-signing-profile',
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python38:49',
|
|
150
|
+
CodeSize: 0,
|
|
151
|
+
SigningJobArn: 'some-signing-job-arn',
|
|
152
|
+
SigningProfileVersionArn: 'some-signing-profile',
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
Runtime: 'python3.8',
|
|
134
156
|
},
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
process.env.DATADOG_API_KEY = '1234';
|
|
159
|
-
yield cli.run(['lambda', 'uninstrument', '-f', functionARN, '-r', 'us-east-1'], context);
|
|
160
|
-
expect(lambda.updateFunctionConfiguration).toHaveBeenCalled();
|
|
161
|
-
}));
|
|
162
|
-
test('aborts early when the aws-sdk throws an error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
163
|
-
;
|
|
164
|
-
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
165
|
-
aws_sdk_1.Lambda.mockImplementation(() => ({
|
|
166
|
-
getFunction: jest.fn().mockImplementation(() => ({ promise: () => Promise.reject('Lambda failed') })),
|
|
157
|
+
});
|
|
158
|
+
aws_sdk_1.Lambda.mockImplementation(() => lambda);
|
|
159
|
+
const cli = fixtures_1.makeCli();
|
|
160
|
+
const context = fixtures_1.createMockContext();
|
|
161
|
+
const functionARN = 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument';
|
|
162
|
+
process.env.DATADOG_API_KEY = '1234';
|
|
163
|
+
yield cli.run(['lambda', 'uninstrument', '-f', functionARN, '-r', 'us-east-1'], context);
|
|
164
|
+
expect(lambda.updateFunctionConfiguration).toHaveBeenCalled();
|
|
165
|
+
}));
|
|
166
|
+
test('aborts early when the aws-sdk throws an error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
167
|
+
;
|
|
168
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
169
|
+
aws_sdk_1.Lambda.mockImplementation(() => ({
|
|
170
|
+
getFunction: jest.fn().mockImplementation(() => ({ promise: () => Promise.reject('Lambda failed') })),
|
|
171
|
+
}));
|
|
172
|
+
process.env = {};
|
|
173
|
+
const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
174
|
+
command['functions'] = ['my-func'];
|
|
175
|
+
command['region'] = 'us-east-1';
|
|
176
|
+
const code = yield command['execute']();
|
|
177
|
+
const output = command.context.stdout.toString();
|
|
178
|
+
expect(code).toBe(1);
|
|
179
|
+
expect(output).toMatch("[Error] Couldn't fetch Lambda functions. Lambda failed\n");
|
|
167
180
|
}));
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
;
|
|
179
|
-
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
180
|
-
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
|
|
181
|
-
const cli = fixtures_1.makeCli();
|
|
182
|
-
const context = fixtures_1.createMockContext();
|
|
183
|
-
const code = yield cli.run(['lambda', 'uninstrument', '--function', 'my-func'], context);
|
|
184
|
-
const output = context.stdout.toString();
|
|
185
|
-
expect(code).toBe(1);
|
|
186
|
-
expect(output).toMatch('No default region specified for ["my-func"]. Use -r, --region, or use a full functionARN');
|
|
187
|
-
}));
|
|
188
|
-
test('aborts early when no functions are specified', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
189
|
-
;
|
|
190
|
-
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
191
|
-
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
|
|
192
|
-
const cli = fixtures_1.makeCli();
|
|
193
|
-
const context = fixtures_1.createMockContext();
|
|
194
|
-
const code = yield cli.run(['lambda', 'uninstrument'], context);
|
|
195
|
-
const output = context.stdout.toString();
|
|
196
|
-
expect(code).toBe(1);
|
|
197
|
-
expect(output).toMatchInlineSnapshot(`
|
|
198
|
-
"\nš¶ Uninstrumenting Lambda function
|
|
199
|
-
[Error] No functions specified to remove instrumentation.
|
|
200
|
-
"
|
|
201
|
-
`);
|
|
202
|
-
}));
|
|
203
|
-
test('aborts early when no functions are specified while using config file', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
204
|
-
;
|
|
205
|
-
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
206
|
-
process.env = {};
|
|
207
|
-
const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
208
|
-
command['config']['region'] = 'ap-southeast-1';
|
|
209
|
-
yield command['execute']();
|
|
210
|
-
const output = command.context.stdout.toString();
|
|
211
|
-
expect(output).toMatchInlineSnapshot(`
|
|
212
|
-
"\nš¶ Uninstrumenting Lambda function
|
|
213
|
-
[Error] No functions specified to remove instrumentation.
|
|
214
|
-
"
|
|
215
|
-
`);
|
|
216
|
-
}));
|
|
217
|
-
test('aborts if functions and a pattern are set at the same time', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
218
|
-
;
|
|
219
|
-
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
220
|
-
process.env = {};
|
|
221
|
-
let command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
222
|
-
command['config']['region'] = 'ap-southeast-1';
|
|
223
|
-
command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
|
|
224
|
-
command['regExPattern'] = 'valid-pattern';
|
|
225
|
-
yield command['execute']();
|
|
226
|
-
let output = command.context.stdout.toString();
|
|
227
|
-
expect(output).toMatch('Functions in config file and "--functions-regex" should not be used at the same time.\n');
|
|
228
|
-
command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
229
|
-
command['region'] = 'ap-southeast-1';
|
|
230
|
-
command['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
|
|
231
|
-
command['regExPattern'] = 'valid-pattern';
|
|
232
|
-
yield command['execute']();
|
|
233
|
-
output = command.context.stdout.toString();
|
|
234
|
-
expect(output).toMatch('"--functions" and "--functions-regex" should not be used at the same time.\n');
|
|
235
|
-
}));
|
|
236
|
-
test('aborts if the regEx pattern is an ARN', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
237
|
-
;
|
|
238
|
-
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
239
|
-
process.env = {};
|
|
240
|
-
const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
241
|
-
command['region'] = 'ap-southeast-1';
|
|
242
|
-
command['regExPattern'] = 'arn:aws:lambda:ap-southeast-1:123456789012:function:*';
|
|
243
|
-
const code = yield command['execute']();
|
|
244
|
-
const output = command.context.stdout.toString();
|
|
245
|
-
expect(code).toBe(1);
|
|
246
|
-
expect(output).toMatch(`"--functions-regex" isn't meant to be used with ARNs.\n`);
|
|
247
|
-
}));
|
|
248
|
-
test('aborts if the regEx pattern is set but no region is specified', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
249
|
-
;
|
|
250
|
-
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
251
|
-
process.env = {};
|
|
252
|
-
const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
253
|
-
command['regExPattern'] = 'my-function';
|
|
254
|
-
const code = yield command['execute']();
|
|
255
|
-
const output = command.context.stdout.toString();
|
|
256
|
-
expect(code).toBe(1);
|
|
257
|
-
expect(output).toMatch('No default region specified. Use `-r`, `--region`.');
|
|
258
|
-
}));
|
|
259
|
-
test('aborts if the the aws-sdk fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
260
|
-
;
|
|
261
|
-
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
262
|
-
aws_sdk_1.Lambda.mockImplementation(() => ({
|
|
263
|
-
listFunctions: jest.fn().mockImplementation(() => ({ promise: () => Promise.reject('ListFunctionsError') })),
|
|
181
|
+
test("aborts early when function regions can't be found", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
182
|
+
;
|
|
183
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
184
|
+
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
|
|
185
|
+
const cli = fixtures_1.makeCli();
|
|
186
|
+
const context = fixtures_1.createMockContext();
|
|
187
|
+
const code = yield cli.run(['lambda', 'uninstrument', '--function', 'my-func'], context);
|
|
188
|
+
const output = context.stdout.toString();
|
|
189
|
+
expect(code).toBe(1);
|
|
190
|
+
expect(output).toMatch('No default region specified for ["my-func"]. Use -r, --region, or use a full functionARN');
|
|
264
191
|
}));
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
192
|
+
test('aborts early when no functions are specified', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
193
|
+
;
|
|
194
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
195
|
+
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
|
|
196
|
+
const cli = fixtures_1.makeCli();
|
|
197
|
+
const context = fixtures_1.createMockContext();
|
|
198
|
+
const code = yield cli.run(['lambda', 'uninstrument'], context);
|
|
199
|
+
const output = context.stdout.toString();
|
|
200
|
+
expect(code).toBe(1);
|
|
201
|
+
expect(output).toMatchInlineSnapshot(`
|
|
202
|
+
"
|
|
203
|
+
š¶ Uninstrumenting Lambda function
|
|
204
|
+
[Error] No functions specified to remove instrumentation.
|
|
205
|
+
"
|
|
206
|
+
`);
|
|
268
207
|
}));
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
208
|
+
test('aborts early when no functions are specified while using config file', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
209
|
+
;
|
|
210
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
211
|
+
process.env = {};
|
|
212
|
+
const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
213
|
+
command['config']['region'] = 'ap-southeast-1';
|
|
214
|
+
yield command['execute']();
|
|
215
|
+
const output = command.context.stdout.toString();
|
|
216
|
+
expect(output).toMatchInlineSnapshot(`
|
|
217
|
+
"
|
|
218
|
+
š¶ Uninstrumenting Lambda function
|
|
219
|
+
[Error] No functions specified to remove instrumentation.
|
|
220
|
+
"
|
|
221
|
+
`);
|
|
222
|
+
}));
|
|
223
|
+
test('aborts if functions and a pattern are set at the same time', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
224
|
+
;
|
|
225
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
226
|
+
process.env = {};
|
|
227
|
+
let command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
228
|
+
command['config']['region'] = 'ap-southeast-1';
|
|
229
|
+
command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
|
|
230
|
+
command['regExPattern'] = 'valid-pattern';
|
|
231
|
+
yield command['execute']();
|
|
232
|
+
let output = command.context.stdout.toString();
|
|
233
|
+
expect(output).toMatch('Functions in config file and "--functions-regex" should not be used at the same time.\n');
|
|
234
|
+
command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
235
|
+
command['region'] = 'ap-southeast-1';
|
|
236
|
+
command['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
|
|
237
|
+
command['regExPattern'] = 'valid-pattern';
|
|
238
|
+
yield command['execute']();
|
|
239
|
+
output = command.context.stdout.toString();
|
|
240
|
+
expect(output).toMatch('"--functions" and "--functions-regex" should not be used at the same time.\n');
|
|
241
|
+
}));
|
|
242
|
+
test('aborts if the regEx pattern is an ARN', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
243
|
+
;
|
|
244
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
245
|
+
process.env = {};
|
|
246
|
+
const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
247
|
+
command['region'] = 'ap-southeast-1';
|
|
248
|
+
command['regExPattern'] = 'arn:aws:lambda:ap-southeast-1:123456789012:function:*';
|
|
249
|
+
const code = yield command['execute']();
|
|
250
|
+
const output = command.context.stdout.toString();
|
|
251
|
+
expect(code).toBe(1);
|
|
252
|
+
expect(output).toMatch(`"--functions-regex" isn't meant to be used with ARNs.\n`);
|
|
253
|
+
}));
|
|
254
|
+
test('aborts if the regEx pattern is set but no region is specified', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
255
|
+
;
|
|
256
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
257
|
+
process.env = {};
|
|
258
|
+
const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
259
|
+
command['regExPattern'] = 'my-function';
|
|
260
|
+
const code = yield command['execute']();
|
|
261
|
+
const output = command.context.stdout.toString();
|
|
262
|
+
expect(code).toBe(1);
|
|
263
|
+
expect(output).toMatch('No default region specified. Use `-r`, `--region`.');
|
|
264
|
+
}));
|
|
265
|
+
test('aborts if the the aws-sdk fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
266
|
+
;
|
|
267
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
268
|
+
aws_sdk_1.Lambda.mockImplementation(() => ({
|
|
269
|
+
listFunctions: jest.fn().mockImplementation(() => ({ promise: () => Promise.reject('ListFunctionsError') })),
|
|
270
|
+
}));
|
|
271
|
+
process.env = {};
|
|
272
|
+
aws_sdk_1.Lambda.mockImplementation(() => ({
|
|
273
|
+
listFunctions: jest.fn().mockImplementation(() => ({ promise: () => Promise.reject('ListFunctionsError') })),
|
|
274
|
+
}));
|
|
275
|
+
const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
276
|
+
command['region'] = 'ap-southeast-1';
|
|
277
|
+
command['regExPattern'] = 'my-function';
|
|
278
|
+
const code = yield command['execute']();
|
|
279
|
+
const output = command.context.stdout.toString();
|
|
280
|
+
expect(code).toBe(1);
|
|
281
|
+
expect(output).toMatch("\n[Error] Couldn't fetch Lambda functions. Error: Max retry count exceeded. ListFunctionsError\n");
|
|
282
|
+
}));
|
|
283
|
+
test('uninstrument multiple functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
284
|
+
;
|
|
285
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
286
|
+
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
|
|
287
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
|
|
288
|
+
Architectures: ['x86_64'],
|
|
289
|
+
Environment: {
|
|
290
|
+
Variables: {
|
|
291
|
+
[constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
|
|
292
|
+
[constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
|
|
293
|
+
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
|
|
294
|
+
[constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
|
|
295
|
+
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
296
|
+
[constants_1.SERVICE_ENV_VAR]: 'middletier',
|
|
297
|
+
[constants_1.SITE_ENV_VAR]: 'datadoghq.com',
|
|
298
|
+
[constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
|
|
299
|
+
[constants_1.VERSION_ENV_VAR]: '0.2',
|
|
300
|
+
USER_VARIABLE: 'shouldnt be deleted by uninstrumentation',
|
|
301
|
+
},
|
|
295
302
|
},
|
|
303
|
+
FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
|
|
304
|
+
FunctionName: 'lambda-hello-world',
|
|
305
|
+
Handler: 'datadog_lambda.handler.handler',
|
|
306
|
+
Layers: [
|
|
307
|
+
{
|
|
308
|
+
Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
|
|
309
|
+
CodeSize: 0,
|
|
310
|
+
SigningJobArn: 'some-signing-job-arn',
|
|
311
|
+
SigningProfileVersionArn: 'some-signing-profile',
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python38:49',
|
|
315
|
+
CodeSize: 0,
|
|
316
|
+
SigningJobArn: 'some-signing-job-arn',
|
|
317
|
+
SigningProfileVersionArn: 'some-signing-profile',
|
|
318
|
+
},
|
|
319
|
+
],
|
|
320
|
+
Runtime: 'python3.8',
|
|
296
321
|
},
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
SigningProfileVersionArn: 'some-signing-profile',
|
|
312
|
-
},
|
|
313
|
-
],
|
|
314
|
-
Runtime: 'python3.8',
|
|
315
|
-
},
|
|
316
|
-
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2': {
|
|
317
|
-
Architectures: ['x86_64'],
|
|
318
|
-
Environment: {
|
|
319
|
-
Variables: {
|
|
320
|
-
[constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
|
|
321
|
-
[constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
|
|
322
|
-
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
|
|
323
|
-
[constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
|
|
324
|
-
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
325
|
-
[constants_1.SERVICE_ENV_VAR]: 'middletier',
|
|
326
|
-
[constants_1.SITE_ENV_VAR]: 'datadoghq.com',
|
|
327
|
-
[constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
|
|
328
|
-
[constants_1.VERSION_ENV_VAR]: '0.2',
|
|
322
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2': {
|
|
323
|
+
Architectures: ['x86_64'],
|
|
324
|
+
Environment: {
|
|
325
|
+
Variables: {
|
|
326
|
+
[constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
|
|
327
|
+
[constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
|
|
328
|
+
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
|
|
329
|
+
[constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
|
|
330
|
+
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
331
|
+
[constants_1.SERVICE_ENV_VAR]: 'middletier',
|
|
332
|
+
[constants_1.SITE_ENV_VAR]: 'datadoghq.com',
|
|
333
|
+
[constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
|
|
334
|
+
[constants_1.VERSION_ENV_VAR]: '0.2',
|
|
335
|
+
},
|
|
329
336
|
},
|
|
337
|
+
FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
|
|
338
|
+
FunctionName: 'lambda-hello-world-2',
|
|
339
|
+
Handler: 'datadog_lambda.handler.handler',
|
|
340
|
+
Layers: [
|
|
341
|
+
{
|
|
342
|
+
Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
|
|
343
|
+
CodeSize: 0,
|
|
344
|
+
SigningJobArn: 'some-signing-job-arn',
|
|
345
|
+
SigningProfileVersionArn: 'some-signing-profile',
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python39:49',
|
|
349
|
+
CodeSize: 0,
|
|
350
|
+
SigningJobArn: 'some-signing-job-arn',
|
|
351
|
+
SigningProfileVersionArn: 'some-signing-profile',
|
|
352
|
+
},
|
|
353
|
+
],
|
|
354
|
+
Runtime: 'python3.9',
|
|
330
355
|
},
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
Runtime: 'python3.9',
|
|
349
|
-
},
|
|
356
|
+
}));
|
|
357
|
+
prompt_1.requestAWSCredentials.mockImplementation(() => {
|
|
358
|
+
process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_1.mockAwsAccessKeyId;
|
|
359
|
+
process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_1.mockAwsSecretAccessKey;
|
|
360
|
+
process.env[constants_1.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
|
|
361
|
+
});
|
|
362
|
+
prompt_1.requestFunctionSelection.mockImplementation(() => [
|
|
363
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
|
|
364
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
|
|
365
|
+
]);
|
|
366
|
+
prompt_1.requestChangesConfirmation.mockImplementation(() => true);
|
|
367
|
+
const cli = fixtures_1.makeCli();
|
|
368
|
+
const context = fixtures_1.createMockContext();
|
|
369
|
+
const code = yield cli.run(['lambda', 'uninstrument', '-i'], context);
|
|
370
|
+
const output = context.stdout.toString();
|
|
371
|
+
expect(code).toBe(0);
|
|
372
|
+
expect(output).toMatchSnapshot();
|
|
350
373
|
}));
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
\t- arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
|
|
371
|
-
\t- arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2\n
|
|
372
|
-
Will apply the following updates:
|
|
373
|
-
UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
|
|
374
|
-
{
|
|
375
|
-
\\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world\\",
|
|
376
|
-
\\"Handler\\": \\"lambda_function.lambda_handler\\",
|
|
377
|
-
\\"Environment\\": {
|
|
378
|
-
\\"Variables\\": {
|
|
379
|
-
\\"USER_VARIABLE\\": \\"shouldnt be deleted by uninstrumentation\\"
|
|
380
|
-
}
|
|
381
|
-
},
|
|
382
|
-
\\"Layers\\": []
|
|
383
|
-
}
|
|
384
|
-
UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
|
|
385
|
-
{
|
|
386
|
-
\\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2\\",
|
|
387
|
-
\\"Handler\\": \\"lambda_function.lambda_handler\\",
|
|
388
|
-
\\"Environment\\": {
|
|
389
|
-
\\"Variables\\": {}
|
|
390
|
-
},
|
|
391
|
-
\\"Layers\\": []
|
|
392
|
-
}
|
|
393
|
-
[!] Confirmation needed.
|
|
394
|
-
[!] Uninstrumenting functions.
|
|
395
|
-
"
|
|
396
|
-
`);
|
|
397
|
-
}));
|
|
398
|
-
test('uninstrument multiple specified functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
399
|
-
;
|
|
400
|
-
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
401
|
-
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
|
|
402
|
-
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
|
|
403
|
-
Architectures: ['x86_64'],
|
|
404
|
-
Environment: {
|
|
405
|
-
Variables: {
|
|
406
|
-
[constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
|
|
407
|
-
[constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
|
|
408
|
-
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
|
|
409
|
-
[constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
|
|
410
|
-
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
411
|
-
[constants_1.SERVICE_ENV_VAR]: 'middletier',
|
|
412
|
-
[constants_1.SITE_ENV_VAR]: 'datadoghq.com',
|
|
413
|
-
[constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
|
|
414
|
-
[constants_1.VERSION_ENV_VAR]: '0.2',
|
|
415
|
-
USER_VARIABLE: 'shouldnt be deleted by uninstrumentation',
|
|
374
|
+
test('uninstrument multiple specified functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
375
|
+
;
|
|
376
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
377
|
+
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
|
|
378
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
|
|
379
|
+
Architectures: ['x86_64'],
|
|
380
|
+
Environment: {
|
|
381
|
+
Variables: {
|
|
382
|
+
[constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
|
|
383
|
+
[constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
|
|
384
|
+
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
|
|
385
|
+
[constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
|
|
386
|
+
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
387
|
+
[constants_1.SERVICE_ENV_VAR]: 'middletier',
|
|
388
|
+
[constants_1.SITE_ENV_VAR]: 'datadoghq.com',
|
|
389
|
+
[constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
|
|
390
|
+
[constants_1.VERSION_ENV_VAR]: '0.2',
|
|
391
|
+
USER_VARIABLE: 'shouldnt be deleted by uninstrumentation',
|
|
392
|
+
},
|
|
416
393
|
},
|
|
394
|
+
FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
|
|
395
|
+
FunctionName: 'lambda-hello-world',
|
|
396
|
+
Handler: 'datadog_lambda.handler.handler',
|
|
397
|
+
Layers: [
|
|
398
|
+
{
|
|
399
|
+
Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
|
|
400
|
+
CodeSize: 0,
|
|
401
|
+
SigningJobArn: 'some-signing-job-arn',
|
|
402
|
+
SigningProfileVersionArn: 'some-signing-profile',
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python38:49',
|
|
406
|
+
CodeSize: 0,
|
|
407
|
+
SigningJobArn: 'some-signing-job-arn',
|
|
408
|
+
SigningProfileVersionArn: 'some-signing-profile',
|
|
409
|
+
},
|
|
410
|
+
],
|
|
411
|
+
Runtime: 'python3.8',
|
|
417
412
|
},
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
SigningProfileVersionArn: 'some-signing-profile',
|
|
433
|
-
},
|
|
434
|
-
],
|
|
435
|
-
Runtime: 'python3.8',
|
|
436
|
-
},
|
|
437
|
-
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2': {
|
|
438
|
-
Architectures: ['x86_64'],
|
|
439
|
-
Environment: {
|
|
440
|
-
Variables: {
|
|
441
|
-
[constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
|
|
442
|
-
[constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
|
|
443
|
-
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
|
|
444
|
-
[constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
|
|
445
|
-
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
446
|
-
[constants_1.SERVICE_ENV_VAR]: 'middletier',
|
|
447
|
-
[constants_1.SITE_ENV_VAR]: 'datadoghq.com',
|
|
448
|
-
[constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
|
|
449
|
-
[constants_1.VERSION_ENV_VAR]: '0.2',
|
|
413
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2': {
|
|
414
|
+
Architectures: ['x86_64'],
|
|
415
|
+
Environment: {
|
|
416
|
+
Variables: {
|
|
417
|
+
[constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
|
|
418
|
+
[constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
|
|
419
|
+
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
|
|
420
|
+
[constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
|
|
421
|
+
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
422
|
+
[constants_1.SERVICE_ENV_VAR]: 'middletier',
|
|
423
|
+
[constants_1.SITE_ENV_VAR]: 'datadoghq.com',
|
|
424
|
+
[constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
|
|
425
|
+
[constants_1.VERSION_ENV_VAR]: '0.2',
|
|
426
|
+
},
|
|
450
427
|
},
|
|
428
|
+
FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
|
|
429
|
+
FunctionName: 'lambda-hello-world-2',
|
|
430
|
+
Handler: 'datadog_lambda.handler.handler',
|
|
431
|
+
Layers: [
|
|
432
|
+
{
|
|
433
|
+
Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
|
|
434
|
+
CodeSize: 0,
|
|
435
|
+
SigningJobArn: 'some-signing-job-arn',
|
|
436
|
+
SigningProfileVersionArn: 'some-signing-profile',
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python39:49',
|
|
440
|
+
CodeSize: 0,
|
|
441
|
+
SigningJobArn: 'some-signing-job-arn',
|
|
442
|
+
SigningProfileVersionArn: 'some-signing-profile',
|
|
443
|
+
},
|
|
444
|
+
],
|
|
445
|
+
Runtime: 'python3.9',
|
|
451
446
|
},
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
447
|
+
}));
|
|
448
|
+
prompt_1.requestAWSCredentials.mockImplementation(() => {
|
|
449
|
+
process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_1.mockAwsAccessKeyId;
|
|
450
|
+
process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_1.mockAwsSecretAccessKey;
|
|
451
|
+
process.env[constants_1.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
|
|
452
|
+
});
|
|
453
|
+
prompt_1.requestFunctionSelection.mockImplementation(() => [
|
|
454
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
|
|
455
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
|
|
456
|
+
]);
|
|
457
|
+
prompt_1.requestChangesConfirmation.mockImplementation(() => true);
|
|
458
|
+
const cli = fixtures_1.makeCli();
|
|
459
|
+
const context = fixtures_1.createMockContext();
|
|
460
|
+
const code = yield cli.run([
|
|
461
|
+
'lambda',
|
|
462
|
+
'uninstrument',
|
|
463
|
+
'-i',
|
|
464
|
+
'-f',
|
|
465
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
|
|
466
|
+
'-f',
|
|
467
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
|
|
468
|
+
], context);
|
|
469
|
+
const output = context.stdout.toString();
|
|
470
|
+
expect(code).toBe(0);
|
|
471
|
+
expect(output).toMatchSnapshot();
|
|
471
472
|
}));
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
'
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
[
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
};
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
473
|
+
test('aborts if a problem occurs while setting the AWS credentials interactively', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
474
|
+
;
|
|
475
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
476
|
+
prompt_1.requestAWSCredentials.mockImplementation(() => Promise.reject('Unexpected error'));
|
|
477
|
+
const cli = fixtures_1.makeCli();
|
|
478
|
+
const context = fixtures_1.createMockContext();
|
|
479
|
+
const code = yield cli.run(['lambda', 'uninstrument', '-i'], context);
|
|
480
|
+
const output = context.stdout.toString();
|
|
481
|
+
expect(code).toBe(1);
|
|
482
|
+
expect(output).toMatchInlineSnapshot(`
|
|
483
|
+
"
|
|
484
|
+
š¶ Uninstrumenting Lambda function
|
|
485
|
+
[!] No AWS credentials found, let's set them up! Or you can re-run the command and supply the AWS credentials in the same way when you invoke the AWS CLI.
|
|
486
|
+
[Error] Unexpected error
|
|
487
|
+
"
|
|
488
|
+
`);
|
|
489
|
+
}));
|
|
490
|
+
test('aborts if there are no functions to uninstrument in the user AWS account', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
491
|
+
process.env = {
|
|
492
|
+
[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_1.mockAwsAccessKeyId,
|
|
493
|
+
[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_1.mockAwsSecretAccessKey,
|
|
494
|
+
[constants_1.AWS_DEFAULT_REGION_ENV_VAR]: 'sa-east-1',
|
|
495
|
+
};
|
|
496
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
497
|
+
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
|
|
498
|
+
const cli = fixtures_1.makeCli();
|
|
499
|
+
const context = fixtures_1.createMockContext();
|
|
500
|
+
const code = yield cli.run(['lambda', 'uninstrument', '-i'], context);
|
|
501
|
+
const output = context.stdout.toString();
|
|
502
|
+
expect(code).toBe(1);
|
|
503
|
+
expect(output).toMatchInlineSnapshot(`
|
|
504
|
+
"
|
|
505
|
+
š¶ Uninstrumenting Lambda function
|
|
506
|
+
[Error] Couldn't find any Lambda functions in the specified region.
|
|
507
|
+
"
|
|
508
|
+
`);
|
|
509
|
+
}));
|
|
510
|
+
test('aborts early when the aws-sdk throws an error while uninstrumenting interactively', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
511
|
+
process.env = {
|
|
512
|
+
[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_1.mockAwsAccessKeyId,
|
|
513
|
+
[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_1.mockAwsSecretAccessKey,
|
|
514
|
+
[constants_1.AWS_DEFAULT_REGION_ENV_VAR]: 'sa-east-1',
|
|
515
|
+
};
|
|
516
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
517
|
+
aws_sdk_1.Lambda.mockImplementation(() => ({
|
|
518
|
+
listFunctions: jest.fn().mockImplementation(() => ({ promise: () => Promise.reject('ListFunctionsError') })),
|
|
519
|
+
}));
|
|
520
|
+
const cli = fixtures_1.makeCli();
|
|
521
|
+
const context = fixtures_1.createMockContext();
|
|
522
|
+
const code = yield cli.run(['lambda', 'uninstrument', '-i'], context);
|
|
523
|
+
const output = context.stdout.toString();
|
|
524
|
+
expect(code).toBe(1);
|
|
525
|
+
expect(output).toMatchInlineSnapshot(`
|
|
526
|
+
"
|
|
527
|
+
š¶ Uninstrumenting Lambda function
|
|
528
|
+
[Error] Couldn't fetch Lambda functions. Error: Max retry count exceeded. ListFunctionsError
|
|
529
|
+
"
|
|
530
|
+
`);
|
|
531
|
+
}));
|
|
532
|
+
test('prints error when updating aws profile credentials fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
533
|
+
;
|
|
534
|
+
aws_sdk_1.SharedIniFileCredentials.mockImplementation(() => {
|
|
535
|
+
throw Error('Update failed!');
|
|
536
|
+
});
|
|
537
|
+
const cli = fixtures_1.makeCli();
|
|
538
|
+
const context = fixtures_1.createMockContext();
|
|
539
|
+
const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
|
|
540
|
+
const code = yield cli.run(['lambda', 'uninstrument', '-f', functionARN, '--profile', 'SOME-AWS-PROFILE'], context);
|
|
541
|
+
const output = context.stdout.toString();
|
|
542
|
+
expect(code).toBe(1);
|
|
543
|
+
expect(output).toMatchInlineSnapshot(`
|
|
544
|
+
"
|
|
545
|
+
š¶ Uninstrumenting Lambda function
|
|
546
|
+
[Error] Error: Couldn't set AWS profile credentials. Update failed!
|
|
547
|
+
"
|
|
548
|
+
`);
|
|
549
|
+
}));
|
|
550
|
+
test('prints which functions failed to uninstrument without aborting when at least one function was uninstrumented correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
551
|
+
;
|
|
552
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
553
|
+
const failingLambdas = [
|
|
554
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
|
|
555
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-2-us-east-1',
|
|
556
|
+
'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
|
|
557
|
+
];
|
|
558
|
+
aws_sdk_1.Lambda.mockImplementation(() => (Object.assign(Object.assign({}, fixtures_1.makeMockLambda({
|
|
559
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1': {
|
|
560
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
|
|
561
|
+
FunctionName: 'lambda-1-us-east-1',
|
|
562
|
+
Handler: 'index.handler',
|
|
563
|
+
Runtime: 'nodejs12.x',
|
|
564
|
+
},
|
|
565
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-2-us-east-1': {
|
|
566
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-2-us-east-1',
|
|
567
|
+
FunctionName: 'lambda-2-us-east-1',
|
|
568
|
+
Handler: 'index.handler',
|
|
569
|
+
Runtime: 'nodejs12.x',
|
|
570
|
+
},
|
|
571
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-3-us-east-1': {
|
|
572
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-3-us-east-1',
|
|
573
|
+
FunctionName: 'lambda-3-us-east-1',
|
|
574
|
+
Handler: 'index.handler',
|
|
575
|
+
Runtime: 'nodejs12.x',
|
|
576
|
+
},
|
|
577
|
+
'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2': {
|
|
578
|
+
FunctionArn: 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
|
|
579
|
+
FunctionName: 'lambda-1-us-east-2',
|
|
580
|
+
Handler: 'index.handler',
|
|
581
|
+
Runtime: 'nodejs14.x',
|
|
582
|
+
},
|
|
583
|
+
'arn:aws:lambda:us-east-2:123456789012:function:lambda-2-us-east-2': {
|
|
584
|
+
FunctionArn: 'arn:aws:lambda:us-east-2:123456789012:function:lambda-2-us-east-2',
|
|
585
|
+
FunctionName: 'lambda-2-us-east-2',
|
|
586
|
+
Handler: 'index.handler',
|
|
587
|
+
Runtime: 'nodejs16.x',
|
|
588
|
+
},
|
|
589
|
+
'arn:aws:lambda:us-east-2:123456789012:function:lambda-3-us-east-2': {
|
|
590
|
+
FunctionArn: 'arn:aws:lambda:us-east-2:123456789012:function:lambda-3-us-east-2',
|
|
591
|
+
FunctionName: 'lambda-3-us-east-2',
|
|
592
|
+
Handler: 'index.handler',
|
|
593
|
+
Runtime: 'nodejs18.x',
|
|
594
|
+
},
|
|
595
|
+
})), { updateFunctionConfiguration: jest.fn().mockImplementation((updateRequest) => {
|
|
596
|
+
if (failingLambdas.includes(updateRequest['FunctionName'])) {
|
|
597
|
+
return { promise: () => Promise.reject(Error('Unexpected error updating request')) };
|
|
598
|
+
}
|
|
599
|
+
return { promise: () => Promise.resolve() };
|
|
600
|
+
}) })));
|
|
601
|
+
const cli = fixtures_1.makeCli();
|
|
602
|
+
const context = fixtures_1.createMockContext();
|
|
603
|
+
const code = yield cli.run([
|
|
604
|
+
'lambda',
|
|
605
|
+
'instrument',
|
|
606
|
+
'-f',
|
|
607
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
|
|
608
|
+
'-f',
|
|
609
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-2-us-east-1',
|
|
610
|
+
'-f',
|
|
611
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-3-us-east-1',
|
|
612
|
+
'-f',
|
|
613
|
+
'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
|
|
614
|
+
'-f',
|
|
615
|
+
'arn:aws:lambda:us-east-2:123456789012:function:lambda-2-us-east-2',
|
|
616
|
+
'-f',
|
|
617
|
+
'arn:aws:lambda:us-east-2:123456789012:function:lambda-3-us-east-2',
|
|
618
|
+
], context);
|
|
619
|
+
const output = context.stdout.toString();
|
|
620
|
+
expect(code).toBe(0);
|
|
621
|
+
expect(output).toMatchSnapshot();
|
|
571
622
|
}));
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
623
|
+
test('aborts when every lambda function fails to update on uninstrument', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
624
|
+
;
|
|
625
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
626
|
+
const failingLambdas = [
|
|
627
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
|
|
628
|
+
'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
|
|
629
|
+
];
|
|
630
|
+
aws_sdk_1.Lambda.mockImplementation(() => (Object.assign(Object.assign({}, fixtures_1.makeMockLambda({
|
|
631
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1': {
|
|
632
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
|
|
633
|
+
FunctionName: 'lambda-1-us-east-1',
|
|
634
|
+
Handler: 'index.handler',
|
|
635
|
+
Runtime: 'nodejs12.x',
|
|
636
|
+
},
|
|
637
|
+
'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2': {
|
|
638
|
+
FunctionArn: 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
|
|
639
|
+
FunctionName: 'lambda-1-us-east-2',
|
|
640
|
+
Handler: 'index.handler',
|
|
641
|
+
Runtime: 'nodejs14.x',
|
|
642
|
+
},
|
|
643
|
+
})), { updateFunctionConfiguration: jest.fn().mockImplementation((updateRequest) => {
|
|
644
|
+
if (failingLambdas.includes(updateRequest['FunctionName'])) {
|
|
645
|
+
return { promise: () => Promise.reject(Error('Unexpected error updating request')) };
|
|
646
|
+
}
|
|
647
|
+
return { promise: () => Promise.resolve() };
|
|
648
|
+
}) })));
|
|
649
|
+
const cli = fixtures_1.makeCli();
|
|
650
|
+
const context = fixtures_1.createMockContext();
|
|
651
|
+
const code = yield cli.run([
|
|
652
|
+
'lambda',
|
|
653
|
+
'instrument',
|
|
654
|
+
'-f',
|
|
655
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
|
|
656
|
+
'-f',
|
|
657
|
+
'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
|
|
658
|
+
], context);
|
|
659
|
+
const output = context.stdout.toString();
|
|
660
|
+
expect(code).toBe(1);
|
|
661
|
+
expect(output).toMatchSnapshot();
|
|
662
|
+
}));
|
|
663
|
+
});
|
|
664
|
+
describe('printPlannedActions', () => {
|
|
665
|
+
test('prints no output when list is empty', () => {
|
|
666
|
+
process.env = {};
|
|
667
|
+
const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
668
|
+
command['printPlannedActions']([]);
|
|
669
|
+
const output = command.context.stdout.toString();
|
|
670
|
+
expect(output).toMatchInlineSnapshot(`
|
|
671
|
+
"
|
|
672
|
+
No updates will be applied.
|
|
673
|
+
"
|
|
674
|
+
`);
|
|
587
675
|
});
|
|
588
|
-
const cli = fixtures_1.makeCli();
|
|
589
|
-
const context = fixtures_1.createMockContext();
|
|
590
|
-
const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
|
|
591
|
-
const code = yield cli.run(['lambda', 'uninstrument', '-f', functionARN, '--profile', 'SOME-AWS-PROFILE'], context);
|
|
592
|
-
const output = context.stdout.toString();
|
|
593
|
-
expect(code).toBe(1);
|
|
594
|
-
expect(output).toMatchInlineSnapshot(`
|
|
595
|
-
"\nš¶ Uninstrumenting Lambda function
|
|
596
|
-
[Error] Error: Couldn't set AWS profile credentials. Update failed!
|
|
597
|
-
"
|
|
598
|
-
`);
|
|
599
|
-
}));
|
|
600
|
-
});
|
|
601
|
-
describe('printPlannedActions', () => {
|
|
602
|
-
test('prints no output when list is empty', () => {
|
|
603
|
-
process.env = {};
|
|
604
|
-
const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
605
|
-
command['printPlannedActions']([]);
|
|
606
|
-
const output = command.context.stdout.toString();
|
|
607
|
-
expect(output).toMatchInlineSnapshot(`
|
|
608
|
-
"
|
|
609
|
-
No updates will be applied.
|
|
610
|
-
"
|
|
611
|
-
`);
|
|
612
676
|
});
|
|
613
677
|
});
|
|
614
678
|
});
|