@datadog/datadog-ci 2.40.1 → 2.40.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/cli.test.d.ts +1 -0
- package/dist/__tests__/cli.test.js +41 -0
- package/dist/__tests__/cli.test.js.map +1 -0
- package/dist/commands/cloud-run/__tests__/fixtures.d.ts +2 -0
- package/dist/commands/cloud-run/__tests__/fixtures.js +12 -0
- package/dist/commands/cloud-run/__tests__/fixtures.js.map +1 -0
- package/dist/commands/cloud-run/__tests__/flare.test.d.ts +1 -0
- package/dist/commands/cloud-run/__tests__/flare.test.js +557 -0
- package/dist/commands/cloud-run/__tests__/flare.test.js.map +1 -0
- package/dist/commands/deployment/__tests__/mark.test.d.ts +1 -0
- package/dist/commands/deployment/__tests__/mark.test.js +47 -0
- package/dist/commands/deployment/__tests__/mark.test.js.map +1 -0
- package/dist/commands/dora/__tests__/deployment.test.d.ts +1 -0
- package/dist/commands/dora/__tests__/deployment.test.js +201 -0
- package/dist/commands/dora/__tests__/deployment.test.js.map +1 -0
- package/dist/commands/dsyms/__tests__/upload.test.d.ts +1 -0
- package/dist/commands/dsyms/__tests__/upload.test.js +346 -0
- package/dist/commands/dsyms/__tests__/upload.test.js.map +1 -0
- package/dist/commands/dsyms/__tests__/utils.test.d.ts +1 -0
- package/dist/commands/dsyms/__tests__/utils.test.js +100 -0
- package/dist/commands/dsyms/__tests__/utils.test.js.map +1 -0
- package/dist/commands/dsyms/upload.js +3 -3
- package/dist/commands/dsyms/upload.js.map +1 -1
- package/dist/commands/dsyms/utils.js +4 -2
- package/dist/commands/dsyms/utils.js.map +1 -1
- package/dist/commands/elf-symbols/__tests__/elf.test.d.ts +1 -0
- package/dist/commands/elf-symbols/__tests__/elf.test.js +813 -0
- package/dist/commands/elf-symbols/__tests__/elf.test.js.map +1 -0
- package/dist/commands/elf-symbols/__tests__/upload.test.d.ts +1 -0
- package/dist/commands/elf-symbols/__tests__/upload.test.js +249 -0
- package/dist/commands/elf-symbols/__tests__/upload.test.js.map +1 -0
- package/dist/commands/elf-symbols/upload.js +2 -3
- package/dist/commands/elf-symbols/upload.js.map +1 -1
- package/dist/commands/flutter-symbols/__tests__/upload.test.d.ts +1 -0
- package/dist/commands/flutter-symbols/__tests__/upload.test.js +617 -0
- package/dist/commands/flutter-symbols/__tests__/upload.test.js.map +1 -0
- package/dist/commands/flutter-symbols/upload.js +2 -2
- package/dist/commands/flutter-symbols/upload.js.map +1 -1
- package/dist/commands/gate/__tests__/evaluate.test.d.ts +1 -0
- package/dist/commands/gate/__tests__/evaluate.test.js +398 -0
- package/dist/commands/gate/__tests__/evaluate.test.js.map +1 -0
- package/dist/commands/gate/__tests__/scope.test.d.ts +1 -0
- package/dist/commands/gate/__tests__/scope.test.js +29 -0
- package/dist/commands/gate/__tests__/scope.test.js.map +1 -0
- package/dist/commands/git-metadata/__tests__/git.test.d.ts +1 -0
- package/dist/commands/git-metadata/__tests__/git.test.js +132 -0
- package/dist/commands/git-metadata/__tests__/git.test.js.map +1 -0
- package/dist/commands/git-metadata/__tests__/gitdb.test.d.ts +1 -0
- package/dist/commands/git-metadata/__tests__/gitdb.test.js +1386 -0
- package/dist/commands/git-metadata/__tests__/gitdb.test.js.map +1 -0
- package/dist/commands/git-metadata/__tests__/library.test.d.ts +1 -0
- package/dist/commands/git-metadata/__tests__/library.test.js +118 -0
- package/dist/commands/git-metadata/__tests__/library.test.js.map +1 -0
- package/dist/commands/git-metadata/__tests__/upload.test.d.ts +1 -0
- package/dist/commands/git-metadata/__tests__/upload.test.js +52 -0
- package/dist/commands/git-metadata/__tests__/upload.test.js.map +1 -0
- package/dist/commands/junit/__tests__/id.test.d.ts +1 -0
- package/dist/commands/junit/__tests__/id.test.js +24 -0
- package/dist/commands/junit/__tests__/id.test.js.map +1 -0
- package/dist/commands/junit/__tests__/upload.test.d.ts +1 -0
- package/dist/commands/junit/__tests__/upload.test.js +495 -0
- package/dist/commands/junit/__tests__/upload.test.js.map +1 -0
- package/dist/commands/junit/upload.js +5 -3
- package/dist/commands/junit/upload.js.map +1 -1
- package/dist/commands/lambda/__tests__/fixtures.d.ts +51 -0
- package/dist/commands/lambda/__tests__/fixtures.js +146 -0
- package/dist/commands/lambda/__tests__/fixtures.js.map +1 -0
- package/dist/commands/lambda/__tests__/flare.test.d.ts +1 -0
- package/dist/commands/lambda/__tests__/flare.test.js +730 -0
- package/dist/commands/lambda/__tests__/flare.test.js.map +1 -0
- package/dist/commands/lambda/__tests__/functions/commons.test.d.ts +1 -0
- package/dist/commands/lambda/__tests__/functions/commons.test.js +791 -0
- package/dist/commands/lambda/__tests__/functions/commons.test.js.map +1 -0
- package/dist/commands/lambda/__tests__/functions/instrument.part1.test.d.ts +1 -0
- package/dist/commands/lambda/__tests__/functions/instrument.part1.test.js +386 -0
- package/dist/commands/lambda/__tests__/functions/instrument.part1.test.js.map +1 -0
- package/dist/commands/lambda/__tests__/functions/instrument.part2.test.d.ts +1 -0
- package/dist/commands/lambda/__tests__/functions/instrument.part2.test.js +721 -0
- package/dist/commands/lambda/__tests__/functions/instrument.part2.test.js.map +1 -0
- package/dist/commands/lambda/__tests__/functions/uninstrument.test.d.ts +1 -0
- package/dist/commands/lambda/__tests__/functions/uninstrument.test.js +513 -0
- package/dist/commands/lambda/__tests__/functions/uninstrument.test.js.map +1 -0
- package/dist/commands/lambda/__tests__/functions/versionChecker.test.d.ts +1 -0
- package/dist/commands/lambda/__tests__/functions/versionChecker.test.js +33 -0
- package/dist/commands/lambda/__tests__/functions/versionChecker.test.js.map +1 -0
- package/dist/commands/lambda/__tests__/instrument.test.d.ts +1 -0
- package/dist/commands/lambda/__tests__/instrument.test.js +1511 -0
- package/dist/commands/lambda/__tests__/instrument.test.js.map +1 -0
- package/dist/commands/lambda/__tests__/loggroup.test.d.ts +1 -0
- package/dist/commands/lambda/__tests__/loggroup.test.js +340 -0
- package/dist/commands/lambda/__tests__/loggroup.test.js.map +1 -0
- package/dist/commands/lambda/__tests__/prompt.test.d.ts +1 -0
- package/dist/commands/lambda/__tests__/prompt.test.js +206 -0
- package/dist/commands/lambda/__tests__/prompt.test.js.map +1 -0
- package/dist/commands/lambda/__tests__/tags.test.d.ts +1 -0
- package/dist/commands/lambda/__tests__/tags.test.js +305 -0
- package/dist/commands/lambda/__tests__/tags.test.js.map +1 -0
- package/dist/commands/lambda/__tests__/uninstrument.test.d.ts +1 -0
- package/dist/commands/lambda/__tests__/uninstrument.test.js +722 -0
- package/dist/commands/lambda/__tests__/uninstrument.test.js.map +1 -0
- package/dist/commands/measure/__tests__/measure.test.d.ts +1 -0
- package/dist/commands/measure/__tests__/measure.test.js +110 -0
- package/dist/commands/measure/__tests__/measure.test.js.map +1 -0
- package/dist/commands/react-native/__tests__/codepush.test.d.ts +1 -0
- package/dist/commands/react-native/__tests__/codepush.test.js +161 -0
- package/dist/commands/react-native/__tests__/codepush.test.js.map +1 -0
- package/dist/commands/react-native/__tests__/interfaces.test.d.ts +1 -0
- package/dist/commands/react-native/__tests__/interfaces.test.js +33 -0
- package/dist/commands/react-native/__tests__/interfaces.test.js.map +1 -0
- package/dist/commands/react-native/__tests__/upload.test.d.ts +1 -0
- package/dist/commands/react-native/__tests__/upload.test.js +238 -0
- package/dist/commands/react-native/__tests__/upload.test.js.map +1 -0
- package/dist/commands/react-native/__tests__/utils.test.d.ts +1 -0
- package/dist/commands/react-native/__tests__/utils.test.js +27 -0
- package/dist/commands/react-native/__tests__/utils.test.js.map +1 -0
- package/dist/commands/react-native/__tests__/xcode.test.d.ts +1 -0
- package/dist/commands/react-native/__tests__/xcode.test.js +465 -0
- package/dist/commands/react-native/__tests__/xcode.test.js.map +1 -0
- package/dist/commands/sarif/__tests__/upload.test.d.ts +1 -0
- package/dist/commands/sarif/__tests__/upload.test.js +228 -0
- package/dist/commands/sarif/__tests__/upload.test.js.map +1 -0
- package/dist/commands/sarif/upload.js +2 -2
- package/dist/commands/sarif/upload.js.map +1 -1
- package/dist/commands/sbom/__tests__/payload.test.d.ts +1 -0
- package/dist/commands/sbom/__tests__/payload.test.js +262 -0
- package/dist/commands/sbom/__tests__/payload.test.js.map +1 -0
- package/dist/commands/sbom/__tests__/validation.test.d.ts +1 -0
- package/dist/commands/sbom/__tests__/validation.test.js +41 -0
- package/dist/commands/sbom/__tests__/validation.test.js.map +1 -0
- package/dist/commands/sourcemaps/__tests__/upload.test.d.ts +1 -0
- package/dist/commands/sourcemaps/__tests__/upload.test.js +270 -0
- package/dist/commands/sourcemaps/__tests__/upload.test.js.map +1 -0
- package/dist/commands/sourcemaps/__tests__/utils.test.d.ts +1 -0
- package/dist/commands/sourcemaps/__tests__/utils.test.js +31 -0
- package/dist/commands/sourcemaps/__tests__/utils.test.js.map +1 -0
- package/dist/commands/sourcemaps/upload.js +2 -2
- package/dist/commands/sourcemaps/upload.js.map +1 -1
- package/dist/commands/stepfunctions/__tests__/awsCommands.test.d.ts +1 -0
- package/dist/commands/stepfunctions/__tests__/awsCommands.test.js +192 -0
- package/dist/commands/stepfunctions/__tests__/awsCommands.test.js.map +1 -0
- package/dist/commands/stepfunctions/__tests__/fixtures/aws-resources.d.ts +6 -0
- package/dist/commands/stepfunctions/__tests__/fixtures/aws-resources.js +45 -0
- package/dist/commands/stepfunctions/__tests__/fixtures/aws-resources.js.map +1 -0
- package/dist/commands/stepfunctions/__tests__/fixtures/cli.d.ts +5 -0
- package/dist/commands/stepfunctions/__tests__/fixtures/cli.js +19 -0
- package/dist/commands/stepfunctions/__tests__/fixtures/cli.js.map +1 -0
- package/dist/commands/stepfunctions/__tests__/helpers.test.d.ts +1 -0
- package/dist/commands/stepfunctions/__tests__/helpers.test.js +205 -0
- package/dist/commands/stepfunctions/__tests__/helpers.test.js.map +1 -0
- package/dist/commands/stepfunctions/__tests__/instrument.test.d.ts +1 -0
- package/dist/commands/stepfunctions/__tests__/instrument.test.js +431 -0
- package/dist/commands/stepfunctions/__tests__/instrument.test.js.map +1 -0
- package/dist/commands/stepfunctions/__tests__/uninstrument.test.d.ts +1 -0
- package/dist/commands/stepfunctions/__tests__/uninstrument.test.js +166 -0
- package/dist/commands/stepfunctions/__tests__/uninstrument.test.js.map +1 -0
- package/dist/commands/synthetics/__tests__/api.test.d.ts +1 -0
- package/dist/commands/synthetics/__tests__/api.test.js +422 -0
- package/dist/commands/synthetics/__tests__/api.test.js.map +1 -0
- package/dist/commands/synthetics/__tests__/cli.test.d.ts +1 -0
- package/dist/commands/synthetics/__tests__/cli.test.js +1325 -0
- package/dist/commands/synthetics/__tests__/cli.test.js.map +1 -0
- package/dist/commands/synthetics/__tests__/fixtures.d.ts +149 -0
- package/dist/commands/synthetics/__tests__/fixtures.js +507 -0
- package/dist/commands/synthetics/__tests__/fixtures.js.map +1 -0
- package/dist/commands/synthetics/__tests__/mobile.test.d.ts +1 -0
- package/dist/commands/synthetics/__tests__/mobile.test.js +376 -0
- package/dist/commands/synthetics/__tests__/mobile.test.js.map +1 -0
- package/dist/commands/synthetics/__tests__/reporters/default.test.d.ts +1 -0
- package/dist/commands/synthetics/__tests__/reporters/default.test.js +354 -0
- package/dist/commands/synthetics/__tests__/reporters/default.test.js.map +1 -0
- package/dist/commands/synthetics/__tests__/reporters/junit.test.d.ts +1 -0
- package/dist/commands/synthetics/__tests__/reporters/junit.test.js +353 -0
- package/dist/commands/synthetics/__tests__/reporters/junit.test.js.map +1 -0
- package/dist/commands/synthetics/__tests__/reporters/mobile/app-upload.test.d.ts +1 -0
- package/dist/commands/synthetics/__tests__/reporters/mobile/app-upload.test.js +232 -0
- package/dist/commands/synthetics/__tests__/reporters/mobile/app-upload.test.js.map +1 -0
- package/dist/commands/synthetics/__tests__/run-tests-lib.test.d.ts +1 -0
- package/dist/commands/synthetics/__tests__/run-tests-lib.test.js +735 -0
- package/dist/commands/synthetics/__tests__/run-tests-lib.test.js.map +1 -0
- package/dist/commands/synthetics/__tests__/test.test.d.ts +1 -0
- package/dist/commands/synthetics/__tests__/test.test.js +33 -0
- package/dist/commands/synthetics/__tests__/test.test.js.map +1 -0
- package/dist/commands/synthetics/__tests__/tunnel/crypto.test.d.ts +1 -0
- package/dist/commands/synthetics/__tests__/tunnel/crypto.test.js +21 -0
- package/dist/commands/synthetics/__tests__/tunnel/crypto.test.js.map +1 -0
- package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.d.ts +1 -0
- package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.js +80 -0
- package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.js.map +1 -0
- package/dist/commands/synthetics/__tests__/tunnel/websocket.test.d.ts +1 -0
- package/dist/commands/synthetics/__tests__/tunnel/websocket.test.js +109 -0
- package/dist/commands/synthetics/__tests__/tunnel/websocket.test.js.map +1 -0
- package/dist/commands/synthetics/__tests__/utils/internal.test.d.ts +1 -0
- package/dist/commands/synthetics/__tests__/utils/internal.test.js +186 -0
- package/dist/commands/synthetics/__tests__/utils/internal.test.js.map +1 -0
- package/dist/commands/synthetics/__tests__/utils/public.test.d.ts +1 -0
- package/dist/commands/synthetics/__tests__/utils/public.test.js +1526 -0
- package/dist/commands/synthetics/__tests__/utils/public.test.js.map +1 -0
- package/dist/commands/synthetics/api.d.ts +1 -1
- package/dist/commands/synthetics/api.js +10 -5
- package/dist/commands/synthetics/api.js.map +1 -1
- package/dist/commands/synthetics/run-tests-command.d.ts +1 -0
- package/dist/commands/synthetics/run-tests-command.js +3 -2
- package/dist/commands/synthetics/run-tests-command.js.map +1 -1
- package/dist/commands/synthetics/run-tests-lib.js +0 -4
- package/dist/commands/synthetics/run-tests-lib.js.map +1 -1
- package/dist/commands/synthetics/test.js +9 -1
- package/dist/commands/synthetics/test.js.map +1 -1
- package/dist/commands/synthetics/utils/public.js +3 -3
- package/dist/commands/synthetics/utils/public.js.map +1 -1
- package/dist/commands/tag/__tests__/tag.test.d.ts +1 -0
- package/dist/commands/tag/__tests__/tag.test.js +75 -0
- package/dist/commands/tag/__tests__/tag.test.js.map +1 -0
- package/dist/commands/trace/__tests__/trace.test.d.ts +1 -0
- package/dist/commands/trace/__tests__/trace.test.js +145 -0
- package/dist/commands/trace/__tests__/trace.test.js.map +1 -0
- package/dist/commands/unity-symbols/__tests__/upload.test.d.ts +1 -0
- package/dist/commands/unity-symbols/__tests__/upload.test.js +369 -0
- package/dist/commands/unity-symbols/__tests__/upload.test.js.map +1 -0
- package/dist/commands/unity-symbols/upload.js +2 -2
- package/dist/commands/unity-symbols/upload.js.map +1 -1
- package/dist/helpers/__tests__/app.test.d.ts +1 -0
- package/dist/helpers/__tests__/app.test.js +31 -0
- package/dist/helpers/__tests__/app.test.js.map +1 -0
- package/dist/helpers/__tests__/ci.test.d.ts +1 -0
- package/dist/helpers/__tests__/ci.test.js +252 -0
- package/dist/helpers/__tests__/ci.test.js.map +1 -0
- package/dist/helpers/__tests__/fixtures.d.ts +33 -0
- package/dist/helpers/__tests__/fixtures.js +71 -0
- package/dist/helpers/__tests__/fixtures.js.map +1 -0
- package/dist/helpers/__tests__/flare.test.d.ts +1 -0
- package/dist/helpers/__tests__/flare.test.js +226 -0
- package/dist/helpers/__tests__/flare.test.js.map +1 -0
- package/dist/helpers/__tests__/fs.test.d.ts +1 -0
- package/dist/helpers/__tests__/fs.test.js +189 -0
- package/dist/helpers/__tests__/fs.test.js.map +1 -0
- package/dist/helpers/__tests__/plist.test.d.ts +1 -0
- package/dist/helpers/__tests__/plist.test.js +43 -0
- package/dist/helpers/__tests__/plist.test.js.map +1 -0
- package/dist/helpers/__tests__/prompt.test.d.ts +1 -0
- package/dist/helpers/__tests__/prompt.test.js +71 -0
- package/dist/helpers/__tests__/prompt.test.js.map +1 -0
- package/dist/helpers/__tests__/retry.test.d.ts +1 -0
- package/dist/helpers/__tests__/retry.test.js +99 -0
- package/dist/helpers/__tests__/retry.test.js.map +1 -0
- package/dist/helpers/__tests__/tags.test.d.ts +1 -0
- package/dist/helpers/__tests__/tags.test.js +71 -0
- package/dist/helpers/__tests__/tags.test.js.map +1 -0
- package/dist/helpers/__tests__/upload.test.d.ts +1 -0
- package/dist/helpers/__tests__/upload.test.js +231 -0
- package/dist/helpers/__tests__/upload.test.js.map +1 -0
- package/dist/helpers/__tests__/user-provided-git.test.d.ts +1 -0
- package/dist/helpers/__tests__/user-provided-git.test.js +119 -0
- package/dist/helpers/__tests__/user-provided-git.test.js.map +1 -0
- package/dist/helpers/__tests__/utils.test.d.ts +1 -0
- package/dist/helpers/__tests__/utils.test.js +429 -0
- package/dist/helpers/__tests__/utils.test.js.map +1 -0
- package/dist/helpers/__tests__/validation.test.d.ts +1 -0
- package/dist/helpers/__tests__/validation.test.js +25 -0
- package/dist/helpers/__tests__/validation.test.js.map +1 -0
- package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.d.ts +1 -0
- package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.js +103 -0
- package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.js.map +1 -0
- package/dist/helpers/git/__tests__/format-git-span-data.test.d.ts +1 -0
- package/dist/helpers/git/__tests__/format-git-span-data.test.js +121 -0
- package/dist/helpers/git/__tests__/format-git-span-data.test.js.map +1 -0
- package/dist/helpers/git/__tests__/get-git-data.test.d.ts +1 -0
- package/dist/helpers/git/__tests__/get-git-data.test.js +72 -0
- package/dist/helpers/git/__tests__/get-git-data.test.js.map +1 -0
- package/package.json +4 -6
|
@@ -0,0 +1,1511 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
jest.mock('fs');
|
|
36
|
+
jest.mock('@aws-sdk/credential-providers', () => (Object.assign(Object.assign({}, jest.requireActual('@aws-sdk/credential-providers')), { fromIni: jest.fn() })));
|
|
37
|
+
jest.mock('../prompt');
|
|
38
|
+
jest.mock('../renderers/instrument-uninstrument-renderer');
|
|
39
|
+
jest.mock('../../../helpers/prompt');
|
|
40
|
+
jest.mock('../../../../package.json', () => ({ version: 'XXXX' }));
|
|
41
|
+
const fs = __importStar(require("fs"));
|
|
42
|
+
const client_lambda_1 = require("@aws-sdk/client-lambda");
|
|
43
|
+
const credential_providers_1 = require("@aws-sdk/credential-providers");
|
|
44
|
+
const aws_sdk_client_mock_1 = require("aws-sdk-client-mock");
|
|
45
|
+
require("aws-sdk-client-mock-jest");
|
|
46
|
+
const advanced_1 = require("clipanion/lib/advanced");
|
|
47
|
+
const constants_1 = require("../../../constants");
|
|
48
|
+
const fixtures_1 = require("../../../helpers/__tests__/fixtures");
|
|
49
|
+
const prompt_1 = require("../../../helpers/prompt");
|
|
50
|
+
const constants_2 = require("../constants");
|
|
51
|
+
const instrument_1 = require("../instrument");
|
|
52
|
+
const prompt_2 = require("../prompt");
|
|
53
|
+
const fixtures_2 = require("./fixtures");
|
|
54
|
+
describe('lambda', () => {
|
|
55
|
+
const lambdaClientMock = (0, aws_sdk_client_mock_1.mockClient)(client_lambda_1.LambdaClient);
|
|
56
|
+
describe('instrument', () => {
|
|
57
|
+
describe('execute', () => {
|
|
58
|
+
const OLD_ENV = process.env;
|
|
59
|
+
beforeEach(() => {
|
|
60
|
+
lambdaClientMock.reset();
|
|
61
|
+
jest.resetModules();
|
|
62
|
+
process.env = {};
|
|
63
|
+
(0, fixtures_2.mockLambdaClientCommands)(lambdaClientMock);
|
|
64
|
+
});
|
|
65
|
+
afterAll(() => {
|
|
66
|
+
process.env = OLD_ENV;
|
|
67
|
+
});
|
|
68
|
+
test('prints dry run data for lambda library layer', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
;
|
|
70
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
71
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
72
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
73
|
+
config: {
|
|
74
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
75
|
+
Handler: 'index.handler',
|
|
76
|
+
Runtime: 'nodejs20.x',
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
81
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
82
|
+
const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
|
|
83
|
+
const code = yield cli.run([
|
|
84
|
+
'lambda',
|
|
85
|
+
'instrument',
|
|
86
|
+
'-f',
|
|
87
|
+
functionARN,
|
|
88
|
+
'--dry-run',
|
|
89
|
+
'--layerVersion',
|
|
90
|
+
'10',
|
|
91
|
+
'--logLevel',
|
|
92
|
+
'debug',
|
|
93
|
+
'--service',
|
|
94
|
+
'middletier',
|
|
95
|
+
'--env',
|
|
96
|
+
'staging',
|
|
97
|
+
'--version',
|
|
98
|
+
'0.2',
|
|
99
|
+
'--extra-tags',
|
|
100
|
+
'layer:api,team:intake',
|
|
101
|
+
'--no-source-code-integration',
|
|
102
|
+
], context);
|
|
103
|
+
const output = context.stdout.toString();
|
|
104
|
+
expect(code).toBe(0);
|
|
105
|
+
expect(output).toMatchSnapshot();
|
|
106
|
+
}));
|
|
107
|
+
test('prints dry run data for lambda library and extension layers using kebab case args', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
108
|
+
;
|
|
109
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
110
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
111
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
112
|
+
config: {
|
|
113
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
114
|
+
Handler: 'index.handler',
|
|
115
|
+
Runtime: 'nodejs20.x',
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
120
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
121
|
+
const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
|
|
122
|
+
process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
|
|
123
|
+
const code = yield cli.run([
|
|
124
|
+
'lambda',
|
|
125
|
+
'instrument',
|
|
126
|
+
'-f',
|
|
127
|
+
functionARN,
|
|
128
|
+
'--dry-run',
|
|
129
|
+
'--service',
|
|
130
|
+
'middletier',
|
|
131
|
+
'--env',
|
|
132
|
+
'staging',
|
|
133
|
+
'--version',
|
|
134
|
+
'0.2',
|
|
135
|
+
'--extra-tags',
|
|
136
|
+
'layer:api,team:intake',
|
|
137
|
+
'--layer-version',
|
|
138
|
+
'10',
|
|
139
|
+
'--extension-version',
|
|
140
|
+
'5',
|
|
141
|
+
'--merge-xray-traces',
|
|
142
|
+
'true',
|
|
143
|
+
'--flush-metrics-to-logs',
|
|
144
|
+
'false',
|
|
145
|
+
'--log-level',
|
|
146
|
+
'debug',
|
|
147
|
+
'--no-source-code-integration',
|
|
148
|
+
], context);
|
|
149
|
+
const output = context.stdout.toString();
|
|
150
|
+
expect(code).toBe(0);
|
|
151
|
+
expect(output).toMatchSnapshot();
|
|
152
|
+
}));
|
|
153
|
+
test('prints dry run data for lambda extension layer', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
154
|
+
;
|
|
155
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
156
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
157
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
158
|
+
config: {
|
|
159
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
160
|
+
Handler: 'index.handler',
|
|
161
|
+
Runtime: 'nodejs20.x',
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
166
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
167
|
+
const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
|
|
168
|
+
process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
|
|
169
|
+
const code = yield cli.run([
|
|
170
|
+
'lambda',
|
|
171
|
+
'instrument',
|
|
172
|
+
'-f',
|
|
173
|
+
functionARN,
|
|
174
|
+
'--dry-run',
|
|
175
|
+
'--extensionVersion',
|
|
176
|
+
'6',
|
|
177
|
+
'--service',
|
|
178
|
+
'middletier',
|
|
179
|
+
'--env',
|
|
180
|
+
'staging',
|
|
181
|
+
'--version',
|
|
182
|
+
'0.2',
|
|
183
|
+
'--extra-tags',
|
|
184
|
+
'layer:api,team:intake',
|
|
185
|
+
'--no-source-code-integration',
|
|
186
|
+
], context);
|
|
187
|
+
const output = context.stdout.toString();
|
|
188
|
+
expect(code).toBe(0);
|
|
189
|
+
expect(output).toMatchSnapshot();
|
|
190
|
+
}));
|
|
191
|
+
test('prints dry run data for lambda .NET layer', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
192
|
+
;
|
|
193
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
194
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
195
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
196
|
+
config: {
|
|
197
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
198
|
+
Runtime: 'dotnet8',
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
203
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
204
|
+
const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
|
|
205
|
+
process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
|
|
206
|
+
const code = yield cli.run([
|
|
207
|
+
'lambda',
|
|
208
|
+
'instrument',
|
|
209
|
+
'-f',
|
|
210
|
+
functionARN,
|
|
211
|
+
'--dry-run',
|
|
212
|
+
'-v',
|
|
213
|
+
'129',
|
|
214
|
+
'--extra-tags',
|
|
215
|
+
'layer:api,team:intake',
|
|
216
|
+
'--service',
|
|
217
|
+
'middletier',
|
|
218
|
+
'--env',
|
|
219
|
+
'staging',
|
|
220
|
+
'--version',
|
|
221
|
+
'0.2',
|
|
222
|
+
'--no-source-code-integration',
|
|
223
|
+
], context);
|
|
224
|
+
const output = context.stdout.toString();
|
|
225
|
+
expect(code).toBe(0);
|
|
226
|
+
expect(output).toMatchSnapshot();
|
|
227
|
+
}));
|
|
228
|
+
test('instrumenting with source code integrations fails if not run within a git repo', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
229
|
+
;
|
|
230
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
231
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
232
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
233
|
+
config: {
|
|
234
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
235
|
+
Handler: 'index.handler',
|
|
236
|
+
Runtime: 'nodejs20.x',
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
|
|
241
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
242
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
243
|
+
yield cli.run([
|
|
244
|
+
'lambda',
|
|
245
|
+
'instrument',
|
|
246
|
+
'--function',
|
|
247
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
248
|
+
'--layerVersion',
|
|
249
|
+
'10',
|
|
250
|
+
'-s',
|
|
251
|
+
'--service',
|
|
252
|
+
'dummy',
|
|
253
|
+
'--env',
|
|
254
|
+
'dummy',
|
|
255
|
+
'--version',
|
|
256
|
+
'0.1',
|
|
257
|
+
], context);
|
|
258
|
+
const output = context.stdout.toString();
|
|
259
|
+
expect(output.replace('\n', '')).toMatch(/.*Error: Couldn't get local git status.*/);
|
|
260
|
+
}));
|
|
261
|
+
test('ensure the instrument command ran from a dirty git repo fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
262
|
+
;
|
|
263
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
264
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
265
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
266
|
+
config: {
|
|
267
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
268
|
+
Handler: 'index.handler',
|
|
269
|
+
Runtime: 'nodejs20.x',
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
|
|
274
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
275
|
+
const instrumentCommand = instrument_1.InstrumentCommand;
|
|
276
|
+
const mockGitStatus = jest.spyOn(instrumentCommand.prototype, 'getCurrentGitStatus');
|
|
277
|
+
mockGitStatus.mockImplementation(() => ({
|
|
278
|
+
ahead: 0,
|
|
279
|
+
isClean: false,
|
|
280
|
+
}));
|
|
281
|
+
const cli = new advanced_1.Cli();
|
|
282
|
+
cli.register(instrumentCommand);
|
|
283
|
+
yield cli.run([
|
|
284
|
+
'lambda',
|
|
285
|
+
'instrument',
|
|
286
|
+
'--function',
|
|
287
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
288
|
+
'--layerVersion',
|
|
289
|
+
'10',
|
|
290
|
+
'-s',
|
|
291
|
+
'--service',
|
|
292
|
+
'dummy',
|
|
293
|
+
'--env',
|
|
294
|
+
'dummy',
|
|
295
|
+
'--version',
|
|
296
|
+
'0.1',
|
|
297
|
+
], context);
|
|
298
|
+
const output = context.stdout.toString();
|
|
299
|
+
expect(output).toMatch('Error: Local git repository is dirty');
|
|
300
|
+
}));
|
|
301
|
+
test('ensure source code integration flag works from a clean repo', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
302
|
+
;
|
|
303
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
304
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
305
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
306
|
+
config: {
|
|
307
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
308
|
+
Handler: 'index.handler',
|
|
309
|
+
Runtime: 'nodejs20.x',
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
});
|
|
313
|
+
process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
|
|
314
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
315
|
+
const instrumentCommand = instrument_1.InstrumentCommand;
|
|
316
|
+
const mockGitStatus = jest.spyOn(instrumentCommand.prototype, 'getCurrentGitStatus');
|
|
317
|
+
mockGitStatus.mockImplementation(() => ({
|
|
318
|
+
ahead: 0,
|
|
319
|
+
hash: '1be168ff837f043bde17c0314341c84271047b31',
|
|
320
|
+
remote: 'git.repository_url:git@github.com:datadog/test.git',
|
|
321
|
+
isClean: true,
|
|
322
|
+
}));
|
|
323
|
+
const mockUploadFunction = jest.spyOn(instrumentCommand.prototype, 'uploadGitData');
|
|
324
|
+
mockUploadFunction.mockImplementation(() => {
|
|
325
|
+
return;
|
|
326
|
+
});
|
|
327
|
+
const cli = new advanced_1.Cli();
|
|
328
|
+
cli.register(instrumentCommand);
|
|
329
|
+
yield cli.run([
|
|
330
|
+
'lambda',
|
|
331
|
+
'instrument',
|
|
332
|
+
'--function',
|
|
333
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
334
|
+
'--layerVersion',
|
|
335
|
+
'10',
|
|
336
|
+
'-s',
|
|
337
|
+
'--service',
|
|
338
|
+
'dummy',
|
|
339
|
+
'--env',
|
|
340
|
+
'dummy',
|
|
341
|
+
'--version',
|
|
342
|
+
'0.1',
|
|
343
|
+
], context);
|
|
344
|
+
const output = context.stdout.toString();
|
|
345
|
+
expect(output).toMatchSnapshot();
|
|
346
|
+
expect(mockUploadFunction).toHaveBeenCalledTimes(1);
|
|
347
|
+
}));
|
|
348
|
+
test('ensure no git metadata upload flag works', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
349
|
+
;
|
|
350
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
351
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
352
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
353
|
+
config: {
|
|
354
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
355
|
+
Handler: 'index.handler',
|
|
356
|
+
Runtime: 'nodejs20.x',
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
});
|
|
360
|
+
process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
|
|
361
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
362
|
+
const instrumentCommand = instrument_1.InstrumentCommand;
|
|
363
|
+
const mockGitStatus = jest.spyOn(instrumentCommand.prototype, 'getCurrentGitStatus');
|
|
364
|
+
mockGitStatus.mockImplementation(() => ({
|
|
365
|
+
ahead: 0,
|
|
366
|
+
hash: '1be168ff837f043bde17c0314341c84271047b31',
|
|
367
|
+
remote: 'git.repository_url:git@github.com:datadog/test.git',
|
|
368
|
+
isClean: true,
|
|
369
|
+
}));
|
|
370
|
+
const mockUploadFunction = jest.spyOn(instrumentCommand.prototype, 'uploadGitData');
|
|
371
|
+
mockUploadFunction.mockImplementation(() => {
|
|
372
|
+
return;
|
|
373
|
+
});
|
|
374
|
+
const cli = new advanced_1.Cli();
|
|
375
|
+
cli.register(instrumentCommand);
|
|
376
|
+
yield cli.run([
|
|
377
|
+
'lambda',
|
|
378
|
+
'instrument',
|
|
379
|
+
'--function',
|
|
380
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
381
|
+
'--layerVersion',
|
|
382
|
+
'10',
|
|
383
|
+
'--no-upload-git-metadata',
|
|
384
|
+
'--service',
|
|
385
|
+
'dummy',
|
|
386
|
+
'--env',
|
|
387
|
+
'dummy',
|
|
388
|
+
'--version',
|
|
389
|
+
'0.1',
|
|
390
|
+
], context);
|
|
391
|
+
const output = context.stdout.toString();
|
|
392
|
+
expect(mockUploadFunction).toHaveBeenCalledTimes(0);
|
|
393
|
+
expect(output).toMatchSnapshot();
|
|
394
|
+
}));
|
|
395
|
+
test('ensure the instrument command ran from a local git repo ahead of the origin fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
396
|
+
;
|
|
397
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
398
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
399
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
400
|
+
config: {
|
|
401
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
402
|
+
Handler: 'index.handler',
|
|
403
|
+
Runtime: 'nodejs20.x',
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
});
|
|
407
|
+
process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
|
|
408
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
409
|
+
const instrumentCommand = instrument_1.InstrumentCommand;
|
|
410
|
+
const mockGitStatus = jest.spyOn(instrumentCommand.prototype, 'getCurrentGitStatus');
|
|
411
|
+
mockGitStatus.mockImplementation(() => ({
|
|
412
|
+
ahead: 1,
|
|
413
|
+
isClean: true,
|
|
414
|
+
}));
|
|
415
|
+
const cli = new advanced_1.Cli();
|
|
416
|
+
cli.register(instrumentCommand);
|
|
417
|
+
yield cli.run([
|
|
418
|
+
'lambda',
|
|
419
|
+
'instrument',
|
|
420
|
+
'--function',
|
|
421
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
422
|
+
'--layerVersion',
|
|
423
|
+
'10',
|
|
424
|
+
'-s',
|
|
425
|
+
'--service',
|
|
426
|
+
'dummy',
|
|
427
|
+
'--env',
|
|
428
|
+
'dummy',
|
|
429
|
+
'--version',
|
|
430
|
+
'0.1',
|
|
431
|
+
], context);
|
|
432
|
+
const output = context.stdout.toString();
|
|
433
|
+
expect(output).toMatch('Error: Local changes have not been pushed remotely. Aborting git data tagging.');
|
|
434
|
+
}));
|
|
435
|
+
test('runs function update command for lambda library layer', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
436
|
+
;
|
|
437
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
438
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
439
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
440
|
+
config: {
|
|
441
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
442
|
+
Handler: 'index.handler',
|
|
443
|
+
Runtime: 'nodejs20.x',
|
|
444
|
+
},
|
|
445
|
+
},
|
|
446
|
+
});
|
|
447
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
448
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
449
|
+
yield cli.run([
|
|
450
|
+
'lambda',
|
|
451
|
+
'instrument',
|
|
452
|
+
'--function',
|
|
453
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
454
|
+
'--layerVersion',
|
|
455
|
+
'10',
|
|
456
|
+
'--no-source-code-integration',
|
|
457
|
+
], context);
|
|
458
|
+
expect(lambdaClientMock).toHaveReceivedCommand(client_lambda_1.UpdateFunctionConfigurationCommand);
|
|
459
|
+
}));
|
|
460
|
+
test('runs function update command for lambda extension layer', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
461
|
+
;
|
|
462
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
463
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
464
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
465
|
+
config: {
|
|
466
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
467
|
+
Handler: 'index.handler',
|
|
468
|
+
Runtime: 'nodejs20.x',
|
|
469
|
+
},
|
|
470
|
+
},
|
|
471
|
+
});
|
|
472
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
473
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
474
|
+
process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
|
|
475
|
+
yield cli.run([
|
|
476
|
+
'lambda',
|
|
477
|
+
'instrument',
|
|
478
|
+
'--function',
|
|
479
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
480
|
+
'--extensionVersion',
|
|
481
|
+
'6',
|
|
482
|
+
'--no-source-code-integration',
|
|
483
|
+
], context);
|
|
484
|
+
expect(lambdaClientMock).toHaveReceivedCommand(client_lambda_1.UpdateFunctionConfigurationCommand);
|
|
485
|
+
}));
|
|
486
|
+
test('aborts early when no functions are specified', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
487
|
+
;
|
|
488
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
489
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
490
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
491
|
+
const code = yield cli.run([
|
|
492
|
+
'lambda',
|
|
493
|
+
'instrument',
|
|
494
|
+
'--layerVersion',
|
|
495
|
+
'10',
|
|
496
|
+
'--service',
|
|
497
|
+
'middletier',
|
|
498
|
+
'--env',
|
|
499
|
+
'staging',
|
|
500
|
+
'--version',
|
|
501
|
+
'0.2',
|
|
502
|
+
], context);
|
|
503
|
+
const output = context.stdout.toString();
|
|
504
|
+
expect(code).toBe(1);
|
|
505
|
+
expect(output).toMatchInlineSnapshot(`
|
|
506
|
+
"
|
|
507
|
+
🐶 Instrumenting Lambda function
|
|
508
|
+
[Error] No functions specified to instrument.
|
|
509
|
+
"
|
|
510
|
+
`);
|
|
511
|
+
}));
|
|
512
|
+
test('aborts early when no functions are specified while using config file', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
513
|
+
;
|
|
514
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
515
|
+
process.env = {};
|
|
516
|
+
const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
|
|
517
|
+
command['config']['layerVersion'] = '60';
|
|
518
|
+
command['config']['extensionVersion'] = '10';
|
|
519
|
+
command['config']['region'] = 'ap-southeast-1';
|
|
520
|
+
command['config']['service'] = 'middletier';
|
|
521
|
+
command['config']['environment'] = 'staging';
|
|
522
|
+
command['config']['version'] = '0.2';
|
|
523
|
+
yield command['execute']();
|
|
524
|
+
const output = command.context.stdout.toString();
|
|
525
|
+
expect(output).toMatchInlineSnapshot(`
|
|
526
|
+
"
|
|
527
|
+
🐶 Instrumenting Lambda function
|
|
528
|
+
[Error] No functions specified to instrument.
|
|
529
|
+
"
|
|
530
|
+
`);
|
|
531
|
+
}));
|
|
532
|
+
test("aborts early when function regions can't be found", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
533
|
+
;
|
|
534
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
535
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
536
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
537
|
+
const code = yield cli.run([
|
|
538
|
+
'lambda',
|
|
539
|
+
'instrument',
|
|
540
|
+
'--function',
|
|
541
|
+
'my-func',
|
|
542
|
+
'--layerVersion',
|
|
543
|
+
'10',
|
|
544
|
+
'--service',
|
|
545
|
+
'middletier',
|
|
546
|
+
'--env',
|
|
547
|
+
'staging',
|
|
548
|
+
'--version',
|
|
549
|
+
'0.2',
|
|
550
|
+
'--no-source-code-integration',
|
|
551
|
+
], context);
|
|
552
|
+
const output = context.stdout.toString();
|
|
553
|
+
expect(code).toBe(1);
|
|
554
|
+
expect(output).toMatch(`Couldn't group functions. Error: No default region specified for ["my-func"]. Use -r, --region, or use a full functionARN\n`);
|
|
555
|
+
}));
|
|
556
|
+
test('aborts early when extensionVersion and forwarder are set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
557
|
+
;
|
|
558
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
559
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
560
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
561
|
+
const code = yield cli.run([
|
|
562
|
+
'lambda',
|
|
563
|
+
'instrument',
|
|
564
|
+
'--function',
|
|
565
|
+
'test-function-arn',
|
|
566
|
+
'--forwarder',
|
|
567
|
+
'arn:aws:lambda:sa-east-1:000000000000:function:datadog-forwarder',
|
|
568
|
+
'--extensionVersion',
|
|
569
|
+
'6',
|
|
570
|
+
'--region',
|
|
571
|
+
'us-east-1',
|
|
572
|
+
'--service',
|
|
573
|
+
'middletier',
|
|
574
|
+
'--env',
|
|
575
|
+
'staging',
|
|
576
|
+
'--version',
|
|
577
|
+
'0.2',
|
|
578
|
+
], context);
|
|
579
|
+
const output = context.stdout.toString();
|
|
580
|
+
expect(code).toBe(1);
|
|
581
|
+
expect(output).toMatchInlineSnapshot(`
|
|
582
|
+
"
|
|
583
|
+
🐶 Instrumenting Lambda function
|
|
584
|
+
[Error] "extensionVersion" and "forwarder" should not be used at the same time.
|
|
585
|
+
"
|
|
586
|
+
`);
|
|
587
|
+
}));
|
|
588
|
+
test('check if functions are not empty while using config file', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
589
|
+
;
|
|
590
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
591
|
+
process.env = {};
|
|
592
|
+
const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
|
|
593
|
+
command['config']['layerVersion'] = '60';
|
|
594
|
+
command['config']['extensionVersion'] = '10';
|
|
595
|
+
command['config']['region'] = 'ap-southeast-1';
|
|
596
|
+
command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
|
|
597
|
+
yield command['execute']();
|
|
598
|
+
expect(command['config']['functions']).toHaveLength(1);
|
|
599
|
+
}));
|
|
600
|
+
test('aborts if functions and a pattern are set at the same time', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
601
|
+
;
|
|
602
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
603
|
+
process.env = {};
|
|
604
|
+
let command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
|
|
605
|
+
command['config']['environment'] = 'staging';
|
|
606
|
+
command['config']['service'] = 'middletier';
|
|
607
|
+
command['config']['version'] = '2';
|
|
608
|
+
command['config']['region'] = 'ap-southeast-1';
|
|
609
|
+
command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
|
|
610
|
+
command['regExPattern'] = 'valid-pattern';
|
|
611
|
+
command['sourceCodeIntegration'] = false;
|
|
612
|
+
yield command['execute']();
|
|
613
|
+
let output = command.context.stdout.toString();
|
|
614
|
+
expect(output).toMatch('Functions in config file and "--functions-regex" should not be used at the same time.\n');
|
|
615
|
+
command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
|
|
616
|
+
command['environment'] = 'staging';
|
|
617
|
+
command['service'] = 'middletier';
|
|
618
|
+
command['version'] = '2';
|
|
619
|
+
command['region'] = 'ap-southeast-1';
|
|
620
|
+
command['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
|
|
621
|
+
command['regExPattern'] = 'valid-pattern';
|
|
622
|
+
command['sourceCodeIntegration'] = false;
|
|
623
|
+
yield command['execute']();
|
|
624
|
+
output = command.context.stdout.toString();
|
|
625
|
+
expect(output).toMatch('"--functions" and "--functions-regex" should not be used at the same time.\n');
|
|
626
|
+
}));
|
|
627
|
+
test('aborts if pattern is set and no default region is specified', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
628
|
+
;
|
|
629
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
630
|
+
process.env = {};
|
|
631
|
+
const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
|
|
632
|
+
command['environment'] = 'staging';
|
|
633
|
+
command['service'] = 'middletier';
|
|
634
|
+
command['version'] = '2';
|
|
635
|
+
command['regExPattern'] = 'valid-pattern';
|
|
636
|
+
command['sourceCodeIntegration'] = false;
|
|
637
|
+
yield command['execute']();
|
|
638
|
+
const output = command.context.stdout.toString();
|
|
639
|
+
expect(output).toMatch('[Error] No default region specified. [-r,--region]\n');
|
|
640
|
+
}));
|
|
641
|
+
test('aborts if the regEx pattern is an ARN', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
642
|
+
;
|
|
643
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
644
|
+
process.env = {};
|
|
645
|
+
const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
|
|
646
|
+
command['environment'] = 'staging';
|
|
647
|
+
command['service'] = 'middletier';
|
|
648
|
+
command['version'] = '2';
|
|
649
|
+
command['region'] = 'ap-southeast-1';
|
|
650
|
+
command['regExPattern'] = 'arn:aws:lambda:ap-southeast-1:123456789012:function:*';
|
|
651
|
+
command['sourceCodeIntegration'] = false;
|
|
652
|
+
yield command['execute']();
|
|
653
|
+
const output = command.context.stdout.toString();
|
|
654
|
+
expect(output).toMatch(`"--functions-regex" isn't meant to be used with ARNs.\n`);
|
|
655
|
+
}));
|
|
656
|
+
test('instrument multiple functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
657
|
+
;
|
|
658
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
659
|
+
const node20LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node20-x`;
|
|
660
|
+
const node18LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node18-x`;
|
|
661
|
+
const node16LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node16-x`;
|
|
662
|
+
const extensionLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension`;
|
|
663
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
664
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
|
|
665
|
+
config: {
|
|
666
|
+
FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
|
|
667
|
+
FunctionName: 'lambda-hello-world',
|
|
668
|
+
Handler: 'index.handler',
|
|
669
|
+
Runtime: 'nodejs16.x',
|
|
670
|
+
},
|
|
671
|
+
},
|
|
672
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2': {
|
|
673
|
+
config: {
|
|
674
|
+
FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
|
|
675
|
+
FunctionName: 'lambda-hello-world-2',
|
|
676
|
+
Handler: 'index.handler',
|
|
677
|
+
Runtime: 'nodejs18.x',
|
|
678
|
+
},
|
|
679
|
+
},
|
|
680
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-3': {
|
|
681
|
+
config: {
|
|
682
|
+
FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-3',
|
|
683
|
+
FunctionName: 'lambda-hello-world-3',
|
|
684
|
+
Handler: 'index.handler',
|
|
685
|
+
Runtime: 'nodejs20.x',
|
|
686
|
+
},
|
|
687
|
+
},
|
|
688
|
+
});
|
|
689
|
+
(0, fixtures_2.mockLambdaLayers)(lambdaClientMock, {
|
|
690
|
+
[`${node16LibraryLayer}:1`]: {
|
|
691
|
+
LayerName: `${node16LibraryLayer}`,
|
|
692
|
+
VersionNumber: 1,
|
|
693
|
+
},
|
|
694
|
+
[`${node18LibraryLayer}:1`]: {
|
|
695
|
+
LayerName: `${node18LibraryLayer}`,
|
|
696
|
+
VersionNumber: 1,
|
|
697
|
+
},
|
|
698
|
+
[`${node20LibraryLayer}:1`]: {
|
|
699
|
+
LayerName: `${node20LibraryLayer}`,
|
|
700
|
+
VersionNumber: 1,
|
|
701
|
+
},
|
|
702
|
+
[`${extensionLayer}:1`]: {
|
|
703
|
+
LayerName: `${extensionLayer}`,
|
|
704
|
+
VersionNumber: 1,
|
|
705
|
+
},
|
|
706
|
+
});
|
|
707
|
+
prompt_2.requestAWSCredentials.mockImplementation(() => {
|
|
708
|
+
process.env[constants_2.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_2.mockAwsAccessKeyId;
|
|
709
|
+
process.env[constants_2.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_2.mockAwsSecretAccessKey;
|
|
710
|
+
process.env[constants_2.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
|
|
711
|
+
});
|
|
712
|
+
prompt_2.requestDatadogEnvVars.mockImplementation(() => {
|
|
713
|
+
process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
|
|
714
|
+
process.env[constants_1.CI_API_KEY_ENV_VAR] = fixtures_1.MOCK_DATADOG_API_KEY;
|
|
715
|
+
});
|
|
716
|
+
prompt_2.requestFunctionSelection.mockImplementation(() => [
|
|
717
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
|
|
718
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
|
|
719
|
+
]);
|
|
720
|
+
prompt_1.requestConfirmation.mockImplementation(() => true);
|
|
721
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
722
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
723
|
+
const code = yield cli.run(['lambda', 'instrument', '-i', '--no-source-code-integration'], context);
|
|
724
|
+
const output = context.stdout.toString();
|
|
725
|
+
expect(code).toBe(0);
|
|
726
|
+
expect(output).toMatchSnapshot();
|
|
727
|
+
}));
|
|
728
|
+
test('instrument multiple specified functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
729
|
+
;
|
|
730
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
731
|
+
const node16LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node16-x`;
|
|
732
|
+
const node18LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node18-x`;
|
|
733
|
+
const node20LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node20-x`;
|
|
734
|
+
const extensionLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension`;
|
|
735
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
736
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
|
|
737
|
+
config: {
|
|
738
|
+
FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
|
|
739
|
+
FunctionName: 'lambda-hello-world',
|
|
740
|
+
Handler: 'index.handler',
|
|
741
|
+
Runtime: 'nodejs16.x',
|
|
742
|
+
},
|
|
743
|
+
},
|
|
744
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2': {
|
|
745
|
+
config: {
|
|
746
|
+
FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
|
|
747
|
+
FunctionName: 'lambda-hello-world-2',
|
|
748
|
+
Handler: 'index.handler',
|
|
749
|
+
Runtime: 'nodejs18.x',
|
|
750
|
+
},
|
|
751
|
+
},
|
|
752
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-3': {
|
|
753
|
+
config: {
|
|
754
|
+
FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-3',
|
|
755
|
+
FunctionName: 'lambda-hello-world-3',
|
|
756
|
+
Handler: 'index.handler',
|
|
757
|
+
Runtime: 'nodejs20.x',
|
|
758
|
+
},
|
|
759
|
+
},
|
|
760
|
+
});
|
|
761
|
+
(0, fixtures_2.mockLambdaLayers)(lambdaClientMock, {
|
|
762
|
+
[`${node16LibraryLayer}:1`]: {
|
|
763
|
+
LayerName: `${node16LibraryLayer}`,
|
|
764
|
+
VersionNumber: 1,
|
|
765
|
+
},
|
|
766
|
+
[`${node18LibraryLayer}:1`]: {
|
|
767
|
+
LayerName: `${node18LibraryLayer}`,
|
|
768
|
+
VersionNumber: 1,
|
|
769
|
+
},
|
|
770
|
+
[`${node20LibraryLayer}:1`]: {
|
|
771
|
+
LayerName: `${node20LibraryLayer}`,
|
|
772
|
+
VersionNumber: 1,
|
|
773
|
+
},
|
|
774
|
+
[`${extensionLayer}:1`]: {
|
|
775
|
+
LayerName: `${extensionLayer}`,
|
|
776
|
+
VersionNumber: 1,
|
|
777
|
+
},
|
|
778
|
+
});
|
|
779
|
+
prompt_2.requestAWSCredentials.mockImplementation(() => {
|
|
780
|
+
process.env[constants_2.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_2.mockAwsAccessKeyId;
|
|
781
|
+
process.env[constants_2.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_2.mockAwsSecretAccessKey;
|
|
782
|
+
process.env[constants_2.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
|
|
783
|
+
process.env[constants_2.AWS_SESSION_TOKEN_ENV_VAR] = 'some-session-token';
|
|
784
|
+
});
|
|
785
|
+
prompt_2.requestDatadogEnvVars.mockImplementation(() => {
|
|
786
|
+
process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
|
|
787
|
+
process.env[constants_1.CI_API_KEY_ENV_VAR] = fixtures_1.MOCK_DATADOG_API_KEY;
|
|
788
|
+
});
|
|
789
|
+
prompt_1.requestConfirmation.mockImplementation(() => true);
|
|
790
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
791
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
792
|
+
const code = yield cli.run([
|
|
793
|
+
'lambda',
|
|
794
|
+
'instrument',
|
|
795
|
+
'-i',
|
|
796
|
+
'-f',
|
|
797
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
|
|
798
|
+
'-f',
|
|
799
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
|
|
800
|
+
'--no-source-code-integration',
|
|
801
|
+
], context);
|
|
802
|
+
const output = context.stdout.toString();
|
|
803
|
+
expect(code).toBe(0);
|
|
804
|
+
expect(output).toMatchSnapshot();
|
|
805
|
+
}));
|
|
806
|
+
test('aborts if a problem occurs while setting the AWS credentials interactively', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
807
|
+
;
|
|
808
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
809
|
+
prompt_2.requestAWSCredentials.mockImplementation(() => Promise.reject('Unexpected error'));
|
|
810
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
811
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
812
|
+
const code = yield cli.run(['lambda', 'instrument', '-i'], context);
|
|
813
|
+
const output = context.stdout.toString();
|
|
814
|
+
expect(code).toBe(1);
|
|
815
|
+
expect(output).toMatchInlineSnapshot(`
|
|
816
|
+
"
|
|
817
|
+
🐶 Instrumenting Lambda function
|
|
818
|
+
[!] 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.
|
|
819
|
+
[Error] Unexpected error
|
|
820
|
+
"
|
|
821
|
+
`);
|
|
822
|
+
}));
|
|
823
|
+
test('aborts if a problem occurs while setting the Datadog Environment Variables interactively', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
824
|
+
;
|
|
825
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
826
|
+
process.env = {
|
|
827
|
+
[constants_2.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_2.mockAwsAccessKeyId,
|
|
828
|
+
[constants_2.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_2.mockAwsSecretAccessKey,
|
|
829
|
+
[constants_2.AWS_DEFAULT_REGION_ENV_VAR]: 'sa,-east-1',
|
|
830
|
+
};
|
|
831
|
+
prompt_2.requestDatadogEnvVars.mockImplementation(() => Promise.reject('Unexpected error'));
|
|
832
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
833
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
834
|
+
const code = yield cli.run(['lambda', 'instrument', '-i'], context);
|
|
835
|
+
const output = context.stdout.toString();
|
|
836
|
+
expect(code).toBe(1);
|
|
837
|
+
expect(output).toMatchInlineSnapshot(`
|
|
838
|
+
"
|
|
839
|
+
🐶 Instrumenting Lambda function
|
|
840
|
+
|
|
841
|
+
[!] Configure AWS region.
|
|
842
|
+
|
|
843
|
+
[!] Configure Datadog settings.
|
|
844
|
+
[Error] Unexpected error
|
|
845
|
+
"
|
|
846
|
+
`);
|
|
847
|
+
}));
|
|
848
|
+
test('when provided it sets DD_ENV, DD_SERVICE, and DD_VERSION environment variables in interactive mode', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
849
|
+
;
|
|
850
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
851
|
+
const node20LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node20-x`;
|
|
852
|
+
const extensionLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension`;
|
|
853
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
854
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
|
|
855
|
+
config: {
|
|
856
|
+
FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
|
|
857
|
+
FunctionName: 'lambda-hello-world',
|
|
858
|
+
Handler: 'index.handler',
|
|
859
|
+
Runtime: 'nodejs20.x',
|
|
860
|
+
},
|
|
861
|
+
},
|
|
862
|
+
});
|
|
863
|
+
(0, fixtures_2.mockLambdaLayers)(lambdaClientMock, {
|
|
864
|
+
[`${node20LibraryLayer}:1`]: {
|
|
865
|
+
LayerName: `${node20LibraryLayer}`,
|
|
866
|
+
VersionNumber: 1,
|
|
867
|
+
},
|
|
868
|
+
[`${extensionLayer}:1`]: {
|
|
869
|
+
LayerName: `${extensionLayer}`,
|
|
870
|
+
VersionNumber: 1,
|
|
871
|
+
},
|
|
872
|
+
});
|
|
873
|
+
prompt_2.requestAWSCredentials.mockImplementation(() => {
|
|
874
|
+
process.env[constants_2.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_2.mockAwsAccessKeyId;
|
|
875
|
+
process.env[constants_2.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_2.mockAwsSecretAccessKey;
|
|
876
|
+
process.env[constants_2.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
|
|
877
|
+
});
|
|
878
|
+
prompt_2.requestDatadogEnvVars.mockImplementation(() => {
|
|
879
|
+
process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
|
|
880
|
+
process.env[constants_1.CI_API_KEY_ENV_VAR] = fixtures_1.MOCK_DATADOG_API_KEY;
|
|
881
|
+
});
|
|
882
|
+
prompt_2.requestFunctionSelection.mockImplementation(() => [
|
|
883
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
|
|
884
|
+
]);
|
|
885
|
+
prompt_1.requestConfirmation.mockImplementation(() => true);
|
|
886
|
+
prompt_2.requestEnvServiceVersion.mockImplementation(() => {
|
|
887
|
+
process.env[constants_1.ENVIRONMENT_ENV_VAR] = fixtures_2.mockDatadogEnv;
|
|
888
|
+
process.env[constants_1.SERVICE_ENV_VAR] = fixtures_2.mockDatadogService;
|
|
889
|
+
process.env[constants_1.VERSION_ENV_VAR] = fixtures_2.mockDatadogVersion;
|
|
890
|
+
});
|
|
891
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
892
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
893
|
+
const code = yield cli.run(['lambda', 'instrument', '-i', '--no-source-code-integration'], context);
|
|
894
|
+
const output = context.stdout.toString();
|
|
895
|
+
expect(code).toBe(0);
|
|
896
|
+
expect(output).toMatchSnapshot();
|
|
897
|
+
}));
|
|
898
|
+
test('when not provided it does not set DD_ENV, DD_SERVICE, and DD_VERSION tags in interactive mode', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
899
|
+
;
|
|
900
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
901
|
+
const node20LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node20-x`;
|
|
902
|
+
const extensionLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension`;
|
|
903
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
904
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
|
|
905
|
+
config: {
|
|
906
|
+
FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
|
|
907
|
+
FunctionName: 'lambda-hello-world',
|
|
908
|
+
Handler: 'index.handler',
|
|
909
|
+
Runtime: 'nodejs20.x',
|
|
910
|
+
},
|
|
911
|
+
},
|
|
912
|
+
});
|
|
913
|
+
(0, fixtures_2.mockLambdaLayers)(lambdaClientMock, {
|
|
914
|
+
[`${node20LibraryLayer}:1`]: {
|
|
915
|
+
LayerName: `${node20LibraryLayer}`,
|
|
916
|
+
VersionNumber: 1,
|
|
917
|
+
},
|
|
918
|
+
[`${extensionLayer}:1`]: {
|
|
919
|
+
LayerName: `${extensionLayer}`,
|
|
920
|
+
VersionNumber: 1,
|
|
921
|
+
},
|
|
922
|
+
});
|
|
923
|
+
prompt_2.requestAWSCredentials.mockImplementation(() => {
|
|
924
|
+
process.env[constants_2.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_2.mockAwsAccessKeyId;
|
|
925
|
+
process.env[constants_2.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_2.mockAwsSecretAccessKey;
|
|
926
|
+
process.env[constants_2.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
|
|
927
|
+
});
|
|
928
|
+
prompt_2.requestDatadogEnvVars.mockImplementation(() => {
|
|
929
|
+
process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
|
|
930
|
+
process.env[constants_1.CI_API_KEY_ENV_VAR] = fixtures_1.MOCK_DATADOG_API_KEY;
|
|
931
|
+
});
|
|
932
|
+
prompt_2.requestFunctionSelection.mockImplementation(() => [
|
|
933
|
+
'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
|
|
934
|
+
]);
|
|
935
|
+
prompt_1.requestConfirmation.mockImplementation(() => true);
|
|
936
|
+
prompt_2.requestEnvServiceVersion.mockImplementation(() => {
|
|
937
|
+
process.env[constants_1.ENVIRONMENT_ENV_VAR] = undefined;
|
|
938
|
+
process.env[constants_1.SERVICE_ENV_VAR] = undefined;
|
|
939
|
+
process.env[constants_1.VERSION_ENV_VAR] = undefined;
|
|
940
|
+
});
|
|
941
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
942
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
943
|
+
const code = yield cli.run(['lambda', 'instrument', '-i', '--no-source-code-integration'], context);
|
|
944
|
+
const output = context.stdout.toString();
|
|
945
|
+
expect(code).toBe(0);
|
|
946
|
+
expect(output).toMatchSnapshot();
|
|
947
|
+
}));
|
|
948
|
+
test('aborts if there are no functions to instrument in the user AWS account', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
949
|
+
;
|
|
950
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
951
|
+
process.env = {
|
|
952
|
+
[constants_2.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_2.mockAwsAccessKeyId,
|
|
953
|
+
[constants_2.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_2.mockAwsSecretAccessKey,
|
|
954
|
+
[constants_2.AWS_DEFAULT_REGION_ENV_VAR]: 'sa-east-1',
|
|
955
|
+
[constants_1.CI_SITE_ENV_VAR]: 'datadoghq.com',
|
|
956
|
+
[constants_1.CI_API_KEY_ENV_VAR]: fixtures_1.MOCK_DATADOG_API_KEY,
|
|
957
|
+
};
|
|
958
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
959
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
960
|
+
const code = yield cli.run(['lambda', 'instrument', '-i'], context);
|
|
961
|
+
const output = context.stdout.toString();
|
|
962
|
+
expect(code).toBe(1);
|
|
963
|
+
expect(output).toMatchInlineSnapshot(`
|
|
964
|
+
"
|
|
965
|
+
🐶 Instrumenting Lambda function
|
|
966
|
+
|
|
967
|
+
[!] Configure AWS region.
|
|
968
|
+
[Error] Couldn't find any Lambda functions in the specified region.
|
|
969
|
+
"
|
|
970
|
+
`);
|
|
971
|
+
}));
|
|
972
|
+
test('aborts early when the aws-sdk throws an error while instrumenting interactively', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
973
|
+
;
|
|
974
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
975
|
+
process.env = {
|
|
976
|
+
[constants_2.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_2.mockAwsAccessKeyId,
|
|
977
|
+
[constants_2.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_2.mockAwsSecretAccessKey,
|
|
978
|
+
[constants_2.AWS_DEFAULT_REGION_ENV_VAR]: 'sa-east-1',
|
|
979
|
+
[constants_1.CI_SITE_ENV_VAR]: 'datadoghq.com',
|
|
980
|
+
[constants_1.CI_API_KEY_ENV_VAR]: fixtures_1.MOCK_DATADOG_API_KEY,
|
|
981
|
+
};
|
|
982
|
+
lambdaClientMock.on(client_lambda_1.ListFunctionsCommand).rejects('ListFunctionsError');
|
|
983
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
984
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
985
|
+
const code = yield cli.run(['lambda', 'instrument', '-i'], context);
|
|
986
|
+
const output = context.stdout.toString();
|
|
987
|
+
expect(code).toBe(1);
|
|
988
|
+
expect(output).toMatchInlineSnapshot(`
|
|
989
|
+
"
|
|
990
|
+
🐶 Instrumenting Lambda function
|
|
991
|
+
|
|
992
|
+
[!] Configure AWS region.
|
|
993
|
+
[Error] Couldn't fetch Lambda functions. Error: ListFunctionsError
|
|
994
|
+
"
|
|
995
|
+
`);
|
|
996
|
+
}));
|
|
997
|
+
test('instruments Ruby application properly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
998
|
+
;
|
|
999
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
1000
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
1001
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
1002
|
+
config: {
|
|
1003
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
1004
|
+
Runtime: 'ruby3.2',
|
|
1005
|
+
},
|
|
1006
|
+
},
|
|
1007
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world-2': {
|
|
1008
|
+
config: {
|
|
1009
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world-2',
|
|
1010
|
+
Runtime: 'ruby3.2',
|
|
1011
|
+
Architectures: ['arm64'],
|
|
1012
|
+
},
|
|
1013
|
+
},
|
|
1014
|
+
});
|
|
1015
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
1016
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
1017
|
+
process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
|
|
1018
|
+
const code = yield cli.run([
|
|
1019
|
+
'lambda',
|
|
1020
|
+
'instrument',
|
|
1021
|
+
'-f',
|
|
1022
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
1023
|
+
'-f',
|
|
1024
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world-2',
|
|
1025
|
+
'--dry-run',
|
|
1026
|
+
'-e',
|
|
1027
|
+
'40',
|
|
1028
|
+
'-v',
|
|
1029
|
+
'19',
|
|
1030
|
+
'--extra-tags',
|
|
1031
|
+
'layer:api,team:intake',
|
|
1032
|
+
'--service',
|
|
1033
|
+
'middletier',
|
|
1034
|
+
'--env',
|
|
1035
|
+
'staging',
|
|
1036
|
+
'--version',
|
|
1037
|
+
'0.2',
|
|
1038
|
+
'--no-source-code-integration',
|
|
1039
|
+
], context);
|
|
1040
|
+
const output = context.stdout.toString();
|
|
1041
|
+
expect(code).toBe(0);
|
|
1042
|
+
expect(output).toMatchSnapshot();
|
|
1043
|
+
}));
|
|
1044
|
+
test('aborts early when a layer version is set for a Custom runtime', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1045
|
+
;
|
|
1046
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
1047
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
1048
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
1049
|
+
config: {
|
|
1050
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
1051
|
+
Runtime: 'provided.al2',
|
|
1052
|
+
},
|
|
1053
|
+
},
|
|
1054
|
+
});
|
|
1055
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
1056
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
1057
|
+
const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
|
|
1058
|
+
process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
|
|
1059
|
+
const code = yield cli.run([
|
|
1060
|
+
'lambda',
|
|
1061
|
+
'instrument',
|
|
1062
|
+
'-f',
|
|
1063
|
+
functionARN,
|
|
1064
|
+
'--dry-run',
|
|
1065
|
+
'-v',
|
|
1066
|
+
'6',
|
|
1067
|
+
'--extra-tags',
|
|
1068
|
+
'layer:api,team:intake',
|
|
1069
|
+
'--service',
|
|
1070
|
+
'middletier',
|
|
1071
|
+
'--env',
|
|
1072
|
+
'staging',
|
|
1073
|
+
'--version',
|
|
1074
|
+
'0.2',
|
|
1075
|
+
'--no-source-code-integration',
|
|
1076
|
+
], context);
|
|
1077
|
+
const output = context.stdout.toString();
|
|
1078
|
+
expect(code).toBe(1);
|
|
1079
|
+
expect(output).toMatchInlineSnapshot(`
|
|
1080
|
+
"
|
|
1081
|
+
[Dry Run] 🐶 Instrumenting Lambda function
|
|
1082
|
+
[Error] Couldn't fetch Lambda functions. Error: Only the --extension-version argument should be set for the provided.al2 runtime. Please remove the --layer-version argument from the instrument command.
|
|
1083
|
+
"
|
|
1084
|
+
`);
|
|
1085
|
+
}));
|
|
1086
|
+
test('aborts early when .NET is using ARM64 architecture', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1087
|
+
;
|
|
1088
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
1089
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
1090
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
1091
|
+
config: {
|
|
1092
|
+
Architectures: ['arm64'],
|
|
1093
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
1094
|
+
Runtime: 'dotnet6',
|
|
1095
|
+
},
|
|
1096
|
+
},
|
|
1097
|
+
});
|
|
1098
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
1099
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
1100
|
+
const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
|
|
1101
|
+
process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
|
|
1102
|
+
const code = yield cli.run([
|
|
1103
|
+
'lambda',
|
|
1104
|
+
'instrument',
|
|
1105
|
+
'-f',
|
|
1106
|
+
functionARN,
|
|
1107
|
+
'--dry-run',
|
|
1108
|
+
'-v',
|
|
1109
|
+
'6',
|
|
1110
|
+
'--extra-tags',
|
|
1111
|
+
'layer:api,team:intake',
|
|
1112
|
+
'--service',
|
|
1113
|
+
'middletier',
|
|
1114
|
+
'--env',
|
|
1115
|
+
'staging',
|
|
1116
|
+
'--version',
|
|
1117
|
+
'0.2',
|
|
1118
|
+
'--no-source-code-integration',
|
|
1119
|
+
], context);
|
|
1120
|
+
const output = context.stdout.toString();
|
|
1121
|
+
expect(code).toBe(1);
|
|
1122
|
+
expect(output).toMatchInlineSnapshot(`
|
|
1123
|
+
"
|
|
1124
|
+
[Dry Run] 🐶 Instrumenting Lambda function
|
|
1125
|
+
[Error] Couldn't fetch Lambda functions. Error: Instrumenting arm64 architecture is not supported for the given dd-extension version. Please choose the latest dd-extension version or use x86_64 architecture.
|
|
1126
|
+
"
|
|
1127
|
+
`);
|
|
1128
|
+
}));
|
|
1129
|
+
test('instruments correctly with profile when provided', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1130
|
+
const credentials = fixtures_2.mockAwsCredentials;
|
|
1131
|
+
credential_providers_1.fromIni.mockImplementation((_init) => () => __awaiter(void 0, void 0, void 0, function* () { return Promise.resolve(credentials); }));
|
|
1132
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
1133
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
|
|
1134
|
+
config: {
|
|
1135
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
1136
|
+
Handler: 'index.handler',
|
|
1137
|
+
Runtime: 'nodejs20.x',
|
|
1138
|
+
},
|
|
1139
|
+
},
|
|
1140
|
+
});
|
|
1141
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
1142
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
1143
|
+
const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
|
|
1144
|
+
const code = yield cli.run(['lambda', 'instrument', '-f', functionARN, '--profile', 'SOME-AWS-PROFILE', '--no-source-code-integration'], context);
|
|
1145
|
+
expect(code).toBe(0);
|
|
1146
|
+
}));
|
|
1147
|
+
test('prints error when updating aws profile credentials fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1148
|
+
;
|
|
1149
|
+
credential_providers_1.fromIni.mockImplementation(() => {
|
|
1150
|
+
throw Error('Update failed!');
|
|
1151
|
+
});
|
|
1152
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
1153
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
1154
|
+
const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
|
|
1155
|
+
const code = yield cli.run(['lambda', 'instrument', '-f', functionARN, '--profile', 'SOME-AWS-PROFILE'], context);
|
|
1156
|
+
const output = context.stdout.toString();
|
|
1157
|
+
expect(code).toBe(1);
|
|
1158
|
+
expect(output).toMatchInlineSnapshot(`
|
|
1159
|
+
"
|
|
1160
|
+
🐶 Instrumenting Lambda function
|
|
1161
|
+
[Error] Error: Couldn't set AWS profile credentials. Update failed!
|
|
1162
|
+
"
|
|
1163
|
+
`);
|
|
1164
|
+
}));
|
|
1165
|
+
test('prints which functions failed to instrument without aborting when at least one function was instrumented correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1166
|
+
const failingLambdas = [
|
|
1167
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
|
|
1168
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-2-us-east-1',
|
|
1169
|
+
'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
|
|
1170
|
+
];
|
|
1171
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
1172
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
1173
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1': {
|
|
1174
|
+
config: {
|
|
1175
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
|
|
1176
|
+
FunctionName: 'lambda-1-us-east-1',
|
|
1177
|
+
Handler: 'index.handler',
|
|
1178
|
+
Runtime: 'nodejs20.x',
|
|
1179
|
+
},
|
|
1180
|
+
},
|
|
1181
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-2-us-east-1': {
|
|
1182
|
+
config: {
|
|
1183
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-2-us-east-1',
|
|
1184
|
+
FunctionName: 'lambda-2-us-east-1',
|
|
1185
|
+
Handler: 'index.handler',
|
|
1186
|
+
Runtime: 'nodejs20.x',
|
|
1187
|
+
},
|
|
1188
|
+
},
|
|
1189
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-3-us-east-1': {
|
|
1190
|
+
config: {
|
|
1191
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-3-us-east-1',
|
|
1192
|
+
FunctionName: 'lambda-3-us-east-1',
|
|
1193
|
+
Handler: 'index.handler',
|
|
1194
|
+
Runtime: 'nodejs20.x',
|
|
1195
|
+
},
|
|
1196
|
+
},
|
|
1197
|
+
'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2': {
|
|
1198
|
+
config: {
|
|
1199
|
+
FunctionArn: 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
|
|
1200
|
+
FunctionName: 'lambda-1-us-east-2',
|
|
1201
|
+
Handler: 'index.handler',
|
|
1202
|
+
Runtime: 'nodejs16.x',
|
|
1203
|
+
},
|
|
1204
|
+
},
|
|
1205
|
+
'arn:aws:lambda:us-east-2:123456789012:function:lambda-2-us-east-2': {
|
|
1206
|
+
config: {
|
|
1207
|
+
FunctionArn: 'arn:aws:lambda:us-east-2:123456789012:function:lambda-2-us-east-2',
|
|
1208
|
+
FunctionName: 'lambda-2-us-east-2',
|
|
1209
|
+
Handler: 'index.handler',
|
|
1210
|
+
Runtime: 'nodejs18.x',
|
|
1211
|
+
},
|
|
1212
|
+
},
|
|
1213
|
+
});
|
|
1214
|
+
for (const failingLambda of failingLambdas) {
|
|
1215
|
+
lambdaClientMock
|
|
1216
|
+
.on(client_lambda_1.UpdateFunctionConfigurationCommand, { FunctionName: failingLambda })
|
|
1217
|
+
.rejects('Unexpected error updating request');
|
|
1218
|
+
}
|
|
1219
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
1220
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
1221
|
+
const code = yield cli.run([
|
|
1222
|
+
'lambda',
|
|
1223
|
+
'instrument',
|
|
1224
|
+
'-f',
|
|
1225
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
|
|
1226
|
+
'-f',
|
|
1227
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-2-us-east-1',
|
|
1228
|
+
'-f',
|
|
1229
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-3-us-east-1',
|
|
1230
|
+
'-f',
|
|
1231
|
+
'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
|
|
1232
|
+
'-f',
|
|
1233
|
+
'arn:aws:lambda:us-east-2:123456789012:function:lambda-2-us-east-2',
|
|
1234
|
+
], context);
|
|
1235
|
+
const output = context.stdout.toString();
|
|
1236
|
+
expect(code).toBe(0);
|
|
1237
|
+
expect(output).toMatchSnapshot();
|
|
1238
|
+
}));
|
|
1239
|
+
test('aborts when every lambda function fails to update on instrument', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1240
|
+
;
|
|
1241
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
1242
|
+
(0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
|
|
1243
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1': {
|
|
1244
|
+
config: {
|
|
1245
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
|
|
1246
|
+
FunctionName: 'lambda-1-us-east-1',
|
|
1247
|
+
Handler: 'index.handler',
|
|
1248
|
+
Runtime: 'nodejs20.x',
|
|
1249
|
+
},
|
|
1250
|
+
},
|
|
1251
|
+
'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2': {
|
|
1252
|
+
config: {
|
|
1253
|
+
FunctionArn: 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
|
|
1254
|
+
FunctionName: 'lambda-1-us-east-2',
|
|
1255
|
+
Handler: 'index.handler',
|
|
1256
|
+
Runtime: 'nodejs18.x',
|
|
1257
|
+
},
|
|
1258
|
+
},
|
|
1259
|
+
});
|
|
1260
|
+
lambdaClientMock.on(client_lambda_1.UpdateFunctionConfigurationCommand).rejects('Unexpected error updating request');
|
|
1261
|
+
const cli = (0, fixtures_2.makeCli)();
|
|
1262
|
+
const context = (0, fixtures_1.createMockContext)();
|
|
1263
|
+
const code = yield cli.run([
|
|
1264
|
+
'lambda',
|
|
1265
|
+
'instrument',
|
|
1266
|
+
'-f',
|
|
1267
|
+
'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
|
|
1268
|
+
'-f',
|
|
1269
|
+
'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
|
|
1270
|
+
], context);
|
|
1271
|
+
const output = context.stdout.toString();
|
|
1272
|
+
expect(code).toBe(1);
|
|
1273
|
+
expect(output).toMatchSnapshot();
|
|
1274
|
+
}));
|
|
1275
|
+
});
|
|
1276
|
+
describe('getSettings', () => {
|
|
1277
|
+
beforeEach(() => {
|
|
1278
|
+
lambdaClientMock.reset();
|
|
1279
|
+
});
|
|
1280
|
+
test('uses config file settings', () => {
|
|
1281
|
+
process.env = {};
|
|
1282
|
+
const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
|
|
1283
|
+
command['config']['flushMetricsToLogs'] = 'false';
|
|
1284
|
+
command['config']['forwarder'] = 'my-forwarder';
|
|
1285
|
+
command['config']['layerVersion'] = '2';
|
|
1286
|
+
command['config']['extensionVersion'] = '6';
|
|
1287
|
+
command['config']['layerAWSAccount'] = 'another-account';
|
|
1288
|
+
command['config']['mergeXrayTraces'] = 'false';
|
|
1289
|
+
command['config']['tracing'] = 'false';
|
|
1290
|
+
command['config']['logLevel'] = 'debug';
|
|
1291
|
+
expect(command['getSettings']()).toEqual({
|
|
1292
|
+
appsecEnabled: false,
|
|
1293
|
+
apmFlushDeadline: undefined,
|
|
1294
|
+
captureLambdaPayload: false,
|
|
1295
|
+
environment: undefined,
|
|
1296
|
+
extensionVersion: 6,
|
|
1297
|
+
extraTags: undefined,
|
|
1298
|
+
flushMetricsToLogs: false,
|
|
1299
|
+
forwarderARN: 'my-forwarder',
|
|
1300
|
+
interactive: false,
|
|
1301
|
+
layerAWSAccount: 'another-account',
|
|
1302
|
+
layerVersion: 2,
|
|
1303
|
+
logLevel: 'debug',
|
|
1304
|
+
mergeXrayTraces: false,
|
|
1305
|
+
service: undefined,
|
|
1306
|
+
tracingEnabled: false,
|
|
1307
|
+
version: undefined,
|
|
1308
|
+
});
|
|
1309
|
+
});
|
|
1310
|
+
test('prefers command line arguments over config file', () => {
|
|
1311
|
+
process.env = {};
|
|
1312
|
+
const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
|
|
1313
|
+
command['forwarder'] = 'my-forwarder';
|
|
1314
|
+
command['config']['forwarder'] = 'another-forwarder';
|
|
1315
|
+
command['layerVersion'] = '1';
|
|
1316
|
+
command['config']['layerVersion'] = '2';
|
|
1317
|
+
command['layerAWSAccount'] = 'my-account';
|
|
1318
|
+
command['config']['layerAWSAccount'] = 'another-account';
|
|
1319
|
+
command['mergeXrayTraces'] = 'true';
|
|
1320
|
+
command['config']['mergeXrayTraces'] = 'false';
|
|
1321
|
+
command['flushMetricsToLogs'] = 'false';
|
|
1322
|
+
command['config']['flushMetricsToLogs'] = 'true';
|
|
1323
|
+
command['tracing'] = 'true';
|
|
1324
|
+
command['config']['tracing'] = 'false';
|
|
1325
|
+
command['logLevel'] = 'debug';
|
|
1326
|
+
command['config']['logLevel'] = 'info';
|
|
1327
|
+
command['apmFlushDeadline'] = '20';
|
|
1328
|
+
command['config']['apmFlushDeadline'] = '50';
|
|
1329
|
+
expect(command['getSettings']()).toEqual({
|
|
1330
|
+
appsecEnabled: false,
|
|
1331
|
+
apmFlushDeadline: '20',
|
|
1332
|
+
captureLambdaPayload: false,
|
|
1333
|
+
flushMetricsToLogs: false,
|
|
1334
|
+
forwarderARN: 'my-forwarder',
|
|
1335
|
+
interactive: false,
|
|
1336
|
+
layerAWSAccount: 'my-account',
|
|
1337
|
+
layerVersion: 1,
|
|
1338
|
+
logLevel: 'debug',
|
|
1339
|
+
mergeXrayTraces: true,
|
|
1340
|
+
tracingEnabled: true,
|
|
1341
|
+
});
|
|
1342
|
+
});
|
|
1343
|
+
test("returns undefined when layer version can't be parsed", () => {
|
|
1344
|
+
process.env = {};
|
|
1345
|
+
const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
|
|
1346
|
+
command.context = {
|
|
1347
|
+
stdout: { write: jest.fn() },
|
|
1348
|
+
};
|
|
1349
|
+
command['layerVersion'] = 'abd';
|
|
1350
|
+
expect(command['getSettings']()).toBeUndefined();
|
|
1351
|
+
});
|
|
1352
|
+
test("returns undefined when extension version can't be parsed", () => {
|
|
1353
|
+
process.env = {};
|
|
1354
|
+
const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
|
|
1355
|
+
command.context = {
|
|
1356
|
+
stdout: { write: jest.fn() },
|
|
1357
|
+
};
|
|
1358
|
+
command['extensionVersion'] = 'abd';
|
|
1359
|
+
expect(command['getSettings']()).toBeUndefined();
|
|
1360
|
+
});
|
|
1361
|
+
test('converts string boolean from command line and config file correctly', () => {
|
|
1362
|
+
process.env = {};
|
|
1363
|
+
const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
|
|
1364
|
+
const validSettings = {
|
|
1365
|
+
appsecEnabled: false,
|
|
1366
|
+
captureLambdaPayload: true,
|
|
1367
|
+
extensionVersion: undefined,
|
|
1368
|
+
flushMetricsToLogs: false,
|
|
1369
|
+
forwarderARN: undefined,
|
|
1370
|
+
interactive: false,
|
|
1371
|
+
layerAWSAccount: undefined,
|
|
1372
|
+
layerVersion: undefined,
|
|
1373
|
+
logLevel: undefined,
|
|
1374
|
+
mergeXrayTraces: false,
|
|
1375
|
+
tracingEnabled: true,
|
|
1376
|
+
};
|
|
1377
|
+
command['config']['captureLambdaPayload'] = 'truE';
|
|
1378
|
+
command['config']['flushMetricsToLogs'] = 'False';
|
|
1379
|
+
command['config']['mergeXrayTraces'] = 'falSE';
|
|
1380
|
+
command['config']['tracing'] = 'TRUE';
|
|
1381
|
+
expect(command['getSettings']()).toEqual(validSettings);
|
|
1382
|
+
command['config']['captureLambdaPayload'] = 'true';
|
|
1383
|
+
command['config']['flushMetricsToLogs'] = 'false';
|
|
1384
|
+
command['config']['mergeXrayTraces'] = 'false';
|
|
1385
|
+
command['config']['tracing'] = 'true';
|
|
1386
|
+
expect(command['getSettings']()).toEqual(validSettings);
|
|
1387
|
+
validSettings.captureLambdaPayload = false;
|
|
1388
|
+
validSettings.flushMetricsToLogs = true;
|
|
1389
|
+
validSettings.mergeXrayTraces = true;
|
|
1390
|
+
validSettings.tracingEnabled = false;
|
|
1391
|
+
command['captureLambdaPayload'] = 'faLSE';
|
|
1392
|
+
command['flushMetricsToLogs'] = 'truE';
|
|
1393
|
+
command['mergeXrayTraces'] = 'TRUe';
|
|
1394
|
+
command['tracing'] = 'FALSE';
|
|
1395
|
+
expect(command['getSettings']()).toEqual(validSettings);
|
|
1396
|
+
command['captureLambdaPayload'] = 'false';
|
|
1397
|
+
command['flushMetricsToLogs'] = 'true';
|
|
1398
|
+
command['mergeXrayTraces'] = 'true';
|
|
1399
|
+
command['tracing'] = 'false';
|
|
1400
|
+
expect(command['getSettings']()).toEqual(validSettings);
|
|
1401
|
+
});
|
|
1402
|
+
test('aborts early if converting string boolean has an invalid value', () => {
|
|
1403
|
+
process.env = {};
|
|
1404
|
+
const stringBooleans = [
|
|
1405
|
+
'flushMetricsToLogs',
|
|
1406
|
+
'mergeXrayTraces',
|
|
1407
|
+
'tracing',
|
|
1408
|
+
];
|
|
1409
|
+
for (const option of stringBooleans) {
|
|
1410
|
+
let command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
|
|
1411
|
+
command['config'][option] = 'NotBoolean';
|
|
1412
|
+
command['getSettings']();
|
|
1413
|
+
let output = command.context.stdout.toString();
|
|
1414
|
+
expect(output).toMatch(`[Error] Invalid boolean specified for ${option}.\n`);
|
|
1415
|
+
command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
|
|
1416
|
+
command[option] = 'NotBoolean';
|
|
1417
|
+
command['getSettings']();
|
|
1418
|
+
output = command.context.stdout.toString();
|
|
1419
|
+
expect(output).toMatch(`Invalid boolean specified for ${option}.\n`);
|
|
1420
|
+
}
|
|
1421
|
+
});
|
|
1422
|
+
test('warns if any of environment, service or version tags are not set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1423
|
+
;
|
|
1424
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
1425
|
+
process.env = {};
|
|
1426
|
+
let command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
|
|
1427
|
+
command['config']['region'] = 'ap-southeast-1';
|
|
1428
|
+
command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
|
|
1429
|
+
command['getSettings']();
|
|
1430
|
+
let output = command.context.stdout.toString();
|
|
1431
|
+
expect(output).toMatch('[Warning] The environment, service and version tags have not been configured. Learn more about Datadog unified service tagging: https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/#serverless-environment.\n');
|
|
1432
|
+
command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
|
|
1433
|
+
command['config']['region'] = 'ap-southeast-1';
|
|
1434
|
+
command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
|
|
1435
|
+
command['config']['environment'] = 'b';
|
|
1436
|
+
command['config']['service'] = 'middletier';
|
|
1437
|
+
command['getSettings']();
|
|
1438
|
+
output = command.context.stdout.toString();
|
|
1439
|
+
expect(output).toMatch('[Warning] The version tag has not been configured. Learn more about Datadog unified service tagging: https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/#serverless-environment.\n');
|
|
1440
|
+
}));
|
|
1441
|
+
test('aborts early if extraTags do not comply with expected key:value list', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1442
|
+
;
|
|
1443
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
1444
|
+
process.env = {};
|
|
1445
|
+
const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
|
|
1446
|
+
command['config']['region'] = 'ap-southeast-1';
|
|
1447
|
+
command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
|
|
1448
|
+
command['config']['service'] = 'middletier';
|
|
1449
|
+
command['config']['environment'] = 'staging';
|
|
1450
|
+
command['config']['version'] = '0.2';
|
|
1451
|
+
command['config']['extraTags'] = 'not@complying:illegal-chars-in-key,complies:valid-pair';
|
|
1452
|
+
command['getSettings']();
|
|
1453
|
+
const output = command.context.stdout.toString();
|
|
1454
|
+
expect(output).toMatch('[Error] Extra tags do not comply with the <key>:<value> array.\n');
|
|
1455
|
+
}));
|
|
1456
|
+
});
|
|
1457
|
+
describe('printPlannedActions', () => {
|
|
1458
|
+
test('prints no output when list is empty', () => {
|
|
1459
|
+
process.env = {};
|
|
1460
|
+
const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
|
|
1461
|
+
command['printPlannedActions']([]);
|
|
1462
|
+
const output = command.context.stdout.toString();
|
|
1463
|
+
expect(output).toMatchInlineSnapshot(`
|
|
1464
|
+
"
|
|
1465
|
+
No updates will be applied.
|
|
1466
|
+
"
|
|
1467
|
+
`);
|
|
1468
|
+
});
|
|
1469
|
+
test('prints log group actions', () => {
|
|
1470
|
+
process.env = {};
|
|
1471
|
+
const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
|
|
1472
|
+
command['printPlannedActions']([
|
|
1473
|
+
{
|
|
1474
|
+
functionARN: 'my-func',
|
|
1475
|
+
lambdaConfig: {},
|
|
1476
|
+
logGroupConfiguration: {
|
|
1477
|
+
createLogGroupCommandInput: { logGroupName: 'my-log-group' },
|
|
1478
|
+
deleteSubscriptionFilterCommandInput: { filterName: 'my-filter' },
|
|
1479
|
+
logGroupName: 'my-log-group',
|
|
1480
|
+
putSubscriptionFilterCommandInput: { filterName: 'my-filter' },
|
|
1481
|
+
},
|
|
1482
|
+
},
|
|
1483
|
+
]);
|
|
1484
|
+
const output = command.context.stdout.toString();
|
|
1485
|
+
expect(output).toMatchInlineSnapshot(`
|
|
1486
|
+
"
|
|
1487
|
+
[Warning] Instrument your Lambda functions in a dev or staging environment first. Should the instrumentation result be unsatisfactory, run \`uninstrument\` with the same arguments to revert the changes.
|
|
1488
|
+
|
|
1489
|
+
[!] Functions to be updated:
|
|
1490
|
+
- my-func
|
|
1491
|
+
|
|
1492
|
+
Will apply the following updates:
|
|
1493
|
+
CreateLogGroup -> my-log-group
|
|
1494
|
+
{
|
|
1495
|
+
"logGroupName": "my-log-group"
|
|
1496
|
+
}
|
|
1497
|
+
DeleteSubscriptionFilter -> my-log-group
|
|
1498
|
+
{
|
|
1499
|
+
"filterName": "my-filter"
|
|
1500
|
+
}
|
|
1501
|
+
PutSubscriptionFilter -> my-log-group
|
|
1502
|
+
{
|
|
1503
|
+
"filterName": "my-filter"
|
|
1504
|
+
}
|
|
1505
|
+
"
|
|
1506
|
+
`);
|
|
1507
|
+
});
|
|
1508
|
+
});
|
|
1509
|
+
});
|
|
1510
|
+
});
|
|
1511
|
+
//# sourceMappingURL=instrument.test.js.map
|