@datadog/datadog-ci 0.17.10 → 0.17.11

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.
Files changed (55) hide show
  1. package/LICENSE-3rdparty.csv +2 -0
  2. package/README.md +3 -1
  3. package/dist/{commands/dependencies/index.d.ts → cli.d.ts} +0 -0
  4. package/dist/cli.js +34 -0
  5. package/dist/commands/{dsyms/index.d.ts → dependencies/cli.d.ts} +0 -0
  6. package/dist/commands/dependencies/{index.js → cli.js} +0 -0
  7. package/dist/commands/dependencies/upload.d.ts +1 -1
  8. package/dist/commands/{git-metadata/index.d.ts → dsyms/cli.d.ts} +0 -0
  9. package/dist/commands/dsyms/{index.js → cli.js} +0 -0
  10. package/dist/commands/dsyms/upload.d.ts +1 -1
  11. package/dist/commands/{junit/index.d.ts → git-metadata/cli.d.ts} +0 -0
  12. package/dist/commands/git-metadata/{index.js → cli.js} +0 -0
  13. package/dist/commands/git-metadata/upload.d.ts +1 -1
  14. package/dist/commands/git-metadata/upload.js +6 -1
  15. package/dist/commands/{lambda/index.d.ts → junit/cli.d.ts} +0 -0
  16. package/dist/commands/junit/{index.js → cli.js} +0 -0
  17. package/dist/commands/junit/upload.d.ts +1 -1
  18. package/dist/commands/lambda/__tests__/functions/commons.test.js +14 -0
  19. package/dist/commands/lambda/__tests__/functions/instrument.test.js +49 -16
  20. package/dist/commands/lambda/__tests__/functions/uninstrument.test.js +79 -7
  21. package/dist/commands/lambda/__tests__/instrument.test.js +117 -107
  22. package/dist/commands/lambda/__tests__/uninstrument.test.js +71 -14
  23. package/dist/commands/{sourcemaps/index.d.ts → lambda/cli.d.ts} +0 -0
  24. package/dist/commands/lambda/{index.js → cli.js} +0 -0
  25. package/dist/commands/lambda/constants.d.ts +1 -0
  26. package/dist/commands/lambda/constants.js +8 -1
  27. package/dist/commands/lambda/functions/commons.d.ts +19 -1
  28. package/dist/commands/lambda/functions/commons.js +64 -1
  29. package/dist/commands/lambda/functions/instrument.d.ts +4 -10
  30. package/dist/commands/lambda/functions/instrument.js +22 -39
  31. package/dist/commands/lambda/functions/uninstrument.d.ts +3 -2
  32. package/dist/commands/lambda/functions/uninstrument.js +18 -8
  33. package/dist/commands/lambda/instrument.d.ts +0 -1
  34. package/dist/commands/lambda/instrument.js +22 -21
  35. package/dist/commands/lambda/interfaces.d.ts +0 -1
  36. package/dist/commands/lambda/loggroup.js +3 -1
  37. package/dist/commands/lambda/uninstrument.d.ts +1 -0
  38. package/dist/commands/lambda/uninstrument.js +50 -11
  39. package/dist/commands/{trace/index.d.ts → sourcemaps/cli.d.ts} +0 -0
  40. package/dist/commands/sourcemaps/{index.js → cli.js} +0 -0
  41. package/dist/commands/sourcemaps/upload.d.ts +1 -1
  42. package/dist/commands/synthetics/__tests__/cli.test.js +13 -13
  43. package/dist/commands/synthetics/__tests__/websocket.test.js +3 -3
  44. package/dist/commands/synthetics/cli.d.ts +1 -26
  45. package/dist/commands/synthetics/cli.js +2 -227
  46. package/dist/commands/synthetics/command.d.ts +26 -0
  47. package/dist/commands/synthetics/command.js +229 -0
  48. package/dist/commands/synthetics/index.d.ts +5 -1
  49. package/dist/commands/synthetics/index.js +31 -2
  50. package/dist/commands/trace/cli.d.ts +1 -0
  51. package/dist/commands/trace/{index.js → cli.js} +0 -0
  52. package/dist/commands/trace/trace.d.ts +1 -1
  53. package/dist/index.d.ts +3 -1
  54. package/dist/index.js +23 -31
  55. package/package.json +7 -5
@@ -7,6 +7,7 @@ Component,Origin,Licence,Copyright
7
7
  @types/tiny-async-pool,dev,MIT,Copyright (c) Microsoft Corporation
8
8
  @types/deep-extend,dev,MIT,Copyright Microsoft Corporation
9
9
  @types/glob,dev,MIT,Copyright Microsoft Corporation
10
+ @types/inquirer,dev,MIT,Copyright Microsoft Corporation
10
11
  @types/jest,dev,MIT,Copyright Microsoft Corporation
11
12
  @types/node,dev,MIT,Copyright Microsoft Corporation
12
13
  @types/ssh2,dev,MIT,Copyright Microsoft Corporation
@@ -25,6 +26,7 @@ deep-extend,import,MIT,Copyright (c) 2013-2018, Viacheslav Lotsmanov
25
26
  fast-xml-parser,import,MIT,Copyright (c) 2017 Amit Kumar Gupta
26
27
  form-data,import,MIT,Copyright (c) 2012 Felix Geisendörfer (felix@debuggable.com) and contributors
27
28
  glob,import,ISC,Copyright (c) Isaac Z. Schlueter and Contributors
29
+ inquirer,import,MIT,Copyright (c) 2012 Simon Boudrias
28
30
  jest,dev,MIT,Copyright (c) Facebook, Inc. and its affiliates.
29
31
  jest-environment-node,dev,MIT,Copyright (c) Facebook, Inc. and its affiliates.
30
32
  jest-matcher-specific-error,dev,MIT,Copyright (c) 2020 Daniel Hreben
package/README.md CHANGED
@@ -33,12 +33,13 @@ yarn global add @datadog/datadog-ci
33
33
  ```bash
34
34
  Usage: datadog-ci <command> <subcommand> [options]
35
35
 
36
- Available command:
36
+ Available commands:
37
37
  - dependencies
38
38
  - lambda
39
39
  - sourcemaps
40
40
  - synthetics
41
41
  - dsyms
42
+ - git-metadata
42
43
  ```
43
44
 
44
45
  Each command allows interacting with a product of the Datadog platform. The commands are defined in the [src/commands](/src/commands) folder.
@@ -50,6 +51,7 @@ Further documentation for each command can be found in its folder, ie:
50
51
  - [Sourcemaps](src/commands/sourcemaps/)
51
52
  - [Synthetics CI/CD Testing](src/commands/synthetics/)
52
53
  - [iOS dSYM Files](src/commands/dsyms/)
54
+ - [Git metadata](src/commands/git-metadata)
53
55
 
54
56
  ## Contributing
55
57
 
package/dist/cli.js ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const clipanion_1 = require("clipanion");
9
+ const onError = (err) => {
10
+ console.log(err);
11
+ process.exitCode = 1;
12
+ };
13
+ process.on('uncaughtException', onError);
14
+ process.on('unhandledRejection', onError);
15
+ const cli = new clipanion_1.Cli({
16
+ binaryLabel: 'Datadog CI',
17
+ binaryName: 'datadog-ci',
18
+ binaryVersion: require('../package.json').version,
19
+ });
20
+ const commandsPath = `${__dirname}/commands`;
21
+ for (const commandFolder of fs_1.default.readdirSync(commandsPath)) {
22
+ const commandPath = `${commandsPath}/${commandFolder}`;
23
+ if (fs_1.default.statSync(commandPath).isDirectory()) {
24
+ // tslint:disable-next-line: no-var-requires
25
+ require(`${commandPath}/cli`).forEach((command) => cli.register(command));
26
+ }
27
+ }
28
+ if (require.main === module) {
29
+ cli.runExit(process.argv.slice(2), {
30
+ stderr: process.stderr,
31
+ stdin: process.stdin,
32
+ stdout: process.stdout,
33
+ });
34
+ }
File without changes
@@ -1,7 +1,7 @@
1
1
  import { Command } from 'clipanion';
2
2
  export declare class UploadCommand extends Command {
3
3
  static SUPPORTED_SOURCES: string[];
4
- static usage: import("clipanion/lib/advanced").Usage;
4
+ static usage: import("clipanion").Usage;
5
5
  private static INVALID_INPUT_EXIT_CODE;
6
6
  private static MISSING_FILE_EXIT_CODE;
7
7
  private static UPLOAD_ERROR_EXIT_CODE;
File without changes
@@ -1,6 +1,6 @@
1
1
  import { Command } from 'clipanion';
2
2
  export declare class UploadCommand extends Command {
3
- static usage: import("clipanion/lib/advanced").Usage;
3
+ static usage: import("clipanion").Usage;
4
4
  private basePath;
5
5
  private config;
6
6
  private dryRun;
File without changes
@@ -1,6 +1,6 @@
1
1
  import { Command } from 'clipanion';
2
2
  export declare class UploadCommand extends Command {
3
- static usage: import("clipanion/lib/advanced").Usage;
3
+ static usage: import("clipanion").Usage;
4
4
  repositoryURL?: string;
5
5
  private cliVersion;
6
6
  private config;
@@ -51,7 +51,7 @@ class UploadCommand extends clipanion_1.Command {
51
51
  });
52
52
  const payload = yield git_1.getCommitInfo(yield git_1.newSimpleGit(), this.context.stdout, this.repositoryURL);
53
53
  if (payload === undefined) {
54
- return 0;
54
+ return 1;
55
55
  }
56
56
  this.context.stdout.write(renderer_1.renderCommandInfo(payload));
57
57
  try {
@@ -106,6 +106,11 @@ class UploadCommand extends clipanion_1.Command {
106
106
  return utils_1.getRequestBuilder({
107
107
  apiKey: this.config.apiKey,
108
108
  baseUrl: api_1.getBaseIntakeUrl(),
109
+ headers: new Map([
110
+ ['DD-EVP-ORIGIN', 'datadog-ci git-metadata'],
111
+ ['DD-EVP-ORIGIN-VERSION', this.cliVersion],
112
+ ]),
113
+ overrideUrl: 'api/v2/srcmap',
109
114
  });
110
115
  }
111
116
  uploadRepository(requestBuilder) {
File without changes
@@ -1,6 +1,6 @@
1
1
  import { Command } from 'clipanion';
2
2
  export declare class UploadJUnitXMLCommand extends Command {
3
- static usage: import("clipanion/lib/advanced").Usage;
3
+ static usage: import("clipanion").Usage;
4
4
  private basePaths?;
5
5
  private config;
6
6
  private dryRun;
@@ -58,6 +58,20 @@ describe('commons', () => {
58
58
  ]);
59
59
  });
60
60
  });
61
+ describe('coerceBoolean', () => {
62
+ test('return fallback when none of the values provided can be parsed to boolean', () => {
63
+ expect(commons_1.coerceBoolean(true, 'NotBoolean', 123, [], {})).toBe(true);
64
+ expect(commons_1.coerceBoolean(false, 'NotBooleanEither', 456, ['An array'], { booleanInObject: true })).toBe(false);
65
+ });
66
+ test('return the first boolean when one of the values provided can be parsed to boolean', () => {
67
+ expect(commons_1.coerceBoolean(true, 'false', 'true')).toBe(false);
68
+ expect(commons_1.coerceBoolean(false, 'true', 'False')).toBe(true);
69
+ });
70
+ test('return the first boolean when one of the values provided is boolean', () => {
71
+ expect(commons_1.coerceBoolean(true, false, 'truE', true)).toBe(false);
72
+ expect(commons_1.coerceBoolean(false, true, 'False', false)).toBe(true);
73
+ });
74
+ });
61
75
  describe('collectFunctionsByRegion', () => {
62
76
  test('groups functions with region read from arn', () => {
63
77
  process.env = {};
@@ -140,7 +140,6 @@ describe('instrument', () => {
140
140
  "Environment": Object {
141
141
  "Variables": Object {
142
142
  "DD_API_KEY": "1234",
143
- "DD_FLUSH_TO_LOG": "false",
144
143
  "DD_LAMBDA_HANDLER": "index.handler",
145
144
  "DD_MERGE_XRAY_TRACES": "false",
146
145
  "DD_SITE": "datadoghq.com",
@@ -180,7 +179,6 @@ describe('instrument', () => {
180
179
  "Environment": Object {
181
180
  "Variables": Object {
182
181
  "DD_API_KEY_SECRET_ARN": "some-secret:arn:from:aws",
183
- "DD_FLUSH_TO_LOG": "false",
184
182
  "DD_LAMBDA_HANDLER": "index.handler",
185
183
  "DD_MERGE_XRAY_TRACES": "false",
186
184
  "DD_SITE": "datadoghq.com",
@@ -219,7 +217,6 @@ describe('instrument', () => {
219
217
  Object {
220
218
  "Environment": Object {
221
219
  "Variables": Object {
222
- "DD_FLUSH_TO_LOG": "false",
223
220
  "DD_KMS_API_KEY": "5678",
224
221
  "DD_LAMBDA_HANDLER": "index.handler",
225
222
  "DD_MERGE_XRAY_TRACES": "false",
@@ -262,6 +259,41 @@ describe('instrument', () => {
262
259
  "FunctionName": "arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world",
263
260
  "Handler": "datadog_lambda.handler.handler",
264
261
  }
262
+ `);
263
+ });
264
+ test("doesn't set DD_FLUSH_TO_LOGS when extension is being used", () => {
265
+ process.env[constants_1.CI_API_KEY_ENV_VAR] = '1234';
266
+ const config = {
267
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
268
+ Handler: 'index.handler',
269
+ Layers: [],
270
+ };
271
+ const runtime = 'python3.9';
272
+ const region = 'sa-east-1';
273
+ const settings = {
274
+ extensionVersion: 13,
275
+ flushMetricsToLogs: true,
276
+ mergeXrayTraces: false,
277
+ tracingEnabled: false,
278
+ };
279
+ const updateRequest = instrument_1.calculateUpdateRequest(config, settings, region, runtime);
280
+ expect(updateRequest).toMatchInlineSnapshot(`
281
+ Object {
282
+ "Environment": Object {
283
+ "Variables": Object {
284
+ "DD_API_KEY": "1234",
285
+ "DD_LAMBDA_HANDLER": "index.handler",
286
+ "DD_MERGE_XRAY_TRACES": "false",
287
+ "DD_SITE": "datadoghq.com",
288
+ "DD_TRACE_ENABLED": "false",
289
+ },
290
+ },
291
+ "FunctionName": "arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world",
292
+ "Handler": "datadog_lambda.handler.handler",
293
+ "Layers": Array [
294
+ "arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:13",
295
+ ],
296
+ }
265
297
  `);
266
298
  });
267
299
  test('by default calculates an update request with DATADOG_SITE being set to datadoghq.com', () => {
@@ -346,7 +378,7 @@ describe('instrument', () => {
346
378
  const runtime = 'python3.6';
347
379
  expect(() => {
348
380
  instrument_1.calculateUpdateRequest(config, settings, region, runtime);
349
- }).toThrowError('Warning: Invalid site URL. Must be either datadoghq.com, datadoghq.eu, us3.datadoghq.com, or ddog-gov.com.');
381
+ }).toThrowError('Warning: Invalid site URL. Must be either datadoghq.com, datadoghq.eu, us3.datadoghq.com, us5.datadoghq.com, or ddog-gov.com.');
350
382
  });
351
383
  test('throws an error when neither DATADOG_API_KEY nor DATADOG_KMS_API_KEY are given through the environment while using extensionVersion', () => {
352
384
  const config = {
@@ -390,7 +422,7 @@ describe('instrument', () => {
390
422
  }).toThrowError('`apiKeySecretArn` is not supported for Node runtimes when using Synchronous Metrics. Use either `apiKey` or `apiKmsKey`.');
391
423
  });
392
424
  });
393
- describe('getFunctionConfig', () => {
425
+ describe('getInstrumentedFunctionConfig', () => {
394
426
  const OLD_ENV = process.env;
395
427
  beforeEach(() => {
396
428
  jest.resetModules();
@@ -416,7 +448,7 @@ describe('instrument', () => {
416
448
  const config = (yield lambda
417
449
  .getFunction({ FunctionName: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument' })
418
450
  .promise()).Configuration;
419
- yield expect(instrument_1.getFunctionConfig(lambda, cloudWatch, config, 'us-east-1', settings)).rejects.toThrow();
451
+ yield expect(instrument_1.getInstrumentedFunctionConfig(lambda, cloudWatch, config, 'us-east-1', settings)).rejects.toThrow();
420
452
  }));
421
453
  test('replaces the layer arn when the version has changed', () => __awaiter(void 0, void 0, void 0, function* () {
422
454
  var _a;
@@ -440,7 +472,7 @@ describe('instrument', () => {
440
472
  const config = (yield lambda
441
473
  .getFunction({ FunctionName: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument' })
442
474
  .promise()).Configuration;
443
- const result = yield instrument_1.getFunctionConfig(lambda, cloudWatch, config, 'us-east-1', settings);
475
+ const result = yield instrument_1.getInstrumentedFunctionConfig(lambda, cloudWatch, config, 'us-east-1', settings);
444
476
  expect((_a = result.updateRequest) === null || _a === void 0 ? void 0 : _a.Layers).toMatchInlineSnapshot(`
445
477
  Array [
446
478
  "arn:aws:lambda:us-east-1:464622532012:layer:AnotherLayer:10",
@@ -478,7 +510,8 @@ describe('instrument', () => {
478
510
  const config = (yield lambda
479
511
  .getFunction({ FunctionName: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument' })
480
512
  .promise()).Configuration;
481
- expect((yield instrument_1.getFunctionConfig(lambda, cloudWatch, config, 'us-east-1', settings)).updateRequest).toBeUndefined();
513
+ expect((yield instrument_1.getInstrumentedFunctionConfig(lambda, cloudWatch, config, 'us-east-1', settings))
514
+ .updateRequest).toBeUndefined();
482
515
  }));
483
516
  test('uses the GovCloud lambda layer when a GovCloud region is detected', () => __awaiter(void 0, void 0, void 0, function* () {
484
517
  var _b;
@@ -498,7 +531,7 @@ describe('instrument', () => {
498
531
  const config = (yield lambda
499
532
  .getFunction({ FunctionName: 'arn:aws-us-gov:lambda:us-gov-east-1:000000000000:function:autoinstrument' })
500
533
  .promise()).Configuration;
501
- const result = yield instrument_1.getFunctionConfig(lambda, cloudWatch, config, 'us-gov-east-1', settings);
534
+ const result = yield instrument_1.getInstrumentedFunctionConfig(lambda, cloudWatch, config, 'us-gov-east-1', settings);
502
535
  expect((_b = result.updateRequest) === null || _b === void 0 ? void 0 : _b.Layers).toMatchInlineSnapshot(`
503
536
  Array [
504
537
  "arn:aws-us-gov:lambda:us-gov-east-1:002406178527:layer:Datadog-Node12-x:30",
@@ -526,7 +559,7 @@ describe('instrument', () => {
526
559
  const config = (yield lambda
527
560
  .getFunction({ FunctionName: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument' })
528
561
  .promise()).Configuration;
529
- const result = yield instrument_1.getFunctionConfig(lambda, cloudWatch, config, 'us-east-1', settings);
562
+ const result = yield instrument_1.getInstrumentedFunctionConfig(lambda, cloudWatch, config, 'us-east-1', settings);
530
563
  expect(result).toBeDefined();
531
564
  expect(result.logGroupConfiguration).toMatchInlineSnapshot(`
532
565
  Object {
@@ -535,7 +568,7 @@ describe('instrument', () => {
535
568
  `);
536
569
  }));
537
570
  });
538
- describe('getLambdaConfigs', () => {
571
+ describe('getInstrumentedFunctionConfigs', () => {
539
572
  const OLD_ENV = process.env;
540
573
  beforeEach(() => {
541
574
  jest.resetModules();
@@ -563,7 +596,7 @@ describe('instrument', () => {
563
596
  tracingEnabled: false,
564
597
  version: '0.2',
565
598
  };
566
- const result = yield instrument_1.getFunctionConfigs(lambda, cloudWatch, 'us-east-1', ['arn:aws:lambda:us-east-1:000000000000:function:autoinstrument'], settings);
599
+ const result = yield instrument_1.getInstrumentedFunctionConfigs(lambda, cloudWatch, 'us-east-1', ['arn:aws:lambda:us-east-1:000000000000:function:autoinstrument'], settings);
567
600
  expect(result.length).toEqual(1);
568
601
  expect(result[0].updateRequest).toMatchInlineSnapshot(`
569
602
  Object {
@@ -622,14 +655,14 @@ describe('instrument', () => {
622
655
  tracingEnabled: false,
623
656
  version: '0.2',
624
657
  };
625
- const result = yield instrument_1.getFunctionConfigs(lambda, cloudWatch, 'us-east-1', [
658
+ const result = yield instrument_1.getInstrumentedFunctionConfigs(lambda, cloudWatch, 'us-east-1', [
626
659
  'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument',
627
660
  'arn:aws:lambda:us-east-1:000000000000:function:another-func',
628
661
  ], settings);
629
662
  expect(result.length).toEqual(2);
630
663
  }));
631
664
  });
632
- describe('getLambdaConfigsFromRegEx', () => {
665
+ describe('getInstrumentedFunctionConfigsFromRegEx', () => {
633
666
  const OLD_ENV = process.env;
634
667
  beforeEach(() => {
635
668
  jest.resetModules();
@@ -661,7 +694,7 @@ describe('instrument', () => {
661
694
  mergeXrayTraces: false,
662
695
  tracingEnabled: false,
663
696
  };
664
- const result = yield instrument_1.getLambdaConfigsFromRegEx(lambda, cloudWatch, 'us-east-1', 'autoinstrument-scr.', settings);
697
+ const result = yield instrument_1.getInstrumentedFunctionConfigsFromRegEx(lambda, cloudWatch, 'us-east-1', 'autoinstrument-scr.', settings);
665
698
  expect(result.length).toEqual(1);
666
699
  expect(result[0].updateRequest).toMatchInlineSnapshot(`
667
700
  Object {
@@ -698,7 +731,7 @@ describe('instrument', () => {
698
731
  mergeXrayTraces: false,
699
732
  tracingEnabled: false,
700
733
  };
701
- yield expect(instrument_1.getLambdaConfigsFromRegEx(lambda, cloudWatch, 'us-east-1', 'fake-pattern', settings)).rejects.toStrictEqual(new Error('Max retry count exceeded.'));
734
+ yield expect(instrument_1.getInstrumentedFunctionConfigsFromRegEx(lambda, cloudWatch, 'us-east-1', 'fake-pattern', settings)).rejects.toStrictEqual(new Error('Max retry count exceeded.'));
702
735
  }));
703
736
  });
704
737
  });
@@ -147,7 +147,7 @@ describe('uninstrument', () => {
147
147
  `);
148
148
  }));
149
149
  });
150
- describe('getFunctionConfigs', () => {
150
+ describe('getUninstrumentedFunctionConfigs', () => {
151
151
  const OLD_ENV = process.env;
152
152
  beforeEach(() => {
153
153
  jest.resetModules();
@@ -179,7 +179,7 @@ describe('uninstrument', () => {
179
179
  },
180
180
  });
181
181
  const cloudWatch = fixtures_1.makeMockCloudWatchLogs({});
182
- const result = yield uninstrument_1.getFunctionConfigs(lambda, cloudWatch, ['arn:aws:lambda:us-east-1:000000000000:function:uninstrument'], undefined);
182
+ const result = yield uninstrument_1.getUninstrumentedFunctionConfigs(lambda, cloudWatch, ['arn:aws:lambda:us-east-1:000000000000:function:uninstrument'], undefined);
183
183
  expect(result.length).toEqual(1);
184
184
  expect(result[0].updateRequest).toMatchInlineSnapshot(`
185
185
  Object {
@@ -219,7 +219,7 @@ describe('uninstrument', () => {
219
219
  },
220
220
  });
221
221
  const cloudWatch = fixtures_1.makeMockCloudWatchLogs({});
222
- const result = yield uninstrument_1.getFunctionConfigs(lambda, cloudWatch, [
222
+ const result = yield uninstrument_1.getUninstrumentedFunctionConfigs(lambda, cloudWatch, [
223
223
  'arn:aws:lambda:us-east-1:000000000000:function:another-func',
224
224
  'arn:aws:lambda:us-east-1:000000000000:function:uninstrument',
225
225
  ], undefined);
@@ -236,7 +236,7 @@ describe('uninstrument', () => {
236
236
  `);
237
237
  }));
238
238
  });
239
- describe('getFunctionConfig', () => {
239
+ describe('getUninstrumentedFunctionConfig', () => {
240
240
  const OLD_ENV = process.env;
241
241
  beforeEach(() => {
242
242
  jest.resetModules();
@@ -254,7 +254,7 @@ describe('uninstrument', () => {
254
254
  });
255
255
  const cloudWatch = fixtures_1.makeMockCloudWatchLogs({});
256
256
  const config = yield commons_1.getLambdaFunctionConfig(lambda, 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument');
257
- yield expect(uninstrument_1.getFunctionConfig(lambda, cloudWatch, config, undefined)).rejects.toThrow();
257
+ yield expect(uninstrument_1.getUninstrumentedFunctionConfig(lambda, cloudWatch, config, undefined)).rejects.toThrow();
258
258
  }));
259
259
  test('returns configurations without updateRequest when no changes need to be made', () => __awaiter(void 0, void 0, void 0, function* () {
260
260
  const lambda = fixtures_1.makeMockLambda({
@@ -269,7 +269,7 @@ describe('uninstrument', () => {
269
269
  });
270
270
  const cloudWatch = fixtures_1.makeMockCloudWatchLogs({});
271
271
  const config = yield commons_1.getLambdaFunctionConfig(lambda, 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument');
272
- expect((yield uninstrument_1.getFunctionConfig(lambda, cloudWatch, config, undefined)).updateRequest).toBeUndefined();
272
+ expect((yield uninstrument_1.getUninstrumentedFunctionConfig(lambda, cloudWatch, config, undefined)).updateRequest).toBeUndefined();
273
273
  }));
274
274
  test('returns log group configuration subscription delete request when forwarderARN is set', () => __awaiter(void 0, void 0, void 0, function* () {
275
275
  const logGroupName = '/aws/lambda/group';
@@ -286,7 +286,7 @@ describe('uninstrument', () => {
286
286
  });
287
287
  const cloudWatch = fixtures_1.makeMockCloudWatchLogs({});
288
288
  const config = yield commons_1.getLambdaFunctionConfig(lambda, 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument');
289
- const result = yield uninstrument_1.getFunctionConfig(lambda, cloudWatch, config, 'valid-forwarder-arn');
289
+ const result = yield uninstrument_1.getUninstrumentedFunctionConfig(lambda, cloudWatch, config, 'valid-forwarder-arn');
290
290
  expect(result).toBeDefined();
291
291
  expect(result.logGroupConfiguration).toMatchInlineSnapshot(`
292
292
  Object {
@@ -296,4 +296,76 @@ describe('uninstrument', () => {
296
296
  `);
297
297
  }));
298
298
  });
299
+ describe('getUninstrumentedFunctionConfigsFromRegEx', () => {
300
+ const OLD_ENV = process.env;
301
+ beforeEach(() => {
302
+ jest.resetModules();
303
+ process.env = {};
304
+ });
305
+ afterAll(() => {
306
+ process.env = OLD_ENV;
307
+ });
308
+ test('returns the update request for each function that matches the pattern', () => __awaiter(void 0, void 0, void 0, function* () {
309
+ const lambda = fixtures_1.makeMockLambda({
310
+ 'autoinstrument-scooby': {
311
+ Environment: {
312
+ Variables: {
313
+ [constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
314
+ [constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
315
+ [constants_1.LAMBDA_HANDLER_ENV_VAR]: 'index.handler',
316
+ [constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
317
+ [constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
318
+ [constants_1.SERVICE_ENV_VAR]: 'middletier',
319
+ [constants_1.SITE_ENV_VAR]: 'datadoghq.com',
320
+ [constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
321
+ [constants_1.VERSION_ENV_VAR]: '0.2',
322
+ USER_VARIABLE: 'shouldnt be deleted by uninstrumentation',
323
+ },
324
+ },
325
+ FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument-scooby',
326
+ FunctionName: 'autoinstrument-scooby',
327
+ Handler: '/opt/nodejs/node_modules/datadog-lambda-js/handler.handler',
328
+ Runtime: 'nodejs12.x',
329
+ },
330
+ 'autoinstrument-scrapy': {
331
+ Environment: {
332
+ Variables: {
333
+ [constants_1.API_KEY_ENV_VAR]: '1234',
334
+ [constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
335
+ [constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
336
+ [constants_1.LAMBDA_HANDLER_ENV_VAR]: 'index.handler',
337
+ [constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
338
+ [constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
339
+ },
340
+ },
341
+ FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument-scrapy',
342
+ FunctionName: 'autoinstrument-scrapy',
343
+ Handler: '/opt/nodejs/node_modules/datadog-lambda-js/handler.handler',
344
+ Runtime: 'nodejs12.x',
345
+ },
346
+ });
347
+ const cloudWatch = fixtures_1.makeMockCloudWatchLogs({});
348
+ const result = yield uninstrument_1.getUninstrumentedFunctionConfigsFromRegEx(lambda, cloudWatch, 'autoinstrument-scr.', undefined);
349
+ expect(result.length).toEqual(1);
350
+ expect(result[0].updateRequest).toMatchInlineSnapshot(`
351
+ Object {
352
+ "Environment": Object {
353
+ "Variables": Object {},
354
+ },
355
+ "FunctionName": "arn:aws:lambda:us-east-1:000000000000:function:autoinstrument-scrapy",
356
+ "Handler": "index.handler",
357
+ }
358
+ `);
359
+ }));
360
+ test('fails when retry count is exceeded', () => __awaiter(void 0, void 0, void 0, function* () {
361
+ const makeMockLambdaListFunctionsError = () => ({
362
+ listFunctions: jest.fn().mockImplementation((args) => ({
363
+ promise: () => Promise.reject(),
364
+ })),
365
+ });
366
+ const lambda = makeMockLambdaListFunctionsError();
367
+ const cloudWatch = fixtures_1.makeMockCloudWatchLogs({});
368
+ yield expect(uninstrument_1.getUninstrumentedFunctionConfigsFromRegEx(lambda, cloudWatch, 'fake-pattern', undefined)).rejects.toStrictEqual(new Error('Max retry count exceeded.'));
369
+ }));
370
+ });
299
371
  });