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