@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
|
@@ -9,107 +9,61 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.calculateUpdateRequest = exports.
|
|
12
|
+
exports.calculateUpdateRequest = exports.getInstrumentedFunctionConfigsFromRegEx = exports.getInstrumentedFunctionConfig = exports.getInstrumentedFunctionConfigs = void 0;
|
|
13
13
|
const constants_1 = require("../constants");
|
|
14
14
|
const loggroup_1 = require("../loggroup");
|
|
15
15
|
const tags_1 = require("../tags");
|
|
16
16
|
const commons_1 = require("./commons");
|
|
17
|
-
const
|
|
17
|
+
const getInstrumentedFunctionConfigs = (lambda, cloudWatch, region, functionARNs, settings) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
18
|
const lambdaFunctionConfigs = yield commons_1.getLambdaFunctionConfigs(lambda, functionARNs);
|
|
19
19
|
const configs = [];
|
|
20
20
|
for (const config of lambdaFunctionConfigs) {
|
|
21
|
-
const functionConfig = yield exports.
|
|
21
|
+
const functionConfig = yield exports.getInstrumentedFunctionConfig(lambda, cloudWatch, config, region, settings);
|
|
22
22
|
configs.push(functionConfig);
|
|
23
23
|
}
|
|
24
24
|
return configs;
|
|
25
25
|
});
|
|
26
|
-
exports.
|
|
27
|
-
const
|
|
26
|
+
exports.getInstrumentedFunctionConfigs = getInstrumentedFunctionConfigs;
|
|
27
|
+
const getInstrumentedFunctionConfig = (lambda, cloudWatch, config, region, settings) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
28
|
const functionARN = config.FunctionArn;
|
|
29
29
|
const runtime = config.Runtime;
|
|
30
30
|
if (!commons_1.isSupportedRuntime(runtime)) {
|
|
31
31
|
throw Error(`Can't instrument ${functionARN}, runtime ${runtime} not supported`);
|
|
32
32
|
}
|
|
33
33
|
yield commons_1.isLambdaActive(lambda, config, functionARN);
|
|
34
|
-
const
|
|
35
|
-
const lambdaExtensionLayerArn = exports.getExtensionArn(settings, region);
|
|
36
|
-
const updateRequest = exports.calculateUpdateRequest(config, settings, lambdaLibraryLayerArn, lambdaExtensionLayerArn, runtime);
|
|
34
|
+
const updateRequest = yield exports.calculateUpdateRequest(config, settings, region, runtime);
|
|
37
35
|
let logGroupConfiguration;
|
|
38
36
|
if (settings.forwarderARN !== undefined) {
|
|
39
|
-
const
|
|
40
|
-
logGroupConfiguration = yield loggroup_1.calculateLogGroupUpdateRequest(cloudWatch,
|
|
37
|
+
const logGroupName = `/aws/lambda/${config.FunctionName}`;
|
|
38
|
+
logGroupConfiguration = yield loggroup_1.calculateLogGroupUpdateRequest(cloudWatch, logGroupName, settings.forwarderARN);
|
|
41
39
|
}
|
|
42
40
|
const tagConfiguration = yield tags_1.calculateTagUpdateRequest(lambda, functionARN);
|
|
43
41
|
return {
|
|
44
42
|
functionARN,
|
|
45
43
|
lambdaConfig: config,
|
|
46
|
-
lambdaLibraryLayerArn,
|
|
47
44
|
logGroupConfiguration,
|
|
48
45
|
tagConfiguration,
|
|
49
46
|
updateRequest,
|
|
50
47
|
};
|
|
51
48
|
});
|
|
52
|
-
exports.
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
const regEx = new RegExp(pattern);
|
|
56
|
-
const matchedFunctions = [];
|
|
57
|
-
let retryCount = 0;
|
|
58
|
-
let listFunctionsResponse;
|
|
59
|
-
let nextMarker;
|
|
60
|
-
while (true) {
|
|
61
|
-
try {
|
|
62
|
-
listFunctionsResponse = yield lambda.listFunctions({ Marker: nextMarker }).promise();
|
|
63
|
-
(_a = listFunctionsResponse.Functions) === null || _a === void 0 ? void 0 : _a.map((fn) => { var _a; return ((_a = fn.FunctionName) === null || _a === void 0 ? void 0 : _a.match(regEx)) && matchedFunctions.push(fn); });
|
|
64
|
-
nextMarker = listFunctionsResponse.NextMarker;
|
|
65
|
-
if (!nextMarker) {
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
retryCount = 0;
|
|
69
|
-
}
|
|
70
|
-
catch (e) {
|
|
71
|
-
retryCount++;
|
|
72
|
-
if (retryCount > constants_1.LIST_FUNCTIONS_MAX_RETRY_COUNT) {
|
|
73
|
-
throw Error('Max retry count exceeded.');
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
49
|
+
exports.getInstrumentedFunctionConfig = getInstrumentedFunctionConfig;
|
|
50
|
+
const getInstrumentedFunctionConfigsFromRegEx = (lambda, cloudWatch, region, pattern, settings) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
+
const matchedFunctions = yield commons_1.getLambdaFunctionConfigsFromRegex(lambda, pattern);
|
|
77
52
|
const functionsToUpdate = [];
|
|
78
53
|
for (const config of matchedFunctions) {
|
|
79
|
-
const functionConfig = yield exports.
|
|
54
|
+
const functionConfig = yield exports.getInstrumentedFunctionConfig(lambda, cloudWatch, config, region, settings);
|
|
80
55
|
functionsToUpdate.push(functionConfig);
|
|
81
56
|
}
|
|
82
57
|
return functionsToUpdate;
|
|
83
58
|
});
|
|
84
|
-
exports.
|
|
85
|
-
const
|
|
86
|
-
var _a;
|
|
87
|
-
const layerName = constants_1.RUNTIME_LAYER_LOOKUP[runtime];
|
|
88
|
-
const account = (_a = settings.layerAWSAccount) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_LAYER_AWS_ACCOUNT;
|
|
89
|
-
const isGovCloud = region.startsWith('us-gov');
|
|
90
|
-
if (isGovCloud) {
|
|
91
|
-
return `arn:aws-us-gov:lambda:${region}:${constants_1.GOVCLOUD_LAYER_AWS_ACCOUNT}:layer:${layerName}`;
|
|
92
|
-
}
|
|
93
|
-
return `arn:aws:lambda:${region}:${account}:layer:${layerName}`;
|
|
94
|
-
};
|
|
95
|
-
exports.getLayerArn = getLayerArn;
|
|
96
|
-
const getExtensionArn = (settings, region) => {
|
|
97
|
-
var _a;
|
|
98
|
-
const layerName = constants_1.DD_LAMBDA_EXTENSION_LAYER_NAME;
|
|
99
|
-
const account = (_a = settings.layerAWSAccount) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_LAYER_AWS_ACCOUNT;
|
|
100
|
-
const isGovCloud = region.startsWith('us-gov');
|
|
101
|
-
if (isGovCloud) {
|
|
102
|
-
return `arn:aws-us-gov:lambda:${region}:${constants_1.GOVCLOUD_LAYER_AWS_ACCOUNT}:layer:${layerName}`;
|
|
103
|
-
}
|
|
104
|
-
return `arn:aws:lambda:${region}:${account}:layer:${layerName}`;
|
|
105
|
-
};
|
|
106
|
-
exports.getExtensionArn = getExtensionArn;
|
|
107
|
-
const calculateUpdateRequest = (config, settings, lambdaLibraryLayerArn, lambdaExtensionLayerArn, runtime) => {
|
|
108
|
-
var _a, _b, _c, _d, _e;
|
|
59
|
+
exports.getInstrumentedFunctionConfigsFromRegEx = getInstrumentedFunctionConfigsFromRegEx;
|
|
60
|
+
const calculateUpdateRequest = (config, settings, region, runtime) => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
+
var _a, _b, _c, _d;
|
|
109
62
|
const oldEnvVars = Object.assign({}, (_a = config.Environment) === null || _a === void 0 ? void 0 : _a.Variables);
|
|
110
63
|
const changedEnvVars = {};
|
|
111
64
|
const functionARN = config.FunctionArn;
|
|
112
65
|
const apiKey = process.env[constants_1.CI_API_KEY_ENV_VAR];
|
|
66
|
+
const apiKeySecretArn = process.env[constants_1.CI_API_KEY_SECRET_ARN_ENV_VAR];
|
|
113
67
|
const apiKmsKey = process.env[constants_1.CI_KMS_API_KEY_ENV_VAR];
|
|
114
68
|
const site = process.env[constants_1.CI_SITE_ENV_VAR];
|
|
115
69
|
if (functionARN === undefined) {
|
|
@@ -130,22 +84,31 @@ const calculateUpdateRequest = (config, settings, lambdaLibraryLayerArn, lambdaE
|
|
|
130
84
|
needsUpdate = true;
|
|
131
85
|
changedEnvVars[constants_1.LAMBDA_HANDLER_ENV_VAR] = (_b = config.Handler) !== null && _b !== void 0 ? _b : '';
|
|
132
86
|
}
|
|
133
|
-
|
|
134
|
-
needsUpdate = true;
|
|
135
|
-
changedEnvVars[constants_1.API_KEY_ENV_VAR] = apiKey;
|
|
136
|
-
}
|
|
87
|
+
// KMS > Secrets Manager > API Key
|
|
137
88
|
if (apiKmsKey !== undefined && oldEnvVars[constants_1.KMS_API_KEY_ENV_VAR] !== apiKmsKey) {
|
|
138
89
|
needsUpdate = true;
|
|
139
90
|
changedEnvVars[constants_1.KMS_API_KEY_ENV_VAR] = apiKmsKey;
|
|
140
91
|
}
|
|
92
|
+
else if (apiKeySecretArn !== undefined && oldEnvVars[constants_1.API_KEY_SECRET_ARN_ENV_VAR] !== apiKeySecretArn) {
|
|
93
|
+
const isNode = constants_1.RUNTIME_LOOKUP[runtime] === constants_1.RuntimeType.NODE;
|
|
94
|
+
const isSendingSynchronousMetrics = settings.extensionVersion === undefined && !settings.flushMetricsToLogs;
|
|
95
|
+
if (isSendingSynchronousMetrics && isNode) {
|
|
96
|
+
throw new Error('`apiKeySecretArn` is not supported for Node runtimes when using Synchronous Metrics. Use either `apiKey` or `apiKmsKey`.');
|
|
97
|
+
}
|
|
98
|
+
needsUpdate = true;
|
|
99
|
+
changedEnvVars[constants_1.API_KEY_SECRET_ARN_ENV_VAR] = apiKeySecretArn;
|
|
100
|
+
}
|
|
101
|
+
else if (apiKey !== undefined && oldEnvVars[constants_1.API_KEY_ENV_VAR] !== apiKey) {
|
|
102
|
+
needsUpdate = true;
|
|
103
|
+
changedEnvVars[constants_1.API_KEY_ENV_VAR] = apiKey;
|
|
104
|
+
}
|
|
141
105
|
if (site !== undefined && oldEnvVars[constants_1.SITE_ENV_VAR] !== site) {
|
|
142
|
-
|
|
143
|
-
if (siteList.includes(site.toLowerCase())) {
|
|
106
|
+
if (constants_1.SITES.includes(site.toLowerCase())) {
|
|
144
107
|
needsUpdate = true;
|
|
145
108
|
changedEnvVars[constants_1.SITE_ENV_VAR] = site;
|
|
146
109
|
}
|
|
147
110
|
else {
|
|
148
|
-
throw new Error('Warning: Invalid site URL. Must be either datadoghq.com, datadoghq.eu, us3.datadoghq.com, or ddog-gov.com.');
|
|
111
|
+
throw new Error('Warning: Invalid site URL. Must be either datadoghq.com, datadoghq.eu, us3.datadoghq.com, us5.datadoghq.com, or ddog-gov.com.');
|
|
149
112
|
}
|
|
150
113
|
}
|
|
151
114
|
if (site === undefined && oldEnvVars[constants_1.SITE_ENV_VAR] === undefined) {
|
|
@@ -153,9 +116,9 @@ const calculateUpdateRequest = (config, settings, lambdaLibraryLayerArn, lambdaE
|
|
|
153
116
|
changedEnvVars[constants_1.SITE_ENV_VAR] = 'datadoghq.com';
|
|
154
117
|
}
|
|
155
118
|
const environmentVarsTupleArray = [
|
|
119
|
+
['captureLambdaPayload', constants_1.CAPTURE_LAMBDA_PAYLOAD_ENV_VAR],
|
|
156
120
|
['environment', constants_1.ENVIRONMENT_ENV_VAR],
|
|
157
121
|
['extraTags', constants_1.EXTRA_TAGS_ENV_VAR],
|
|
158
|
-
['flushMetricsToLogs', constants_1.FLUSH_TO_LOG_ENV_VAR],
|
|
159
122
|
['mergeXrayTraces', constants_1.MERGE_XRAY_TRACES_ENV_VAR],
|
|
160
123
|
['service', constants_1.SERVICE_ENV_VAR],
|
|
161
124
|
['tracingEnabled', constants_1.TRACE_ENABLED_ENV_VAR],
|
|
@@ -167,6 +130,14 @@ const calculateUpdateRequest = (config, settings, lambdaLibraryLayerArn, lambdaE
|
|
|
167
130
|
changedEnvVars[environmentVar] = settings[key].toString();
|
|
168
131
|
}
|
|
169
132
|
}
|
|
133
|
+
// Skip adding DD_FLUSH_TO_LOGS when using Extension
|
|
134
|
+
const isUsingExtension = settings.extensionVersion !== undefined;
|
|
135
|
+
if (!isUsingExtension &&
|
|
136
|
+
settings.flushMetricsToLogs !== undefined &&
|
|
137
|
+
oldEnvVars[constants_1.FLUSH_TO_LOG_ENV_VAR] !== ((_d = settings.flushMetricsToLogs) === null || _d === void 0 ? void 0 : _d.toString())) {
|
|
138
|
+
needsUpdate = true;
|
|
139
|
+
changedEnvVars[constants_1.FLUSH_TO_LOG_ENV_VAR] = settings.flushMetricsToLogs.toString();
|
|
140
|
+
}
|
|
170
141
|
const newEnvVars = Object.assign(Object.assign({}, oldEnvVars), changedEnvVars);
|
|
171
142
|
if (newEnvVars[constants_1.LOG_LEVEL_ENV_VAR] !== settings.logLevel) {
|
|
172
143
|
needsUpdate = true;
|
|
@@ -181,19 +152,30 @@ const calculateUpdateRequest = (config, settings, lambdaLibraryLayerArn, lambdaE
|
|
|
181
152
|
Variables: newEnvVars,
|
|
182
153
|
};
|
|
183
154
|
// Update Layers
|
|
155
|
+
const lambdaLibraryLayerArn = commons_1.getLayerArn(config, config.Runtime, region, settings);
|
|
156
|
+
const lambraLibraryLayerName = constants_1.RUNTIME_LAYER_LOOKUP[runtime];
|
|
184
157
|
let fullLambdaLibraryLayerARN;
|
|
185
|
-
if (settings.layerVersion !== undefined) {
|
|
186
|
-
|
|
158
|
+
if (settings.layerVersion !== undefined || settings.interactive) {
|
|
159
|
+
let layerVersion = settings.layerVersion;
|
|
160
|
+
if (settings.interactive && !settings.layerVersion) {
|
|
161
|
+
layerVersion = yield commons_1.findLatestLayerVersion(config.Runtime, region);
|
|
162
|
+
}
|
|
163
|
+
fullLambdaLibraryLayerARN = `${lambdaLibraryLayerArn}:${layerVersion}`;
|
|
187
164
|
}
|
|
165
|
+
const lambdaExtensionLayerArn = commons_1.getLayerArn(config, constants_1.EXTENSION_LAYER_KEY, region, settings);
|
|
188
166
|
let fullExtensionLayerARN;
|
|
189
|
-
if (settings.extensionVersion !== undefined) {
|
|
190
|
-
|
|
167
|
+
if (settings.extensionVersion !== undefined || settings.interactive) {
|
|
168
|
+
let extensionVersion = settings.extensionVersion;
|
|
169
|
+
if (settings.interactive && !settings.extensionVersion) {
|
|
170
|
+
extensionVersion = yield commons_1.findLatestLayerVersion(constants_1.EXTENSION_LAYER_KEY, region);
|
|
171
|
+
}
|
|
172
|
+
fullExtensionLayerARN = `${lambdaExtensionLayerArn}:${extensionVersion}`;
|
|
191
173
|
}
|
|
192
|
-
let layerARNs = (
|
|
193
|
-
const originalLayerARNs =
|
|
174
|
+
let layerARNs = commons_1.getLayers(config);
|
|
175
|
+
const originalLayerARNs = layerARNs;
|
|
194
176
|
let needsLayerUpdate = false;
|
|
195
|
-
layerARNs = commons_1.
|
|
196
|
-
layerARNs = commons_1.
|
|
177
|
+
layerARNs = commons_1.addLayerArn(fullLambdaLibraryLayerARN, lambraLibraryLayerName, layerARNs);
|
|
178
|
+
layerARNs = commons_1.addLayerArn(fullExtensionLayerARN, constants_1.DD_LAMBDA_EXTENSION_LAYER_NAME, layerARNs);
|
|
197
179
|
if (originalLayerARNs.sort().join(',') !== layerARNs.sort().join(',')) {
|
|
198
180
|
needsLayerUpdate = true;
|
|
199
181
|
}
|
|
@@ -204,10 +186,11 @@ const calculateUpdateRequest = (config, settings, lambdaLibraryLayerArn, lambdaE
|
|
|
204
186
|
layerARNs.forEach((layerARN) => {
|
|
205
187
|
if (layerARN.includes(constants_1.DD_LAMBDA_EXTENSION_LAYER_NAME) &&
|
|
206
188
|
newEnvVars[constants_1.API_KEY_ENV_VAR] === undefined &&
|
|
189
|
+
newEnvVars[constants_1.API_KEY_SECRET_ARN_ENV_VAR] === undefined &&
|
|
207
190
|
newEnvVars[constants_1.KMS_API_KEY_ENV_VAR] === undefined) {
|
|
208
|
-
throw new Error(`When 'extensionLayer' is set, ${constants_1.CI_API_KEY_ENV_VAR} or ${constants_1.
|
|
191
|
+
throw new Error(`When 'extensionLayer' is set, ${constants_1.CI_API_KEY_ENV_VAR}, ${constants_1.CI_KMS_API_KEY_ENV_VAR}, or ${constants_1.CI_API_KEY_SECRET_ARN_ENV_VAR} must also be set`);
|
|
209
192
|
}
|
|
210
193
|
});
|
|
211
194
|
return needsUpdate ? updateRequest : undefined;
|
|
212
|
-
};
|
|
195
|
+
});
|
|
213
196
|
exports.calculateUpdateRequest = calculateUpdateRequest;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CloudWatchLogs, Lambda } from 'aws-sdk';
|
|
2
2
|
import { Runtime } from '../constants';
|
|
3
3
|
import { FunctionConfiguration } from '../interfaces';
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
4
|
+
export declare const getUninstrumentedFunctionConfigs: (lambda: Lambda, cloudWatch: CloudWatchLogs, functionARNs: string[], forwarderARN: string | undefined) => Promise<FunctionConfiguration[]>;
|
|
5
|
+
export declare const getUninstrumentedFunctionConfig: (lambda: Lambda, cloudWatch: CloudWatchLogs, config: Lambda.FunctionConfiguration, forwarderARN: string | undefined) => Promise<FunctionConfiguration>;
|
|
6
|
+
export declare const getUninstrumentedFunctionConfigsFromRegEx: (lambda: Lambda, cloudWatch: CloudWatchLogs, pattern: string, forwarderArn: string | undefined) => Promise<FunctionConfiguration[]>;
|
|
6
7
|
export declare const calculateUpdateRequest: (config: Lambda.FunctionConfiguration, runtime: Runtime) => Lambda.UpdateFunctionConfigurationRequest | undefined;
|
|
@@ -9,22 +9,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.calculateUpdateRequest = exports.
|
|
12
|
+
exports.calculateUpdateRequest = exports.getUninstrumentedFunctionConfigsFromRegEx = exports.getUninstrumentedFunctionConfig = exports.getUninstrumentedFunctionConfigs = void 0;
|
|
13
13
|
const constants_1 = require("../constants");
|
|
14
14
|
const loggroup_1 = require("../loggroup");
|
|
15
15
|
const tags_1 = require("../tags");
|
|
16
16
|
const commons_1 = require("./commons");
|
|
17
|
-
const
|
|
17
|
+
const getUninstrumentedFunctionConfigs = (lambda, cloudWatch, functionARNs, forwarderARN) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
18
|
const lambdaFunctionConfigs = yield commons_1.getLambdaFunctionConfigs(lambda, functionARNs);
|
|
19
19
|
const configs = [];
|
|
20
20
|
for (const config of lambdaFunctionConfigs) {
|
|
21
|
-
const functionConfig = yield exports.
|
|
21
|
+
const functionConfig = yield exports.getUninstrumentedFunctionConfig(lambda, cloudWatch, config, forwarderARN);
|
|
22
22
|
configs.push(functionConfig);
|
|
23
23
|
}
|
|
24
24
|
return configs;
|
|
25
25
|
});
|
|
26
|
-
exports.
|
|
27
|
-
const
|
|
26
|
+
exports.getUninstrumentedFunctionConfigs = getUninstrumentedFunctionConfigs;
|
|
27
|
+
const getUninstrumentedFunctionConfig = (lambda, cloudWatch, config, forwarderARN) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
28
|
const functionARN = config.FunctionArn;
|
|
29
29
|
const runtime = config.Runtime;
|
|
30
30
|
if (!commons_1.isSupportedRuntime(runtime)) {
|
|
@@ -33,8 +33,8 @@ const getFunctionConfig = (lambda, cloudWatch, config, forwarderARN) => __awaite
|
|
|
33
33
|
const updateRequest = exports.calculateUpdateRequest(config, runtime);
|
|
34
34
|
let logGroupConfiguration;
|
|
35
35
|
if (forwarderARN) {
|
|
36
|
-
const
|
|
37
|
-
logGroupConfiguration = yield loggroup_1.calculateLogGroupRemoveRequest(cloudWatch,
|
|
36
|
+
const logGroupName = `/aws/lambda/${config.FunctionName}`;
|
|
37
|
+
logGroupConfiguration = yield loggroup_1.calculateLogGroupRemoveRequest(cloudWatch, logGroupName, forwarderARN);
|
|
38
38
|
}
|
|
39
39
|
const tagConfiguration = yield tags_1.calculateTagRemoveRequest(lambda, functionARN);
|
|
40
40
|
return {
|
|
@@ -45,9 +45,19 @@ const getFunctionConfig = (lambda, cloudWatch, config, forwarderARN) => __awaite
|
|
|
45
45
|
updateRequest,
|
|
46
46
|
};
|
|
47
47
|
});
|
|
48
|
-
exports.
|
|
48
|
+
exports.getUninstrumentedFunctionConfig = getUninstrumentedFunctionConfig;
|
|
49
|
+
const getUninstrumentedFunctionConfigsFromRegEx = (lambda, cloudWatch, pattern, forwarderArn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
const matchedFunctions = yield commons_1.getLambdaFunctionConfigsFromRegex(lambda, pattern);
|
|
51
|
+
const functionsToUpdate = [];
|
|
52
|
+
for (const config of matchedFunctions) {
|
|
53
|
+
const functionConfig = yield exports.getUninstrumentedFunctionConfig(lambda, cloudWatch, config, forwarderArn);
|
|
54
|
+
functionsToUpdate.push(functionConfig);
|
|
55
|
+
}
|
|
56
|
+
return functionsToUpdate;
|
|
57
|
+
});
|
|
58
|
+
exports.getUninstrumentedFunctionConfigsFromRegEx = getUninstrumentedFunctionConfigsFromRegEx;
|
|
49
59
|
const calculateUpdateRequest = (config, runtime) => {
|
|
50
|
-
var _a, _b
|
|
60
|
+
var _a, _b;
|
|
51
61
|
const oldEnvVars = Object.assign({}, (_a = config.Environment) === null || _a === void 0 ? void 0 : _a.Variables);
|
|
52
62
|
const functionARN = config.FunctionArn;
|
|
53
63
|
if (functionARN === undefined) {
|
|
@@ -70,8 +80,10 @@ const calculateUpdateRequest = (config, runtime) => {
|
|
|
70
80
|
*/
|
|
71
81
|
const environmentVarsArray = [
|
|
72
82
|
constants_1.API_KEY_ENV_VAR,
|
|
83
|
+
constants_1.API_KEY_SECRET_ARN_ENV_VAR,
|
|
73
84
|
constants_1.KMS_API_KEY_ENV_VAR,
|
|
74
85
|
constants_1.SITE_ENV_VAR,
|
|
86
|
+
constants_1.CAPTURE_LAMBDA_PAYLOAD_ENV_VAR,
|
|
75
87
|
constants_1.ENVIRONMENT_ENV_VAR,
|
|
76
88
|
constants_1.EXTRA_TAGS_ENV_VAR,
|
|
77
89
|
constants_1.FLUSH_TO_LOG_ENV_VAR,
|
|
@@ -94,8 +106,8 @@ const calculateUpdateRequest = (config, runtime) => {
|
|
|
94
106
|
// Remove Layers
|
|
95
107
|
let needsLayerRemoval = false;
|
|
96
108
|
const lambdaLibraryLayerName = constants_1.RUNTIME_LAYER_LOOKUP[runtime];
|
|
97
|
-
const originalLayerARNs = (
|
|
98
|
-
const layerARNs = ((
|
|
109
|
+
const originalLayerARNs = commons_1.getLayers(config);
|
|
110
|
+
const layerARNs = ((_b = config.Layers) !== null && _b !== void 0 ? _b : [])
|
|
99
111
|
.filter((layer) => { var _a, _b; return !((_a = layer.Arn) === null || _a === void 0 ? void 0 : _a.includes(lambdaLibraryLayerName)) && !((_b = layer.Arn) === null || _b === void 0 ? void 0 : _b.includes(constants_1.DD_LAMBDA_EXTENSION_LAYER_NAME)); })
|
|
100
112
|
.map((layer) => { var _a; return (_a = layer.Arn) !== null && _a !== void 0 ? _a : ''; });
|
|
101
113
|
if (originalLayerARNs.sort().join(',') !== layerARNs.sort().join(',')) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Command } from 'clipanion';
|
|
2
2
|
export declare class InstrumentCommand extends Command {
|
|
3
|
+
private captureLambdaPayload?;
|
|
3
4
|
private config;
|
|
4
5
|
private configPath?;
|
|
5
6
|
private dryRun;
|
|
@@ -9,6 +10,7 @@ export declare class InstrumentCommand extends Command {
|
|
|
9
10
|
private flushMetricsToLogs?;
|
|
10
11
|
private forwarder?;
|
|
11
12
|
private functions;
|
|
13
|
+
private interactive;
|
|
12
14
|
private layerAWSAccount?;
|
|
13
15
|
private layerVersion?;
|
|
14
16
|
private logLevel?;
|
|
@@ -20,7 +22,6 @@ export declare class InstrumentCommand extends Command {
|
|
|
20
22
|
private tracing?;
|
|
21
23
|
private version?;
|
|
22
24
|
execute(): Promise<1 | 0>;
|
|
23
|
-
private convertStringBooleanToBoolean;
|
|
24
25
|
private getCurrentGitStatus;
|
|
25
26
|
private getGitDataAndUpload;
|
|
26
27
|
private getSettings;
|