@datadog/datadog-ci 2.18.1 → 2.19.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/cli.d.ts +3 -1
- package/dist/cli.js +9 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/cloud-run/flare.d.ts +38 -7
- package/dist/commands/cloud-run/flare.js +304 -39
- package/dist/commands/cloud-run/flare.js.map +1 -1
- package/dist/commands/cloud-run/renderer.js +5 -1
- package/dist/commands/cloud-run/renderer.js.map +1 -1
- package/dist/commands/dsyms/renderer.js +6 -6
- package/dist/commands/dsyms/renderer.js.map +1 -1
- package/dist/commands/dsyms/upload.d.ts +5 -5
- package/dist/commands/dsyms/upload.js +66 -42
- package/dist/commands/dsyms/upload.js.map +1 -1
- package/dist/commands/dsyms/utils.d.ts +1 -1
- package/dist/commands/dsyms/utils.js +3 -3
- package/dist/commands/dsyms/utils.js.map +1 -1
- package/dist/commands/flutter-symbols/helpers.js +8 -4
- package/dist/commands/flutter-symbols/helpers.js.map +1 -1
- package/dist/commands/flutter-symbols/renderer.js +2 -2
- package/dist/commands/flutter-symbols/renderer.js.map +1 -1
- package/dist/commands/flutter-symbols/upload.d.ts +13 -13
- package/dist/commands/flutter-symbols/upload.js +66 -66
- package/dist/commands/flutter-symbols/upload.js.map +1 -1
- package/dist/commands/gate/api.js +4 -2
- package/dist/commands/gate/api.js.map +1 -1
- package/dist/commands/gate/evaluate.d.ts +18 -6
- package/dist/commands/gate/evaluate.js +116 -40
- package/dist/commands/gate/evaluate.js.map +1 -1
- package/dist/commands/gate/interfaces.d.ts +5 -0
- package/dist/commands/gate/renderer.js +16 -14
- package/dist/commands/gate/renderer.js.map +1 -1
- package/dist/commands/gate/utils.d.ts +1 -0
- package/dist/commands/gate/utils.js +8 -4
- package/dist/commands/gate/utils.js.map +1 -1
- package/dist/commands/git-metadata/git.d.ts +1 -1
- package/dist/commands/git-metadata/git.js +7 -3
- package/dist/commands/git-metadata/git.js.map +1 -1
- package/dist/commands/git-metadata/gitdb.d.ts +1 -1
- package/dist/commands/git-metadata/gitdb.js +7 -7
- package/dist/commands/git-metadata/gitdb.js.map +1 -1
- package/dist/commands/git-metadata/index.js +5 -1
- package/dist/commands/git-metadata/index.js.map +1 -1
- package/dist/commands/git-metadata/library.d.ts +1 -1
- package/dist/commands/git-metadata/library.js +13 -13
- package/dist/commands/git-metadata/library.js.map +1 -1
- package/dist/commands/git-metadata/upload.d.ts +5 -5
- package/dist/commands/git-metadata/upload.js +30 -32
- package/dist/commands/git-metadata/upload.js.map +1 -1
- package/dist/commands/junit/api.js +4 -4
- package/dist/commands/junit/api.js.map +1 -1
- package/dist/commands/junit/id.js +1 -1
- package/dist/commands/junit/id.js.map +1 -1
- package/dist/commands/junit/renderer.d.ts +1 -1
- package/dist/commands/junit/renderer.js +3 -3
- package/dist/commands/junit/renderer.js.map +1 -1
- package/dist/commands/junit/upload.d.ts +12 -11
- package/dist/commands/junit/upload.js +74 -63
- package/dist/commands/junit/upload.js.map +1 -1
- package/dist/commands/junit/utils.d.ts +1 -2
- package/dist/commands/junit/utils.js +5 -10
- package/dist/commands/junit/utils.js.map +1 -1
- package/dist/commands/lambda/constants.d.ts +3 -3
- package/dist/commands/lambda/constants.js +4 -49
- package/dist/commands/lambda/constants.js.map +1 -1
- package/dist/commands/lambda/flare.d.ts +16 -30
- package/dist/commands/lambda/flare.js +90 -146
- package/dist/commands/lambda/flare.js.map +1 -1
- package/dist/commands/lambda/functions/commons.d.ts +3 -3
- package/dist/commands/lambda/functions/commons.js +19 -14
- package/dist/commands/lambda/functions/commons.js.map +1 -1
- package/dist/commands/lambda/functions/instrument.js +28 -28
- package/dist/commands/lambda/functions/instrument.js.map +1 -1
- package/dist/commands/lambda/functions/uninstrument.js +9 -9
- package/dist/commands/lambda/functions/uninstrument.js.map +1 -1
- package/dist/commands/lambda/functions/versionChecker.d.ts +2 -2
- package/dist/commands/lambda/instrument.d.ts +22 -20
- package/dist/commands/lambda/instrument.js +66 -60
- package/dist/commands/lambda/instrument.js.map +1 -1
- package/dist/commands/lambda/loggroup.js +8 -8
- package/dist/commands/lambda/loggroup.js.map +1 -1
- package/dist/commands/lambda/prompt.d.ts +1 -2
- package/dist/commands/lambda/prompt.js +20 -38
- package/dist/commands/lambda/prompt.js.map +1 -1
- package/dist/commands/lambda/renderers/__mocks__/instrument-uninstrument-renderer.d.ts +2 -0
- package/dist/commands/lambda/renderers/__mocks__/instrument-uninstrument-renderer.js +11 -0
- package/dist/commands/lambda/renderers/__mocks__/instrument-uninstrument-renderer.js.map +1 -0
- package/dist/commands/lambda/renderers/common-renderer.js +2 -2
- package/dist/commands/lambda/renderers/common-renderer.js.map +1 -1
- package/dist/commands/lambda/renderers/instrument-uninstrument-renderer.d.ts +2 -2
- package/dist/commands/lambda/renderers/instrument-uninstrument-renderer.js +50 -42
- package/dist/commands/lambda/renderers/instrument-uninstrument-renderer.js.map +1 -1
- package/dist/commands/lambda/tags.js +7 -7
- package/dist/commands/lambda/tags.js.map +1 -1
- package/dist/commands/lambda/uninstrument.d.ts +25 -7
- package/dist/commands/lambda/uninstrument.js +53 -45
- package/dist/commands/lambda/uninstrument.js.map +1 -1
- package/dist/commands/metric/metric.d.ts +4 -3
- package/dist/commands/metric/metric.js +10 -9
- package/dist/commands/metric/metric.js.map +1 -1
- package/dist/commands/react-native/codepush.d.ts +11 -10
- package/dist/commands/react-native/codepush.js +17 -19
- package/dist/commands/react-native/codepush.js.map +1 -1
- package/dist/commands/react-native/interfaces.d.ts +1 -1
- package/dist/commands/react-native/renderer.js +6 -6
- package/dist/commands/react-native/renderer.js.map +1 -1
- package/dist/commands/react-native/upload.d.ts +12 -12
- package/dist/commands/react-native/upload.js +67 -45
- package/dist/commands/react-native/upload.js.map +1 -1
- package/dist/commands/react-native/utils.js +2 -1
- package/dist/commands/react-native/utils.js.map +1 -1
- package/dist/commands/react-native/validation.js +1 -1
- package/dist/commands/react-native/validation.js.map +1 -1
- package/dist/commands/react-native/xcode.d.ts +6 -6
- package/dist/commands/react-native/xcode.js +25 -29
- package/dist/commands/react-native/xcode.js.map +1 -1
- package/dist/commands/sarif/api.js +5 -5
- package/dist/commands/sarif/api.js.map +1 -1
- package/dist/commands/sarif/renderer.d.ts +1 -1
- package/dist/commands/sarif/renderer.js +1 -1
- package/dist/commands/sarif/renderer.js.map +1 -1
- package/dist/commands/sarif/upload.d.ts +6 -6
- package/dist/commands/sarif/upload.js +46 -37
- package/dist/commands/sarif/upload.js.map +1 -1
- package/dist/commands/sbom/api.d.ts +7 -0
- package/dist/commands/sbom/api.js +49 -0
- package/dist/commands/sbom/api.js.map +1 -0
- package/dist/commands/sbom/cli.d.ts +1 -0
- package/dist/commands/sbom/cli.js +5 -0
- package/dist/commands/sbom/cli.js.map +1 -0
- package/dist/commands/sbom/constants.d.ts +2 -0
- package/dist/commands/sbom/constants.js +6 -0
- package/dist/commands/sbom/constants.js.map +1 -0
- package/dist/commands/sbom/json-schema/cyclonedx/bom-1.4.schema.json +1687 -0
- package/dist/commands/sbom/json-schema/jsf/jsf-0.82.schema.json +244 -0
- package/dist/commands/sbom/json-schema/spdx/spdx.schema.json +507 -0
- package/dist/commands/sbom/protobuf/bom-1.4.d.ts +11788 -0
- package/dist/commands/sbom/protobuf/bom-1.4.js +5161 -0
- package/dist/commands/sbom/protobuf/bom-1.4.js.map +1 -0
- package/dist/commands/sbom/protobuf/custom_message.d.ts +11 -0
- package/dist/commands/sbom/protobuf/custom_message.js +3 -0
- package/dist/commands/sbom/protobuf/custom_message.js.map +1 -0
- package/dist/commands/sbom/protobuf/google/protobuf/duration.d.ts +110 -0
- package/dist/commands/sbom/protobuf/google/protobuf/duration.js +126 -0
- package/dist/commands/sbom/protobuf/google/protobuf/duration.js.map +1 -0
- package/dist/commands/sbom/protobuf/google/protobuf/timestamp.d.ts +139 -0
- package/dist/commands/sbom/protobuf/google/protobuf/timestamp.js +126 -0
- package/dist/commands/sbom/protobuf/google/protobuf/timestamp.js.map +1 -0
- package/dist/commands/sbom/protobuf/sbom_intake.d.ts +53 -0
- package/dist/commands/sbom/protobuf/sbom_intake.js +383 -0
- package/dist/commands/sbom/protobuf/sbom_intake.js.map +1 -0
- package/dist/commands/sbom/types.d.ts +4 -0
- package/dist/commands/sbom/types.js +3 -0
- package/dist/commands/sbom/types.js.map +1 -0
- package/dist/commands/sbom/upload.d.ts +16 -0
- package/dist/commands/sbom/upload.js +134 -0
- package/dist/commands/sbom/upload.js.map +1 -0
- package/dist/commands/sbom/validation.d.ts +12 -0
- package/dist/commands/sbom/validation.js +51 -0
- package/dist/commands/sbom/validation.js.map +1 -0
- package/dist/commands/sourcemaps/renderer.js +6 -6
- package/dist/commands/sourcemaps/renderer.js.map +1 -1
- package/dist/commands/sourcemaps/upload.d.ts +10 -10
- package/dist/commands/sourcemaps/upload.js +61 -38
- package/dist/commands/sourcemaps/upload.js.map +1 -1
- package/dist/commands/sourcemaps/validation.js +4 -4
- package/dist/commands/sourcemaps/validation.js.map +1 -1
- package/dist/commands/stepfunctions/awsCommands.js +10 -10
- package/dist/commands/stepfunctions/awsCommands.js.map +1 -1
- package/dist/commands/stepfunctions/helpers.d.ts +4 -4
- package/dist/commands/stepfunctions/helpers.js +4 -4
- package/dist/commands/stepfunctions/helpers.js.map +1 -1
- package/dist/commands/stepfunctions/instrument.d.ts +5 -4
- package/dist/commands/stepfunctions/instrument.js +30 -31
- package/dist/commands/stepfunctions/instrument.js.map +1 -1
- package/dist/commands/stepfunctions/uninstrument.d.ts +6 -1
- package/dist/commands/stepfunctions/uninstrument.js +23 -23
- package/dist/commands/stepfunctions/uninstrument.js.map +1 -1
- package/dist/commands/synthetics/api.d.ts +1 -1
- package/dist/commands/synthetics/api.js +11 -11
- package/dist/commands/synthetics/api.js.map +1 -1
- package/dist/commands/synthetics/errors.d.ts +3 -3
- package/dist/commands/synthetics/index.js +5 -1
- package/dist/commands/synthetics/index.js.map +1 -1
- package/dist/commands/synthetics/interfaces.d.ts +6 -6
- package/dist/commands/synthetics/interfaces.js +2 -2
- package/dist/commands/synthetics/interfaces.js.map +1 -1
- package/dist/commands/synthetics/mobile.d.ts +1 -1
- package/dist/commands/synthetics/mobile.js +26 -20
- package/dist/commands/synthetics/mobile.js.map +1 -1
- package/dist/commands/synthetics/reporters/default.d.ts +2 -2
- package/dist/commands/synthetics/reporters/default.js +14 -14
- 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 +11 -11
- package/dist/commands/synthetics/reporters/junit.js.map +1 -1
- package/dist/commands/synthetics/run-tests-command.d.ts +21 -19
- package/dist/commands/synthetics/run-tests-command.js +108 -42
- package/dist/commands/synthetics/run-tests-command.js.map +1 -1
- package/dist/commands/synthetics/run-tests-lib.d.ts +1 -1
- package/dist/commands/synthetics/run-tests-lib.js +16 -16
- package/dist/commands/synthetics/run-tests-lib.js.map +1 -1
- package/dist/commands/synthetics/tunnel/crypto.js +3 -3
- package/dist/commands/synthetics/tunnel/crypto.js.map +1 -1
- package/dist/commands/synthetics/tunnel/tunnel.js +11 -11
- package/dist/commands/synthetics/tunnel/tunnel.js.map +1 -1
- package/dist/commands/synthetics/tunnel/websocket.d.ts +1 -0
- package/dist/commands/synthetics/tunnel/websocket.js +7 -3
- package/dist/commands/synthetics/tunnel/websocket.js.map +1 -1
- package/dist/commands/synthetics/upload-application-command.d.ts +10 -8
- package/dist/commands/synthetics/upload-application-command.js +36 -13
- package/dist/commands/synthetics/upload-application-command.js.map +1 -1
- package/dist/commands/synthetics/utils.d.ts +12 -12
- package/dist/commands/synthetics/utils.js +51 -47
- package/dist/commands/synthetics/utils.js.map +1 -1
- package/dist/commands/tag/tag.d.ts +4 -3
- package/dist/commands/tag/tag.js +10 -9
- package/dist/commands/tag/tag.js.map +1 -1
- package/dist/commands/trace/api.js +4 -4
- package/dist/commands/trace/api.js.map +1 -1
- package/dist/commands/trace/interfaces.d.ts +1 -1
- package/dist/commands/trace/trace.d.ts +5 -4
- package/dist/commands/trace/trace.js +11 -10
- package/dist/commands/trace/trace.js.map +1 -1
- package/dist/commands/version/cli.js +6 -5
- package/dist/commands/version/cli.js.map +1 -1
- package/dist/constants.d.ts +7 -0
- package/dist/constants.js +52 -1
- package/dist/constants.js.map +1 -1
- package/dist/helpers/api.d.ts +5 -0
- package/dist/helpers/api.js +16 -0
- package/dist/helpers/api.js.map +1 -0
- package/dist/helpers/base-intake-url.d.ts +1 -1
- package/dist/helpers/ci.d.ts +13 -13
- package/dist/helpers/ci.js +17 -17
- package/dist/helpers/ci.js.map +1 -1
- package/dist/helpers/config.d.ts +5 -0
- package/dist/helpers/config.js +3 -0
- package/dist/helpers/config.js.map +1 -0
- package/dist/helpers/flare.d.ts +22 -0
- package/dist/helpers/flare.js +118 -8
- package/dist/helpers/flare.js.map +1 -1
- package/dist/helpers/git/format-git-sourcemaps-data.js +7 -3
- package/dist/helpers/git/format-git-sourcemaps-data.js.map +1 -1
- package/dist/helpers/git/format-git-span-data.js +6 -6
- package/dist/helpers/git/format-git-span-data.js.map +1 -1
- package/dist/helpers/git/get-git-data.js +3 -3
- package/dist/helpers/git/get-git-data.js.map +1 -1
- package/dist/helpers/interfaces.d.ts +9 -3
- package/dist/helpers/logger.js +1 -1
- package/dist/helpers/logger.js.map +1 -1
- package/dist/helpers/plist.d.ts +1 -1
- package/dist/helpers/plist.js +1 -1
- package/dist/helpers/plist.js.map +1 -1
- package/dist/helpers/prompt.d.ts +1 -0
- package/dist/helpers/prompt.js +20 -2
- package/dist/helpers/prompt.js.map +1 -1
- package/dist/helpers/renderer.d.ts +24 -0
- package/dist/helpers/renderer.js +60 -9
- package/dist/helpers/renderer.js.map +1 -1
- package/dist/helpers/retry.d.ts +1 -1
- package/dist/helpers/retry.js +3 -3
- package/dist/helpers/retry.js.map +1 -1
- package/dist/helpers/tags.d.ts +8 -0
- package/dist/helpers/tags.js +27 -1
- package/dist/helpers/tags.js.map +1 -1
- package/dist/helpers/upload.js +3 -3
- package/dist/helpers/upload.js.map +1 -1
- package/dist/helpers/user-provided-git.js +6 -6
- package/dist/helpers/user-provided-git.js.map +1 -1
- package/dist/helpers/utils.d.ts +4 -5
- package/dist/helpers/utils.js +18 -25
- package/dist/helpers/utils.js.map +1 -1
- package/dist/helpers/validation.d.ts +3 -1
- package/dist/helpers/validation.js +27 -1
- package/dist/helpers/validation.js.map +1 -1
- package/dist/helpers/version.d.ts +4 -0
- package/dist/helpers/version.js +9 -0
- package/dist/helpers/version.js.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +11 -8
- package/dist/index.js.map +1 -1
- package/package.json +22 -13
package/dist/cli.d.ts
CHANGED
package/dist/cli.js
CHANGED
|
@@ -4,9 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.cli = void 0;
|
|
7
8
|
const fs_1 = __importDefault(require("fs"));
|
|
8
9
|
const clipanion_1 = require("clipanion");
|
|
9
|
-
const
|
|
10
|
+
const version_1 = require("./helpers/version");
|
|
11
|
+
const BETA_COMMANDS = ['gate', 'sbom'];
|
|
10
12
|
const onError = (err) => {
|
|
11
13
|
console.log(err);
|
|
12
14
|
process.exitCode = 1;
|
|
@@ -16,8 +18,11 @@ process.on('unhandledRejection', onError);
|
|
|
16
18
|
const cli = new clipanion_1.Cli({
|
|
17
19
|
binaryLabel: 'Datadog CI',
|
|
18
20
|
binaryName: 'datadog-ci',
|
|
19
|
-
binaryVersion:
|
|
21
|
+
binaryVersion: version_1.version,
|
|
20
22
|
});
|
|
23
|
+
exports.cli = cli;
|
|
24
|
+
cli.register(clipanion_1.Builtins.HelpCommand);
|
|
25
|
+
cli.register(clipanion_1.Builtins.VersionCommand);
|
|
21
26
|
const commandsPath = `${__dirname}/commands`;
|
|
22
27
|
for (const commandFolder of fs_1.default.readdirSync(commandsPath)) {
|
|
23
28
|
const betaCommandsEnabled = process.env.DD_BETA_COMMANDS_ENABLED === '1' || process.env.DD_BETA_COMMANDS_ENABLED === 'true';
|
|
@@ -26,6 +31,8 @@ for (const commandFolder of fs_1.default.readdirSync(commandsPath)) {
|
|
|
26
31
|
}
|
|
27
32
|
const commandPath = `${commandsPath}/${commandFolder}`;
|
|
28
33
|
if (fs_1.default.statSync(commandPath).isDirectory()) {
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
35
|
+
;
|
|
29
36
|
require(`${commandPath}/cli`).forEach((command) => cli.register(command));
|
|
30
37
|
}
|
|
31
38
|
}
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAmB;AAEnB,yCAAuC;AAGvC,+CAAyC;AAEzC,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAEtC,MAAM,OAAO,GAAG,CAAC,GAAQ,EAAE,EAAE;IAC3B,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAChB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA;AACtB,CAAC,CAAA;AAED,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAA;AACxC,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAA;AAEzC,MAAM,GAAG,GAAG,IAAI,eAAG,CAAC;IAClB,WAAW,EAAE,YAAY;IACzB,UAAU,EAAE,YAAY;IACxB,aAAa,EAAE,iBAAO;CACvB,CAAC,CAAA;AA2BM,kBAAG;AAzBX,GAAG,CAAC,QAAQ,CAAC,oBAAQ,CAAC,WAAW,CAAC,CAAA;AAClC,GAAG,CAAC,QAAQ,CAAC,oBAAQ,CAAC,cAAc,CAAC,CAAA;AAErC,MAAM,YAAY,GAAG,GAAG,SAAS,WAAW,CAAA;AAC5C,KAAK,MAAM,aAAa,IAAI,YAAE,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE;IACxD,MAAM,mBAAmB,GACvB,OAAO,CAAC,GAAG,CAAC,wBAAwB,KAAK,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,wBAAwB,KAAK,MAAM,CAAA;IACjG,IAAI,aAAa,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,mBAAmB,EAAE;QACjE,SAAQ;KACT;IACD,MAAM,WAAW,GAAG,GAAG,YAAY,IAAI,aAAa,EAAE,CAAA;IACtD,IAAI,YAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,WAAW,EAAE,EAAE;QAC1C,8DAA8D;QAC9D,CAAC;QAAC,OAAO,CAAC,GAAG,WAAW,MAAM,CAAoB,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAA;KAC/F;CACF;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE;IAC3B,KAAK,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;QACtC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAA;CACH"}
|
|
@@ -6,20 +6,24 @@ import { Command } from 'clipanion';
|
|
|
6
6
|
import { CloudRunLog } from './interfaces';
|
|
7
7
|
export declare const MAX_LOGS = 1000;
|
|
8
8
|
export declare class CloudRunFlareCommand extends Command {
|
|
9
|
+
static paths: string[][];
|
|
10
|
+
static usage: import("clipanion").Usage;
|
|
9
11
|
private isDryRun;
|
|
10
12
|
private withLogs;
|
|
11
|
-
private service
|
|
12
|
-
private project
|
|
13
|
-
private region
|
|
14
|
-
private caseId
|
|
15
|
-
private email
|
|
13
|
+
private service;
|
|
14
|
+
private project;
|
|
15
|
+
private region;
|
|
16
|
+
private caseId;
|
|
17
|
+
private email;
|
|
18
|
+
private start;
|
|
19
|
+
private end;
|
|
16
20
|
private apiKey?;
|
|
17
21
|
/**
|
|
18
22
|
* Entry point for the `cloud-run flare` command.
|
|
19
23
|
* Gathers Cloud Run service configuration and sends it to Datadog.
|
|
20
24
|
* @returns 0 if the command ran successfully, 1 otherwise.
|
|
21
25
|
*/
|
|
22
|
-
execute(): Promise<
|
|
26
|
+
execute(): Promise<0 | 1>;
|
|
23
27
|
}
|
|
24
28
|
/**
|
|
25
29
|
* Check if the user is authenticated with GCP.
|
|
@@ -43,18 +47,45 @@ export declare const getCloudRunServiceConfig: (runClient: ServicesClient, servi
|
|
|
43
47
|
* @returns masked config
|
|
44
48
|
*/
|
|
45
49
|
export declare const maskConfig: (config: any) => IService;
|
|
50
|
+
/**
|
|
51
|
+
* Summarizes the Cloud Run config as to not flood the terminal
|
|
52
|
+
* @param config
|
|
53
|
+
* @returns a summarized config
|
|
54
|
+
*/
|
|
55
|
+
export declare const summarizeConfig: (config: IService) => any;
|
|
46
56
|
/**
|
|
47
57
|
* Gets recent logs
|
|
48
58
|
* @param logClient Logging client
|
|
49
59
|
* @param serviceId
|
|
50
60
|
* @param location
|
|
61
|
+
* @param startMillis start time in milliseconds or undefined if no start time is specified
|
|
62
|
+
* @param endMillis end time in milliseconds or undefined if no end time is specified
|
|
51
63
|
* @param severityFilter if included, adds the string to the filter
|
|
52
64
|
* @returns array of logs as CloudRunLog interfaces
|
|
53
65
|
*/
|
|
54
|
-
export declare const getLogs: (logClient: Logging, serviceId: string, location: string, severityFilter?: string
|
|
66
|
+
export declare const getLogs: (logClient: Logging, serviceId: string, location: string, startMillis?: number, endMillis?: number, severityFilter?: string) => Promise<CloudRunLog[]>;
|
|
55
67
|
/**
|
|
56
68
|
* Save logs in a CSV format
|
|
57
69
|
* @param logs array of logs stored as CloudRunLog interfaces
|
|
58
70
|
* @param filePath path to save the CSV file
|
|
59
71
|
*/
|
|
60
72
|
export declare const saveLogsFile: (logs: CloudRunLog[], filePath: string) => void;
|
|
73
|
+
/**
|
|
74
|
+
* Gets recent revisions for a cloud-run service
|
|
75
|
+
* @param service
|
|
76
|
+
* @param location
|
|
77
|
+
* @param project
|
|
78
|
+
* @returns a string array of recent revisions and their deployment timestamp
|
|
79
|
+
*/
|
|
80
|
+
export declare const getRecentRevisions: (service: string, location: string, project: string) => Promise<string[]>;
|
|
81
|
+
/**
|
|
82
|
+
* Generate the insights file
|
|
83
|
+
* @param insightsFilePath path to the insights file
|
|
84
|
+
* @param isDryRun whether or not this is a dry run
|
|
85
|
+
* @param config Cloud run service configuration
|
|
86
|
+
* @param service
|
|
87
|
+
* @param location
|
|
88
|
+
* @param project
|
|
89
|
+
* @param revisions a string array of recent revisions
|
|
90
|
+
*/
|
|
91
|
+
export declare const generateInsightsFile: (insightsFilePath: string, isDryRun: boolean, config: IService, service: string, location: string, project: string, revisions: string[]) => void;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -31,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
31
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
36
|
};
|
|
33
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
exports.saveLogsFile = exports.getLogs = exports.maskConfig = exports.getCloudRunServiceConfig = exports.checkAuthentication = exports.CloudRunFlareCommand = exports.MAX_LOGS = void 0;
|
|
38
|
+
exports.generateInsightsFile = exports.getRecentRevisions = exports.saveLogsFile = exports.getLogs = exports.summarizeConfig = exports.maskConfig = exports.getCloudRunServiceConfig = exports.checkAuthentication = exports.CloudRunFlareCommand = exports.MAX_LOGS = void 0;
|
|
35
39
|
const fs_1 = __importDefault(require("fs"));
|
|
36
40
|
const path_1 = __importDefault(require("path"));
|
|
37
41
|
const process_1 = __importDefault(require("process"));
|
|
@@ -46,15 +50,20 @@ const flare_1 = require("../../helpers/flare");
|
|
|
46
50
|
const fs_2 = require("../../helpers/fs");
|
|
47
51
|
const prompt_1 = require("../../helpers/prompt");
|
|
48
52
|
const helpersRenderer = __importStar(require("../../helpers/renderer"));
|
|
53
|
+
const renderer_1 = require("../../helpers/renderer");
|
|
49
54
|
const utils_1 = require("../../helpers/utils");
|
|
55
|
+
const version_1 = require("../../helpers/version");
|
|
56
|
+
const flare_2 = require("../lambda/flare");
|
|
50
57
|
const constants_2 = require("./constants");
|
|
51
|
-
const
|
|
58
|
+
const renderer_2 = require("./renderer");
|
|
52
59
|
const SERVICE_CONFIG_FILE_NAME = 'service_config.json';
|
|
53
|
-
const FLARE_ZIP_FILE_NAME = '
|
|
60
|
+
const FLARE_ZIP_FILE_NAME = 'cloud-run-flare-output.zip';
|
|
54
61
|
const ALL_LOGS_FILE_NAME = 'all_logs.csv';
|
|
55
62
|
const WARNING_LOGS_FILE_NAME = 'warning_logs.csv';
|
|
56
63
|
const ERRORS_LOGS_FILE_NAME = 'error_logs.csv';
|
|
57
64
|
const DEBUG_LOGS_FILE_NAME = 'debug_logs.csv';
|
|
65
|
+
// What's the maximum number of revisions we want to include? Too many revisions will flood the INSIGHTS.md file
|
|
66
|
+
const MAX_REVISIONS = 10;
|
|
58
67
|
// Must be in range 0 - 1000. If more logs are needed, pagination must be implemented
|
|
59
68
|
exports.MAX_LOGS = 1000;
|
|
60
69
|
// How old the logs can be in minutes. Skip older logs
|
|
@@ -70,8 +79,15 @@ const LOG_CONFIGS = [
|
|
|
70
79
|
class CloudRunFlareCommand extends clipanion_1.Command {
|
|
71
80
|
constructor() {
|
|
72
81
|
super(...arguments);
|
|
73
|
-
this.isDryRun = false;
|
|
74
|
-
this.withLogs = false;
|
|
82
|
+
this.isDryRun = clipanion_1.Option.Boolean('-d,--dry,--dry-run', false);
|
|
83
|
+
this.withLogs = clipanion_1.Option.Boolean('--with-logs', false);
|
|
84
|
+
this.service = clipanion_1.Option.String('-s,--service');
|
|
85
|
+
this.project = clipanion_1.Option.String('-p,--project');
|
|
86
|
+
this.region = clipanion_1.Option.String('-r,--region,-l,--location');
|
|
87
|
+
this.caseId = clipanion_1.Option.String('-c,--case-id');
|
|
88
|
+
this.email = clipanion_1.Option.String('-e,--email');
|
|
89
|
+
this.start = clipanion_1.Option.String('--start');
|
|
90
|
+
this.end = clipanion_1.Option.String('--end');
|
|
75
91
|
}
|
|
76
92
|
/**
|
|
77
93
|
* Entry point for the `cloud-run flare` command.
|
|
@@ -108,6 +124,18 @@ class CloudRunFlareCommand extends clipanion_1.Command {
|
|
|
108
124
|
if (this.email === undefined) {
|
|
109
125
|
errorMessages.push(helpersRenderer.renderError('No email specified. [-e,--email]'));
|
|
110
126
|
}
|
|
127
|
+
// Validate start/end flags if both are specified
|
|
128
|
+
let startMillis;
|
|
129
|
+
let endMillis;
|
|
130
|
+
try {
|
|
131
|
+
;
|
|
132
|
+
[startMillis, endMillis] = (0, flare_1.validateStartEndFlags)(this.start, this.end);
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
if (err instanceof Error) {
|
|
136
|
+
errorMessages.push(helpersRenderer.renderError(err.message));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
111
139
|
// If there are errors, print them and exit
|
|
112
140
|
if (errorMessages.length > 0) {
|
|
113
141
|
for (const message of errorMessages) {
|
|
@@ -117,9 +145,9 @@ class CloudRunFlareCommand extends clipanion_1.Command {
|
|
|
117
145
|
}
|
|
118
146
|
// Verify GCP credentials
|
|
119
147
|
this.context.stdout.write(chalk_1.default.bold('\n🔑 Verifying GCP credentials...\n'));
|
|
120
|
-
const authenticated = yield exports.checkAuthentication();
|
|
148
|
+
const authenticated = yield (0, exports.checkAuthentication)();
|
|
121
149
|
if (!authenticated) {
|
|
122
|
-
this.context.stderr.write(
|
|
150
|
+
this.context.stderr.write((0, renderer_2.renderAuthenticationInstructions)());
|
|
123
151
|
return 1;
|
|
124
152
|
}
|
|
125
153
|
this.context.stdout.write('GCP credentials verified!\n');
|
|
@@ -128,7 +156,7 @@ class CloudRunFlareCommand extends clipanion_1.Command {
|
|
|
128
156
|
const runClient = new run_1.ServicesClient();
|
|
129
157
|
let config;
|
|
130
158
|
try {
|
|
131
|
-
config = yield exports.getCloudRunServiceConfig(runClient, this.service, this.project, this.region);
|
|
159
|
+
config = yield (0, exports.getCloudRunServiceConfig)(runClient, this.service, this.project, this.region);
|
|
132
160
|
}
|
|
133
161
|
catch (err) {
|
|
134
162
|
if (err instanceof Error) {
|
|
@@ -136,11 +164,69 @@ class CloudRunFlareCommand extends clipanion_1.Command {
|
|
|
136
164
|
}
|
|
137
165
|
return 1;
|
|
138
166
|
}
|
|
139
|
-
config = exports.maskConfig(config);
|
|
167
|
+
config = (0, exports.maskConfig)(config);
|
|
168
|
+
const summarizedConfig = (0, exports.summarizeConfig)(config);
|
|
140
169
|
// 10 is the depth when inspecting the config file. Cloud-run configs have high depth, so
|
|
141
170
|
// we must raise the depth from the default depth of 2.
|
|
142
|
-
const
|
|
143
|
-
this.context.stdout.write(`\n${
|
|
171
|
+
const summarizedConfigStr = util_1.default.inspect(summarizedConfig, false, 10, true);
|
|
172
|
+
this.context.stdout.write(`\n${summarizedConfigStr}\n`);
|
|
173
|
+
this.context.stdout.write(chalk_1.default.italic(`(This is a summary of the configuration. The full configuration will be saved in "${SERVICE_CONFIG_FILE_NAME}".)\n`));
|
|
174
|
+
// Get project files
|
|
175
|
+
this.context.stdout.write(chalk_1.default.bold('\n📁 Searching for project files in current directory...\n'));
|
|
176
|
+
const projectFilePaths = yield (0, flare_1.getProjectFiles)(constants_1.FLARE_PROJECT_FILES);
|
|
177
|
+
this.context.stdout.write((0, renderer_1.renderProjectFiles)(projectFilePaths));
|
|
178
|
+
// Additional files
|
|
179
|
+
this.context.stdout.write('\n');
|
|
180
|
+
const additionalFilePaths = new Set();
|
|
181
|
+
let confirmAdditionalFiles;
|
|
182
|
+
try {
|
|
183
|
+
confirmAdditionalFiles = yield (0, prompt_1.requestConfirmation)('Do you want to specify any additional files to flare?', false);
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
if (err instanceof Error) {
|
|
187
|
+
this.context.stderr.write(helpersRenderer.renderError(err.message));
|
|
188
|
+
}
|
|
189
|
+
return 1;
|
|
190
|
+
}
|
|
191
|
+
while (confirmAdditionalFiles) {
|
|
192
|
+
this.context.stdout.write('\n');
|
|
193
|
+
let filePath;
|
|
194
|
+
try {
|
|
195
|
+
filePath = yield (0, prompt_1.requestFilePath)();
|
|
196
|
+
}
|
|
197
|
+
catch (err) {
|
|
198
|
+
if (err instanceof Error) {
|
|
199
|
+
this.context.stderr.write(helpersRenderer.renderError(err.message));
|
|
200
|
+
}
|
|
201
|
+
return 1;
|
|
202
|
+
}
|
|
203
|
+
if (filePath === '') {
|
|
204
|
+
this.context.stdout.write((0, renderer_1.renderAdditionalFiles)(additionalFilePaths));
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
try {
|
|
208
|
+
filePath = (0, flare_1.validateFilePath)(filePath, projectFilePaths, additionalFilePaths);
|
|
209
|
+
additionalFilePaths.add(filePath);
|
|
210
|
+
const fileName = path_1.default.basename(filePath);
|
|
211
|
+
this.context.stdout.write(`• Added file '${fileName}'\n`);
|
|
212
|
+
}
|
|
213
|
+
catch (err) {
|
|
214
|
+
if (err instanceof Error) {
|
|
215
|
+
this.context.stderr.write(err.message);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
// Get recent revisions, which will be used to generate insights file
|
|
220
|
+
this.context.stdout.write(chalk_1.default.bold('\n🌧 Fetching recent revisions...\n'));
|
|
221
|
+
let revisions = [];
|
|
222
|
+
try {
|
|
223
|
+
revisions = yield (0, exports.getRecentRevisions)(this.service, this.region, this.project);
|
|
224
|
+
this.context.stdout.write(`• Found ${revisions.length} revisions\n`);
|
|
225
|
+
}
|
|
226
|
+
catch (err) {
|
|
227
|
+
const errorDetails = err instanceof Error ? err.message : '';
|
|
228
|
+
this.context.stdout.write(helpersRenderer.renderSoftWarning(`Unable to fetch recent revisions. ${errorDetails}`));
|
|
229
|
+
}
|
|
144
230
|
// Get logs
|
|
145
231
|
const logFileMappings = new Map();
|
|
146
232
|
if (this.withLogs) {
|
|
@@ -148,7 +234,7 @@ class CloudRunFlareCommand extends clipanion_1.Command {
|
|
|
148
234
|
const logClient = new logging_1.Logging({ projectId: this.project });
|
|
149
235
|
for (const logConfig of LOG_CONFIGS) {
|
|
150
236
|
try {
|
|
151
|
-
const logs = yield exports.getLogs(logClient, this.service, this.region, logConfig.severityFilter);
|
|
237
|
+
const logs = yield (0, exports.getLogs)(logClient, this.service, this.region, startMillis, endMillis, logConfig.severityFilter);
|
|
152
238
|
if (logs.length === 0) {
|
|
153
239
|
this.context.stdout.write(`• No ${logConfig.type} logs were found\n`);
|
|
154
240
|
}
|
|
@@ -167,35 +253,68 @@ class CloudRunFlareCommand extends clipanion_1.Command {
|
|
|
167
253
|
// Create folders
|
|
168
254
|
const rootFolderPath = path_1.default.join(process_1.default.cwd(), constants_1.FLARE_OUTPUT_DIRECTORY);
|
|
169
255
|
const logsFolderPath = path_1.default.join(rootFolderPath, constants_1.LOGS_DIRECTORY);
|
|
256
|
+
const projectFilesFolderPath = path_1.default.join(rootFolderPath, constants_1.PROJECT_FILES_DIRECTORY);
|
|
257
|
+
const additionalFilesFolderPath = path_1.default.join(rootFolderPath, constants_1.ADDITIONAL_FILES_DIRECTORY);
|
|
170
258
|
this.context.stdout.write(chalk_1.default.bold(`\n💾 Saving files to ${rootFolderPath}...\n`));
|
|
171
259
|
if (fs_1.default.existsSync(rootFolderPath)) {
|
|
172
|
-
fs_2.deleteFolder(rootFolderPath);
|
|
260
|
+
(0, fs_2.deleteFolder)(rootFolderPath);
|
|
173
261
|
}
|
|
174
262
|
const subFolders = [];
|
|
175
263
|
if (logFileMappings.size > 0) {
|
|
176
264
|
subFolders.push(logsFolderPath);
|
|
177
265
|
}
|
|
178
|
-
|
|
266
|
+
if (projectFilePaths.size > 0) {
|
|
267
|
+
subFolders.push(projectFilesFolderPath);
|
|
268
|
+
}
|
|
269
|
+
if (additionalFilePaths.size > 0) {
|
|
270
|
+
subFolders.push(additionalFilesFolderPath);
|
|
271
|
+
}
|
|
272
|
+
(0, fs_2.createDirectories)(rootFolderPath, subFolders);
|
|
179
273
|
// Write config file
|
|
180
274
|
const configFilePath = path_1.default.join(rootFolderPath, SERVICE_CONFIG_FILE_NAME);
|
|
181
|
-
fs_2.writeFile(configFilePath, JSON.stringify(config, undefined, 2));
|
|
275
|
+
(0, fs_2.writeFile)(configFilePath, JSON.stringify(config, undefined, 2));
|
|
182
276
|
this.context.stdout.write(`• Saved function config to ./${SERVICE_CONFIG_FILE_NAME}\n`);
|
|
183
277
|
// Write logs
|
|
184
278
|
for (const [fileName, logs] of logFileMappings) {
|
|
185
279
|
const logFilePath = path_1.default.join(logsFolderPath, fileName);
|
|
186
|
-
exports.saveLogsFile(logs, logFilePath);
|
|
280
|
+
(0, exports.saveLogsFile)(logs, logFilePath);
|
|
187
281
|
this.context.stdout.write(`• Saved logs to ./${constants_1.LOGS_DIRECTORY}/${fileName}\n`);
|
|
188
282
|
}
|
|
283
|
+
// Write project files
|
|
284
|
+
for (const filePath of projectFilePaths) {
|
|
285
|
+
const fileName = path_1.default.basename(filePath);
|
|
286
|
+
const newFilePath = path_1.default.join(projectFilesFolderPath, fileName);
|
|
287
|
+
fs_1.default.copyFileSync(filePath, newFilePath);
|
|
288
|
+
this.context.stdout.write(`• Copied ${fileName} to ./${constants_1.PROJECT_FILES_DIRECTORY}/${fileName}\n`);
|
|
289
|
+
}
|
|
290
|
+
// Write additional files
|
|
291
|
+
const additionalFilesMap = (0, flare_2.getUniqueFileNames)(additionalFilePaths);
|
|
292
|
+
for (const [originalFilePath, newFileName] of additionalFilesMap) {
|
|
293
|
+
const originalFileName = path_1.default.basename(originalFilePath);
|
|
294
|
+
const newFilePath = path_1.default.join(additionalFilesFolderPath, newFileName);
|
|
295
|
+
fs_1.default.copyFileSync(originalFilePath, newFilePath);
|
|
296
|
+
this.context.stdout.write(`• Copied ${originalFileName} to ./${constants_1.ADDITIONAL_FILES_DIRECTORY}/${newFileName}\n`);
|
|
297
|
+
}
|
|
298
|
+
// Write insights file
|
|
299
|
+
try {
|
|
300
|
+
const insightsFilePath = path_1.default.join(rootFolderPath, constants_1.INSIGHTS_FILE_NAME);
|
|
301
|
+
(0, exports.generateInsightsFile)(insightsFilePath, this.isDryRun, config, this.service, this.region, this.project, revisions);
|
|
302
|
+
this.context.stdout.write(`• Saved insights file to ./${constants_1.INSIGHTS_FILE_NAME}\n`);
|
|
303
|
+
}
|
|
304
|
+
catch (err) {
|
|
305
|
+
const errorDetails = err instanceof Error ? err.message : '';
|
|
306
|
+
this.context.stdout.write(helpersRenderer.renderSoftWarning(`Unable to create INSIGHTS.md file. ${errorDetails}`));
|
|
307
|
+
}
|
|
189
308
|
// Exit if dry run
|
|
190
309
|
const outputMsg = `\nℹ️ Your output files are located at: ${rootFolderPath}\n\n`;
|
|
191
310
|
if (this.isDryRun) {
|
|
192
|
-
this.context.stdout.write('\n🚫 The flare files were not sent
|
|
311
|
+
this.context.stdout.write('\n🚫 The flare files were not sent because the command was executed in dry run mode.');
|
|
193
312
|
this.context.stdout.write(outputMsg);
|
|
194
313
|
return 0;
|
|
195
314
|
}
|
|
196
315
|
// Confirm before sending
|
|
197
316
|
this.context.stdout.write('\n');
|
|
198
|
-
const confirmSendFiles = yield prompt_1.requestConfirmation('Are you sure you want to send the flare file to Datadog Support?', false);
|
|
317
|
+
const confirmSendFiles = yield (0, prompt_1.requestConfirmation)('Are you sure you want to send the flare file to Datadog Support?', false);
|
|
199
318
|
if (!confirmSendFiles) {
|
|
200
319
|
this.context.stdout.write('\n🚫 The flare files were not sent based on your selection.');
|
|
201
320
|
this.context.stdout.write(outputMsg);
|
|
@@ -203,13 +322,13 @@ class CloudRunFlareCommand extends clipanion_1.Command {
|
|
|
203
322
|
}
|
|
204
323
|
// Zip folder
|
|
205
324
|
const zipPath = path_1.default.join(rootFolderPath, FLARE_ZIP_FILE_NAME);
|
|
206
|
-
yield fs_2.zipContents(rootFolderPath, zipPath);
|
|
325
|
+
yield (0, fs_2.zipContents)(rootFolderPath, zipPath);
|
|
207
326
|
// Send to Datadog
|
|
208
327
|
this.context.stdout.write(chalk_1.default.bold('\n🚀 Sending to Datadog Support...\n'));
|
|
209
|
-
yield flare_1.sendToDatadog(zipPath, this.caseId, this.email, this.apiKey, rootFolderPath);
|
|
328
|
+
yield (0, flare_1.sendToDatadog)(zipPath, this.caseId, this.email, this.apiKey, rootFolderPath);
|
|
210
329
|
this.context.stdout.write(chalk_1.default.bold('\n✅ Successfully sent flare file to Datadog Support!\n'));
|
|
211
330
|
// Delete contents
|
|
212
|
-
fs_2.deleteFolder(rootFolderPath);
|
|
331
|
+
(0, fs_2.deleteFolder)(rootFolderPath);
|
|
213
332
|
}
|
|
214
333
|
catch (err) {
|
|
215
334
|
if (err instanceof Error) {
|
|
@@ -222,6 +341,11 @@ class CloudRunFlareCommand extends clipanion_1.Command {
|
|
|
222
341
|
}
|
|
223
342
|
}
|
|
224
343
|
exports.CloudRunFlareCommand = CloudRunFlareCommand;
|
|
344
|
+
CloudRunFlareCommand.paths = [['cloud-run', 'flare']];
|
|
345
|
+
CloudRunFlareCommand.usage = clipanion_1.Command.Usage({
|
|
346
|
+
category: 'Serverless',
|
|
347
|
+
description: 'Gather Cloud Run service configuration and sends it to Datadog.',
|
|
348
|
+
});
|
|
225
349
|
/**
|
|
226
350
|
* Check if the user is authenticated with GCP.
|
|
227
351
|
* @returns true if the user is authenticated, false otherwise
|
|
@@ -277,32 +401,66 @@ const maskConfig = (config) => {
|
|
|
277
401
|
continue;
|
|
278
402
|
}
|
|
279
403
|
if (!constants_2.SKIP_MASKING_CLOUDRUN_ENV_VARS.has(name)) {
|
|
280
|
-
envVar.value = utils_1.maskString(val);
|
|
404
|
+
envVar.value = (0, utils_1.maskString)(val);
|
|
281
405
|
}
|
|
282
406
|
}
|
|
283
407
|
}
|
|
284
408
|
return configCopy;
|
|
285
409
|
};
|
|
286
410
|
exports.maskConfig = maskConfig;
|
|
411
|
+
/**
|
|
412
|
+
* Summarizes the Cloud Run config as to not flood the terminal
|
|
413
|
+
* @param config
|
|
414
|
+
* @returns a summarized config
|
|
415
|
+
*/
|
|
416
|
+
const summarizeConfig = (config) => {
|
|
417
|
+
var _a;
|
|
418
|
+
const summarizedConfig = {};
|
|
419
|
+
summarizedConfig.name = config.name;
|
|
420
|
+
summarizedConfig.uid = config.uid;
|
|
421
|
+
summarizedConfig.uri = config.uri;
|
|
422
|
+
// Get env vars and image for each containers
|
|
423
|
+
const template = config.template;
|
|
424
|
+
if (template) {
|
|
425
|
+
const summarizedContainers = [];
|
|
426
|
+
const containers = (_a = template.containers) !== null && _a !== void 0 ? _a : [];
|
|
427
|
+
containers.forEach((container) => {
|
|
428
|
+
const summarizedContainer = {};
|
|
429
|
+
summarizedContainer.env = container.env;
|
|
430
|
+
summarizedContainer.image = container.image;
|
|
431
|
+
summarizedContainers.push(summarizedContainer);
|
|
432
|
+
});
|
|
433
|
+
summarizedConfig.containers = summarizedContainers;
|
|
434
|
+
}
|
|
435
|
+
return summarizedConfig;
|
|
436
|
+
};
|
|
437
|
+
exports.summarizeConfig = summarizeConfig;
|
|
287
438
|
/**
|
|
288
439
|
* Gets recent logs
|
|
289
440
|
* @param logClient Logging client
|
|
290
441
|
* @param serviceId
|
|
291
442
|
* @param location
|
|
443
|
+
* @param startMillis start time in milliseconds or undefined if no start time is specified
|
|
444
|
+
* @param endMillis end time in milliseconds or undefined if no end time is specified
|
|
292
445
|
* @param severityFilter if included, adds the string to the filter
|
|
293
446
|
* @returns array of logs as CloudRunLog interfaces
|
|
294
447
|
*/
|
|
295
|
-
const getLogs = (logClient, serviceId, location, severityFilter) => __awaiter(void 0, void 0, void 0, function* () {
|
|
448
|
+
const getLogs = (logClient, serviceId, location, startMillis, endMillis, severityFilter) => __awaiter(void 0, void 0, void 0, function* () {
|
|
296
449
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
297
450
|
const logs = [];
|
|
298
|
-
//
|
|
451
|
+
// Default to the recent logs using MAX_LOG_AGE_MINUTES
|
|
299
452
|
const date = new Date();
|
|
300
453
|
date.setMinutes(date.getMinutes() - MAX_LOG_AGE_MINUTES);
|
|
301
|
-
|
|
454
|
+
let startDate = date.toISOString();
|
|
455
|
+
let endDate = new Date().toISOString(); // Current time
|
|
456
|
+
// If startMillis and endMillis are provided, use them to set the date range
|
|
457
|
+
if (startMillis && endMillis) {
|
|
458
|
+
startDate = new Date(startMillis).toISOString();
|
|
459
|
+
endDate = new Date(endMillis).toISOString();
|
|
460
|
+
}
|
|
302
461
|
// Query options
|
|
303
|
-
let filter = `resource.labels.service_name="${serviceId}" AND resource.labels.location="${location}" AND timestamp>="${
|
|
304
|
-
// We only want to
|
|
305
|
-
// We also only want to include logs with a textPayload or logs that were an HTTP request.
|
|
462
|
+
let filter = `resource.labels.service_name="${serviceId}" AND resource.labels.location="${location}" AND timestamp>="${startDate}" AND timestamp<="${endDate}" AND (textPayload:* OR httpRequest:*)`;
|
|
463
|
+
// We only want to include logs with a textPayload or logs that were an HTTP request.
|
|
306
464
|
// Any other logs are just audit logs which are spammy and don't have any relevant information.
|
|
307
465
|
filter += severityFilter !== null && severityFilter !== void 0 ? severityFilter : '';
|
|
308
466
|
const options = {
|
|
@@ -324,7 +482,7 @@ const getLogs = (logClient, serviceId, location, severityFilter) => __awaiter(vo
|
|
|
324
482
|
if (latency) {
|
|
325
483
|
ms = (Number(latency.seconds) * 1000 + Math.round(Number(latency.nanos) / 1000000)).toString();
|
|
326
484
|
}
|
|
327
|
-
const bytes = utils_1.formatBytes(Number(request.responseSize));
|
|
485
|
+
const bytes = (0, utils_1.formatBytes)(Number(request.responseSize));
|
|
328
486
|
const method = (_b = request.requestMethod) !== null && _b !== void 0 ? _b : '';
|
|
329
487
|
const requestUrl = (_c = request.requestUrl) !== null && _c !== void 0 ? _c : '';
|
|
330
488
|
msg += `${method} ${status}. responseSize: ${bytes}. latency: ${ms} ms. requestUrl: ${requestUrl}`;
|
|
@@ -355,15 +513,122 @@ const saveLogsFile = (logs, filePath) => {
|
|
|
355
513
|
rows.push([severity, timestamp, logName, logMessage]);
|
|
356
514
|
});
|
|
357
515
|
const data = rows.join('\n');
|
|
358
|
-
fs_2.writeFile(filePath, data);
|
|
516
|
+
(0, fs_2.writeFile)(filePath, data);
|
|
359
517
|
};
|
|
360
518
|
exports.saveLogsFile = saveLogsFile;
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
519
|
+
/**
|
|
520
|
+
* Gets recent revisions for a cloud-run service
|
|
521
|
+
* @param service
|
|
522
|
+
* @param location
|
|
523
|
+
* @param project
|
|
524
|
+
* @returns a string array of recent revisions and their deployment timestamp
|
|
525
|
+
*/
|
|
526
|
+
const getRecentRevisions = (service, location, project) => __awaiter(void 0, void 0, void 0, function* () {
|
|
527
|
+
var _j;
|
|
528
|
+
const client = new run_1.RevisionsClient();
|
|
529
|
+
const request = {
|
|
530
|
+
parent: client.servicePath(project, location, service),
|
|
531
|
+
};
|
|
532
|
+
// listRevisions() returns a tuple [Revision[], Request, Response],
|
|
533
|
+
// so we index the first element to get the array of revisions
|
|
534
|
+
const revisions = (yield client.listRevisions(request))[0];
|
|
535
|
+
const revisionTimestampStrings = [];
|
|
536
|
+
let counter = 1;
|
|
537
|
+
for (const entry of revisions) {
|
|
538
|
+
const fullName = entry.name;
|
|
539
|
+
const timestamp = entry.createTime;
|
|
540
|
+
if (fullName && timestamp) {
|
|
541
|
+
// Get the revision name
|
|
542
|
+
const nameSplit = fullName.split('/');
|
|
543
|
+
const revisionName = nameSplit[nameSplit.length - 1];
|
|
544
|
+
// Format the timestamp by first converting seconds/nanos to milliseconds, then using `new Date()`
|
|
545
|
+
const milliseconds = Number((_j = timestamp.seconds) !== null && _j !== void 0 ? _j : 0) * 1000;
|
|
546
|
+
const timestampString = new Date(milliseconds).toISOString().replace('T', ' ').replace('Z', '').slice(0, -4); // Chop off the milliseconds, which will always be .000
|
|
547
|
+
revisionTimestampStrings.push(`\`${revisionName}\` Deployed on ${timestampString}`);
|
|
548
|
+
}
|
|
549
|
+
// Stop iterating once we reach MAX_REVISIONS
|
|
550
|
+
counter += 1;
|
|
551
|
+
if (counter > MAX_REVISIONS) {
|
|
552
|
+
break;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return revisionTimestampStrings;
|
|
556
|
+
});
|
|
557
|
+
exports.getRecentRevisions = getRecentRevisions;
|
|
558
|
+
/**
|
|
559
|
+
* Generate the insights file
|
|
560
|
+
* @param insightsFilePath path to the insights file
|
|
561
|
+
* @param isDryRun whether or not this is a dry run
|
|
562
|
+
* @param config Cloud run service configuration
|
|
563
|
+
* @param service
|
|
564
|
+
* @param location
|
|
565
|
+
* @param project
|
|
566
|
+
* @param revisions a string array of recent revisions
|
|
567
|
+
*/
|
|
568
|
+
const generateInsightsFile = (insightsFilePath, isDryRun, config, service, location, project, revisions) => {
|
|
569
|
+
var _a, _b, _c, _d, _e, _f;
|
|
570
|
+
const lines = [];
|
|
571
|
+
// Header
|
|
572
|
+
lines.push('# Flare Insights');
|
|
573
|
+
lines.push('\n_Autogenerated file from `cloud-run flare`_ ');
|
|
574
|
+
if (isDryRun) {
|
|
575
|
+
lines.push('_This command was run in dry mode._');
|
|
576
|
+
}
|
|
577
|
+
// Cloud Run Service Configuration
|
|
578
|
+
lines.push('\n## Cloud Run Service Configuration');
|
|
579
|
+
lines.push(`**Service Name**: \`${service}\` `);
|
|
580
|
+
lines.push(`**Location**: \`${location}\` `);
|
|
581
|
+
lines.push(`**Project**: \`${project}\` `);
|
|
582
|
+
const description = config.description;
|
|
583
|
+
if (description && description.length > 0) {
|
|
584
|
+
lines.push(`**Description**: \`${description}\` `);
|
|
585
|
+
}
|
|
586
|
+
lines.push(`**URI**: \`${(_a = config.uri) !== null && _a !== void 0 ? _a : ''}\``);
|
|
587
|
+
// Environment variables
|
|
588
|
+
const containers = (_c = (_b = config.template) === null || _b === void 0 ? void 0 : _b.containers) !== null && _c !== void 0 ? _c : [];
|
|
589
|
+
for (const container of containers) {
|
|
590
|
+
// We want to separate environment variables by container if there are multiple containers
|
|
591
|
+
// We can use the container image to uniquely identify each container
|
|
592
|
+
lines.push(`\n**Environment Variables** (${(_d = container.image) !== null && _d !== void 0 ? _d : 'unknown image'}):`);
|
|
593
|
+
const envVars = new Map();
|
|
594
|
+
for (const envVar of (_e = container.env) !== null && _e !== void 0 ? _e : []) {
|
|
595
|
+
const name = envVar.name;
|
|
596
|
+
const value = envVar.value;
|
|
597
|
+
if (name && value) {
|
|
598
|
+
envVars.set(name, value);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
if (envVars.size === 0) {
|
|
602
|
+
lines.push('- No environment variables found.');
|
|
603
|
+
}
|
|
604
|
+
for (const [key, value] of envVars) {
|
|
605
|
+
lines.push(`- \`${key}\`: \`${value}\``);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
// Labels
|
|
609
|
+
lines.push('\n**Labels**:');
|
|
610
|
+
const labels = (_f = config.labels) !== null && _f !== void 0 ? _f : {};
|
|
611
|
+
const entries = Object.entries(labels);
|
|
612
|
+
if (entries.length === 0) {
|
|
613
|
+
lines.push('- No labels found.');
|
|
614
|
+
}
|
|
615
|
+
for (const [key, value] of entries) {
|
|
616
|
+
lines.push(`- \`${key}\`: \`${value}\``);
|
|
617
|
+
}
|
|
618
|
+
// Recent revisions
|
|
619
|
+
if (revisions.length > 0) {
|
|
620
|
+
lines.push('\n**Recent Revisions**:');
|
|
621
|
+
for (const revision of revisions) {
|
|
622
|
+
lines.push(`- ${revision}`);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
// CLI Insights
|
|
626
|
+
lines.push('\n ## CLI');
|
|
627
|
+
lines.push(`**Run Location**: \`${process_1.default.cwd()}\` `);
|
|
628
|
+
lines.push(`**CLI Version**: \`${version_1.version}\` `);
|
|
629
|
+
const timeString = new Date().toISOString().replace('T', ' ').replace('Z', '') + ' UTC';
|
|
630
|
+
lines.push(`**Timestamp**: \`${timeString}\` `);
|
|
631
|
+
(0, fs_2.writeFile)(insightsFilePath, lines.join('\n'));
|
|
632
|
+
};
|
|
633
|
+
exports.generateInsightsFile = generateInsightsFile;
|
|
369
634
|
//# sourceMappingURL=flare.js.map
|