@datadog/datadog-ci 0.17.8 → 0.17.12
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 +3 -1
- 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/__tests__/function.test.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/lambda/__tests__/fixtures.d.ts +42 -0
- package/dist/commands/lambda/__tests__/fixtures.js +73 -0
- package/dist/commands/lambda/{index.d.ts → __tests__/functions/commons.test.d.ts} +0 -0
- package/dist/commands/lambda/__tests__/functions/commons.test.js +350 -0
- package/dist/commands/{sourcemaps/index.d.ts → lambda/__tests__/functions/instrument.test.d.ts} +0 -0
- package/dist/commands/lambda/__tests__/{function.test.js → functions/instrument.test.js} +504 -476
- package/dist/commands/{trace/index.d.ts → lambda/__tests__/functions/uninstrument.test.d.ts} +0 -0
- package/dist/commands/lambda/__tests__/functions/uninstrument.test.js +371 -0
- package/dist/commands/lambda/__tests__/instrument.test.js +351 -234
- package/dist/commands/lambda/__tests__/loggroup.test.js +98 -34
- package/dist/commands/lambda/__tests__/tags.test.js +107 -31
- package/dist/commands/lambda/__tests__/uninstrument.test.d.ts +1 -0
- package/dist/commands/lambda/__tests__/uninstrument.test.js +281 -0
- package/dist/commands/lambda/cli.d.ts +1 -0
- package/dist/commands/lambda/cli.js +5 -0
- package/dist/commands/lambda/constants.d.ts +18 -6
- package/dist/commands/lambda/constants.js +30 -6
- package/dist/commands/lambda/functions/commons.d.ts +101 -0
- package/dist/commands/lambda/functions/commons.js +258 -0
- package/dist/commands/lambda/functions/instrument.d.ts +7 -0
- package/dist/commands/lambda/functions/instrument.js +186 -0
- package/dist/commands/lambda/functions/uninstrument.d.ts +7 -0
- package/dist/commands/lambda/functions/uninstrument.js +121 -0
- package/dist/commands/lambda/instrument.d.ts +4 -4
- package/dist/commands/lambda/instrument.js +103 -57
- package/dist/commands/lambda/interfaces.d.ts +53 -0
- package/dist/commands/lambda/loggroup.d.ts +4 -7
- package/dist/commands/lambda/loggroup.js +30 -5
- package/dist/commands/lambda/tags.d.ts +3 -4
- package/dist/commands/lambda/tags.js +19 -3
- package/dist/commands/lambda/uninstrument.d.ts +12 -0
- package/dist/commands/lambda/uninstrument.js +166 -0
- 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 +35 -13
- package/dist/commands/synthetics/__tests__/utils.test.js +0 -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 +26 -0
- package/dist/commands/synthetics/command.js +230 -0
- package/dist/commands/synthetics/index.d.ts +5 -1
- package/dist/commands/synthetics/index.js +31 -2
- package/dist/commands/synthetics/utils.d.ts +0 -3
- package/dist/commands/synthetics/utils.js +1 -11
- 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 +51 -114
- package/dist/helpers/__tests__/user-provided-git.test.js +14 -2
- package/dist/helpers/__tests__/utils.test.js +4 -0
- package/dist/helpers/ci.js +62 -96
- package/dist/helpers/interfaces.d.ts +28 -2
- package/dist/helpers/user-provided-git.js +11 -2
- 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
- package/dist/commands/lambda/function.d.ts +0 -43
- package/dist/commands/lambda/function.js +0 -273
- package/dist/commands/lambda/index.js +0 -4
package/dist/commands/{trace/index.d.ts → lambda/__tests__/functions/uninstrument.test.d.ts}
RENAMED
|
File without changes
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
jest.mock('../../loggroup');
|
|
32
|
+
const constants_1 = require("../../constants");
|
|
33
|
+
const commons_1 = require("../../functions/commons");
|
|
34
|
+
const uninstrument_1 = require("../../functions/uninstrument");
|
|
35
|
+
const fixtures_1 = require("../fixtures");
|
|
36
|
+
const loggroup = __importStar(require("../../loggroup"));
|
|
37
|
+
describe('uninstrument', () => {
|
|
38
|
+
describe('calculateUpdateRequest', () => {
|
|
39
|
+
const OLD_ENV = process.env;
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
jest.resetModules();
|
|
42
|
+
process.env = {};
|
|
43
|
+
});
|
|
44
|
+
afterAll(() => {
|
|
45
|
+
process.env = OLD_ENV;
|
|
46
|
+
});
|
|
47
|
+
test('calculates an update request removing all variables set by the CI', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
+
const lambda = fixtures_1.makeMockLambda({
|
|
49
|
+
'arn:aws:lambda:us-east-1:000000000000:function:uninstrument': {
|
|
50
|
+
Environment: {
|
|
51
|
+
Variables: {
|
|
52
|
+
[constants_1.API_KEY_SECRET_ARN_ENV_VAR]: 'some-secret:arn:from:aws',
|
|
53
|
+
[constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
|
|
54
|
+
[constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
|
|
55
|
+
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
|
|
56
|
+
[constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
|
|
57
|
+
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
58
|
+
[constants_1.SERVICE_ENV_VAR]: 'middletier',
|
|
59
|
+
[constants_1.SITE_ENV_VAR]: 'datadoghq.com',
|
|
60
|
+
[constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
|
|
61
|
+
[constants_1.VERSION_ENV_VAR]: '0.2',
|
|
62
|
+
USER_VARIABLE: 'shouldnt be deleted by uninstrumentation',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument',
|
|
66
|
+
Handler: 'datadog_lambda.handler.handler',
|
|
67
|
+
Runtime: 'python3.8',
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
const config = yield commons_1.getLambdaFunctionConfig(lambda, 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument');
|
|
71
|
+
const updateRequest = yield uninstrument_1.calculateUpdateRequest(config, config.Runtime);
|
|
72
|
+
expect(updateRequest).toMatchInlineSnapshot(`
|
|
73
|
+
Object {
|
|
74
|
+
"Environment": Object {
|
|
75
|
+
"Variables": Object {
|
|
76
|
+
"USER_VARIABLE": "shouldnt be deleted by uninstrumentation",
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
"FunctionName": "arn:aws:lambda:us-east-1:000000000000:function:uninstrument",
|
|
80
|
+
"Handler": "lambda_function.lambda_handler",
|
|
81
|
+
}
|
|
82
|
+
`);
|
|
83
|
+
}));
|
|
84
|
+
test('calculates an update request setting the previous handler', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
85
|
+
const lambda = fixtures_1.makeMockLambda({
|
|
86
|
+
'arn:aws:lambda:us-east-1:000000000000:function:uninstrument': {
|
|
87
|
+
Environment: {
|
|
88
|
+
Variables: {
|
|
89
|
+
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument',
|
|
93
|
+
Handler: 'datadog_lambda.handler.handler',
|
|
94
|
+
Runtime: 'python3.8',
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
const config = yield commons_1.getLambdaFunctionConfig(lambda, 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument');
|
|
98
|
+
const updateRequest = yield uninstrument_1.calculateUpdateRequest(config, config.Runtime);
|
|
99
|
+
expect(updateRequest).toMatchInlineSnapshot(`
|
|
100
|
+
Object {
|
|
101
|
+
"Environment": Object {
|
|
102
|
+
"Variables": Object {},
|
|
103
|
+
},
|
|
104
|
+
"FunctionName": "arn:aws:lambda:us-east-1:000000000000:function:uninstrument",
|
|
105
|
+
"Handler": "lambda_function.lambda_handler",
|
|
106
|
+
}
|
|
107
|
+
`);
|
|
108
|
+
}));
|
|
109
|
+
test('calculates an update request removing lambda layers set by the CI', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
110
|
+
const lambda = fixtures_1.makeMockLambda({
|
|
111
|
+
'arn:aws:lambda:us-east-1:000000000000:function:uninstrument': {
|
|
112
|
+
Environment: {
|
|
113
|
+
Variables: {
|
|
114
|
+
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument',
|
|
118
|
+
Handler: 'datadog_lambda.handler.handler',
|
|
119
|
+
Layers: [
|
|
120
|
+
{
|
|
121
|
+
Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
|
|
122
|
+
CodeSize: 0,
|
|
123
|
+
SigningJobArn: 'some-signing-job-arn',
|
|
124
|
+
SigningProfileVersionArn: 'some-signing-profile',
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python38:49',
|
|
128
|
+
CodeSize: 0,
|
|
129
|
+
SigningJobArn: 'some-signing-job-arn',
|
|
130
|
+
SigningProfileVersionArn: 'some-signing-profile',
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
Runtime: 'python3.8',
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
const config = yield commons_1.getLambdaFunctionConfig(lambda, 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument');
|
|
137
|
+
const updateRequest = yield uninstrument_1.calculateUpdateRequest(config, config.Runtime);
|
|
138
|
+
expect(updateRequest).toMatchInlineSnapshot(`
|
|
139
|
+
Object {
|
|
140
|
+
"Environment": Object {
|
|
141
|
+
"Variables": Object {},
|
|
142
|
+
},
|
|
143
|
+
"FunctionName": "arn:aws:lambda:us-east-1:000000000000:function:uninstrument",
|
|
144
|
+
"Handler": "lambda_function.lambda_handler",
|
|
145
|
+
"Layers": Array [],
|
|
146
|
+
}
|
|
147
|
+
`);
|
|
148
|
+
}));
|
|
149
|
+
});
|
|
150
|
+
describe('getUninstrumentedFunctionConfigs', () => {
|
|
151
|
+
const OLD_ENV = process.env;
|
|
152
|
+
beforeEach(() => {
|
|
153
|
+
jest.resetModules();
|
|
154
|
+
process.env = {};
|
|
155
|
+
});
|
|
156
|
+
afterAll(() => {
|
|
157
|
+
process.env = OLD_ENV;
|
|
158
|
+
});
|
|
159
|
+
test('returns the update request for each function', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
160
|
+
const lambda = fixtures_1.makeMockLambda({
|
|
161
|
+
'arn:aws:lambda:us-east-1:000000000000:function:uninstrument': {
|
|
162
|
+
Environment: {
|
|
163
|
+
Variables: {
|
|
164
|
+
[constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
|
|
165
|
+
[constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
|
|
166
|
+
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
|
|
167
|
+
[constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
|
|
168
|
+
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
169
|
+
[constants_1.SERVICE_ENV_VAR]: 'middletier',
|
|
170
|
+
[constants_1.SITE_ENV_VAR]: 'datadoghq.com',
|
|
171
|
+
[constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
|
|
172
|
+
[constants_1.VERSION_ENV_VAR]: '0.2',
|
|
173
|
+
USER_VARIABLE: 'shouldnt be deleted by uninstrumentation',
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument',
|
|
177
|
+
Handler: 'datadog_lambda.handler.handler',
|
|
178
|
+
Runtime: 'python3.8',
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
const cloudWatch = fixtures_1.makeMockCloudWatchLogs({});
|
|
182
|
+
const result = yield uninstrument_1.getUninstrumentedFunctionConfigs(lambda, cloudWatch, ['arn:aws:lambda:us-east-1:000000000000:function:uninstrument'], undefined);
|
|
183
|
+
expect(result.length).toEqual(1);
|
|
184
|
+
expect(result[0].updateRequest).toMatchInlineSnapshot(`
|
|
185
|
+
Object {
|
|
186
|
+
"Environment": Object {
|
|
187
|
+
"Variables": Object {
|
|
188
|
+
"USER_VARIABLE": "shouldnt be deleted by uninstrumentation",
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
"FunctionName": "arn:aws:lambda:us-east-1:000000000000:function:uninstrument",
|
|
192
|
+
"Handler": "lambda_function.lambda_handler",
|
|
193
|
+
}
|
|
194
|
+
`);
|
|
195
|
+
}));
|
|
196
|
+
test('returns results for multiple functions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
197
|
+
const lambda = fixtures_1.makeMockLambda({
|
|
198
|
+
'arn:aws:lambda:us-east-1:000000000000:function:another-func': {
|
|
199
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:another-func',
|
|
200
|
+
Runtime: 'nodejs12.x',
|
|
201
|
+
},
|
|
202
|
+
'arn:aws:lambda:us-east-1:000000000000:function:uninstrument': {
|
|
203
|
+
Environment: {
|
|
204
|
+
Variables: {
|
|
205
|
+
[constants_1.FLUSH_TO_LOG_ENV_VAR]: 'false',
|
|
206
|
+
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'index.handler',
|
|
207
|
+
[constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
|
|
208
|
+
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
209
|
+
[constants_1.SITE_ENV_VAR]: 'datadoghq.com',
|
|
210
|
+
[constants_1.TRACE_ENABLED_ENV_VAR]: 'false',
|
|
211
|
+
[constants_1.SERVICE_ENV_VAR]: 'middletier',
|
|
212
|
+
[constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
|
|
213
|
+
[constants_1.VERSION_ENV_VAR]: '0.2',
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument',
|
|
217
|
+
Handler: '/opt/nodejs/node_modules/datadog-lambda-js/handler.handler',
|
|
218
|
+
Runtime: 'nodejs12.x',
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
const cloudWatch = fixtures_1.makeMockCloudWatchLogs({});
|
|
222
|
+
const result = yield uninstrument_1.getUninstrumentedFunctionConfigs(lambda, cloudWatch, [
|
|
223
|
+
'arn:aws:lambda:us-east-1:000000000000:function:another-func',
|
|
224
|
+
'arn:aws:lambda:us-east-1:000000000000:function:uninstrument',
|
|
225
|
+
], undefined);
|
|
226
|
+
expect(result.length).toEqual(2);
|
|
227
|
+
expect(result[0].updateRequest).toBeUndefined();
|
|
228
|
+
expect(result[1].updateRequest).toMatchInlineSnapshot(`
|
|
229
|
+
Object {
|
|
230
|
+
"Environment": Object {
|
|
231
|
+
"Variables": Object {},
|
|
232
|
+
},
|
|
233
|
+
"FunctionName": "arn:aws:lambda:us-east-1:000000000000:function:uninstrument",
|
|
234
|
+
"Handler": "index.handler",
|
|
235
|
+
}
|
|
236
|
+
`);
|
|
237
|
+
}));
|
|
238
|
+
});
|
|
239
|
+
describe('getUninstrumentedFunctionConfig', () => {
|
|
240
|
+
const OLD_ENV = process.env;
|
|
241
|
+
beforeEach(() => {
|
|
242
|
+
jest.resetModules();
|
|
243
|
+
process.env = {};
|
|
244
|
+
});
|
|
245
|
+
afterAll(() => {
|
|
246
|
+
process.env = OLD_ENV;
|
|
247
|
+
});
|
|
248
|
+
test('throws an error when it encounters an unsupported runtime', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
249
|
+
const lambda = fixtures_1.makeMockLambda({
|
|
250
|
+
'arn:aws:lambda:us-east-1:000000000000:function:uninstrument': {
|
|
251
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument',
|
|
252
|
+
Runtime: 'go',
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
const cloudWatch = fixtures_1.makeMockCloudWatchLogs({});
|
|
256
|
+
const config = yield commons_1.getLambdaFunctionConfig(lambda, 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument');
|
|
257
|
+
yield expect(uninstrument_1.getUninstrumentedFunctionConfig(lambda, cloudWatch, config, undefined)).rejects.toThrow();
|
|
258
|
+
}));
|
|
259
|
+
test('returns configurations without updateRequest when no changes need to be made', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
260
|
+
const lambda = fixtures_1.makeMockLambda({
|
|
261
|
+
'arn:aws:lambda:us-east-1:000000000000:function:uninstrument': {
|
|
262
|
+
Environment: {
|
|
263
|
+
Variables: {},
|
|
264
|
+
},
|
|
265
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument',
|
|
266
|
+
Handler: 'index.handler',
|
|
267
|
+
Runtime: 'nodejs12.x',
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
const cloudWatch = fixtures_1.makeMockCloudWatchLogs({});
|
|
271
|
+
const config = yield commons_1.getLambdaFunctionConfig(lambda, 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument');
|
|
272
|
+
expect((yield uninstrument_1.getUninstrumentedFunctionConfig(lambda, cloudWatch, config, undefined)).updateRequest).toBeUndefined();
|
|
273
|
+
}));
|
|
274
|
+
test('returns log group configuration subscription delete request when forwarderARN is set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
275
|
+
const logGroupName = '/aws/lambda/group';
|
|
276
|
+
loggroup.calculateLogGroupRemoveRequest.mockImplementation(() => ({
|
|
277
|
+
filterName: constants_1.SUBSCRIPTION_FILTER_NAME,
|
|
278
|
+
logGroupName,
|
|
279
|
+
}));
|
|
280
|
+
const lambda = fixtures_1.makeMockLambda({
|
|
281
|
+
'arn:aws:lambda:us-east-1:000000000000:function:uninstrument': {
|
|
282
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument',
|
|
283
|
+
Handler: 'index.handler',
|
|
284
|
+
Runtime: 'nodejs12.x',
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
const cloudWatch = fixtures_1.makeMockCloudWatchLogs({});
|
|
288
|
+
const config = yield commons_1.getLambdaFunctionConfig(lambda, 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument');
|
|
289
|
+
const result = yield uninstrument_1.getUninstrumentedFunctionConfig(lambda, cloudWatch, config, 'valid-forwarder-arn');
|
|
290
|
+
expect(result).toBeDefined();
|
|
291
|
+
expect(result.logGroupConfiguration).toMatchInlineSnapshot(`
|
|
292
|
+
Object {
|
|
293
|
+
"filterName": "${constants_1.SUBSCRIPTION_FILTER_NAME}",
|
|
294
|
+
"logGroupName": "${logGroupName}",
|
|
295
|
+
}
|
|
296
|
+
`);
|
|
297
|
+
}));
|
|
298
|
+
});
|
|
299
|
+
describe('getUninstrumentedFunctionConfigsFromRegEx', () => {
|
|
300
|
+
const OLD_ENV = process.env;
|
|
301
|
+
beforeEach(() => {
|
|
302
|
+
jest.resetModules();
|
|
303
|
+
process.env = {};
|
|
304
|
+
});
|
|
305
|
+
afterAll(() => {
|
|
306
|
+
process.env = OLD_ENV;
|
|
307
|
+
});
|
|
308
|
+
test('returns the update request for each function that matches the pattern', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
309
|
+
const lambda = fixtures_1.makeMockLambda({
|
|
310
|
+
'autoinstrument-scooby': {
|
|
311
|
+
Environment: {
|
|
312
|
+
Variables: {
|
|
313
|
+
[constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
|
|
314
|
+
[constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
|
|
315
|
+
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'index.handler',
|
|
316
|
+
[constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
|
|
317
|
+
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
318
|
+
[constants_1.SERVICE_ENV_VAR]: 'middletier',
|
|
319
|
+
[constants_1.SITE_ENV_VAR]: 'datadoghq.com',
|
|
320
|
+
[constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
|
|
321
|
+
[constants_1.VERSION_ENV_VAR]: '0.2',
|
|
322
|
+
USER_VARIABLE: 'shouldnt be deleted by uninstrumentation',
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument-scooby',
|
|
326
|
+
FunctionName: 'autoinstrument-scooby',
|
|
327
|
+
Handler: '/opt/nodejs/node_modules/datadog-lambda-js/handler.handler',
|
|
328
|
+
Runtime: 'nodejs12.x',
|
|
329
|
+
},
|
|
330
|
+
'autoinstrument-scrapy': {
|
|
331
|
+
Environment: {
|
|
332
|
+
Variables: {
|
|
333
|
+
[constants_1.API_KEY_ENV_VAR]: '1234',
|
|
334
|
+
[constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
|
|
335
|
+
[constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
|
|
336
|
+
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'index.handler',
|
|
337
|
+
[constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
|
|
338
|
+
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument-scrapy',
|
|
342
|
+
FunctionName: 'autoinstrument-scrapy',
|
|
343
|
+
Handler: '/opt/nodejs/node_modules/datadog-lambda-js/handler.handler',
|
|
344
|
+
Runtime: 'nodejs12.x',
|
|
345
|
+
},
|
|
346
|
+
});
|
|
347
|
+
const cloudWatch = fixtures_1.makeMockCloudWatchLogs({});
|
|
348
|
+
const result = yield uninstrument_1.getUninstrumentedFunctionConfigsFromRegEx(lambda, cloudWatch, 'autoinstrument-scr.', undefined);
|
|
349
|
+
expect(result.length).toEqual(1);
|
|
350
|
+
expect(result[0].updateRequest).toMatchInlineSnapshot(`
|
|
351
|
+
Object {
|
|
352
|
+
"Environment": Object {
|
|
353
|
+
"Variables": Object {},
|
|
354
|
+
},
|
|
355
|
+
"FunctionName": "arn:aws:lambda:us-east-1:000000000000:function:autoinstrument-scrapy",
|
|
356
|
+
"Handler": "index.handler",
|
|
357
|
+
}
|
|
358
|
+
`);
|
|
359
|
+
}));
|
|
360
|
+
test('fails when retry count is exceeded', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
361
|
+
const makeMockLambdaListFunctionsError = () => ({
|
|
362
|
+
listFunctions: jest.fn().mockImplementation((args) => ({
|
|
363
|
+
promise: () => Promise.reject(),
|
|
364
|
+
})),
|
|
365
|
+
});
|
|
366
|
+
const lambda = makeMockLambdaListFunctionsError();
|
|
367
|
+
const cloudWatch = fixtures_1.makeMockCloudWatchLogs({});
|
|
368
|
+
yield expect(uninstrument_1.getUninstrumentedFunctionConfigsFromRegEx(lambda, cloudWatch, 'fake-pattern', undefined)).rejects.toStrictEqual(new Error('Max retry count exceeded.'));
|
|
369
|
+
}));
|
|
370
|
+
});
|
|
371
|
+
});
|