@elastic/synthetics 1.0.0-beta.8 → 1.0.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/README.md +5 -4
- package/dist/cli.js +139 -165
- package/dist/cli.js.map +1 -1
- package/dist/common_types.d.ts +158 -34
- package/dist/common_types.d.ts.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +7 -6
- package/dist/config.js.map +1 -1
- package/dist/core/browser-service.d.ts +1 -1
- package/dist/core/browser-service.d.ts.map +1 -1
- package/dist/core/browser-service.js +7 -6
- package/dist/core/browser-service.js.map +1 -1
- package/dist/core/expect.d.ts +25 -25
- package/dist/core/expect.d.ts.map +1 -1
- package/dist/core/expect.js.map +1 -1
- package/dist/core/gatherer.d.ts +5 -8
- package/dist/core/gatherer.d.ts.map +1 -1
- package/dist/core/gatherer.js +75 -17
- package/dist/core/gatherer.js.map +1 -1
- package/dist/core/index.d.ts +5 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +23 -11
- package/dist/core/index.js.map +1 -1
- package/dist/core/logger.d.ts +0 -1
- package/dist/core/logger.d.ts.map +1 -1
- package/dist/core/logger.js +10 -17
- package/dist/core/logger.js.map +1 -1
- package/dist/core/runner.d.ts +12 -63
- package/dist/core/runner.d.ts.map +1 -1
- package/dist/core/runner.js +159 -92
- package/dist/core/runner.js.map +1 -1
- package/dist/core/transform.d.ts +37 -0
- package/dist/core/transform.d.ts.map +1 -0
- package/dist/core/transform.js +148 -0
- package/dist/core/transform.js.map +1 -0
- package/dist/dsl/index.js +5 -1
- package/dist/dsl/index.js.map +1 -1
- package/dist/dsl/journey.d.ts +9 -7
- package/dist/dsl/journey.d.ts.map +1 -1
- package/dist/dsl/journey.js +32 -39
- package/dist/dsl/journey.js.map +1 -1
- package/dist/dsl/monitor.d.ts +93 -0
- package/dist/dsl/monitor.d.ts.map +1 -0
- package/dist/dsl/monitor.js +110 -0
- package/dist/dsl/monitor.js.map +1 -0
- package/dist/dsl/step.d.ts +3 -2
- package/dist/dsl/step.d.ts.map +1 -1
- package/dist/dsl/step.js +6 -1
- package/dist/dsl/step.js.map +1 -1
- package/dist/formatter/javascript.d.ts +115 -0
- package/dist/formatter/javascript.d.ts.map +1 -0
- package/dist/formatter/javascript.js +331 -0
- package/dist/formatter/javascript.js.map +1 -0
- package/dist/generator/index.d.ts +24 -0
- package/dist/generator/index.d.ts.map +1 -0
- package/dist/generator/index.js +241 -0
- package/dist/generator/index.js.map +1 -0
- package/dist/{reporters/reporter.js → generator/utils.d.ts} +5 -3
- package/dist/generator/utils.d.ts.map +1 -0
- package/dist/generator/utils.js +84 -0
- package/dist/generator/utils.js.map +1 -0
- package/dist/helpers.d.ts +36 -9
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +170 -24
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.ts +5 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -26
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts +34 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +153 -0
- package/dist/loader.js.map +1 -0
- package/dist/locations/index.d.ts +45 -0
- package/dist/locations/index.d.ts.map +1 -0
- package/dist/locations/index.js +83 -0
- package/dist/locations/index.js.map +1 -0
- package/dist/{reporters/reporter.d.ts → locations/public-locations.d.ts} +12 -8
- package/dist/locations/public-locations.d.ts.map +1 -0
- package/dist/locations/public-locations.js +41 -0
- package/dist/locations/public-locations.js.map +1 -0
- package/dist/options.d.ts +42 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +146 -0
- package/dist/options.js.map +1 -0
- package/dist/plugins/browser-console.d.ts +5 -4
- package/dist/plugins/browser-console.d.ts.map +1 -1
- package/dist/plugins/browser-console.js +47 -24
- package/dist/plugins/browser-console.js.map +1 -1
- package/dist/plugins/index.js +5 -1
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/network.d.ts +24 -31
- package/dist/plugins/network.d.ts.map +1 -1
- package/dist/plugins/network.js +226 -229
- package/dist/plugins/network.js.map +1 -1
- package/dist/plugins/performance.d.ts +4 -19
- package/dist/plugins/performance.d.ts.map +1 -1
- package/dist/plugins/performance.js +6 -5
- package/dist/plugins/performance.js.map +1 -1
- package/dist/plugins/plugin-manager.d.ts +9 -5
- package/dist/plugins/plugin-manager.d.ts.map +1 -1
- package/dist/plugins/plugin-manager.js +46 -30
- package/dist/plugins/plugin-manager.js.map +1 -1
- package/dist/plugins/tracing.d.ts +6 -6
- package/dist/plugins/tracing.d.ts.map +1 -1
- package/dist/plugins/tracing.js +13 -7
- package/dist/plugins/tracing.js.map +1 -1
- package/dist/push/bundler.d.ts +35 -0
- package/dist/push/bundler.d.ts.map +1 -0
- package/dist/push/bundler.js +131 -0
- package/dist/push/bundler.js.map +1 -0
- package/dist/push/index.d.ts +10 -0
- package/dist/push/index.d.ts.map +1 -0
- package/dist/push/index.js +235 -0
- package/dist/push/index.js.map +1 -0
- package/dist/push/kibana_api.d.ts +56 -0
- package/dist/push/kibana_api.d.ts.map +1 -0
- package/dist/push/kibana_api.js +135 -0
- package/dist/push/kibana_api.js.map +1 -0
- package/dist/push/monitor.d.ts +55 -0
- package/dist/push/monitor.d.ts.map +1 -0
- package/dist/push/monitor.js +268 -0
- package/dist/push/monitor.js.map +1 -0
- package/dist/{parse_args.d.ts → push/plugin.d.ts} +9 -6
- package/dist/push/plugin.d.ts.map +1 -0
- package/dist/push/plugin.js +66 -0
- package/dist/push/plugin.js.map +1 -0
- package/dist/push/request.d.ts +45 -0
- package/dist/push/request.d.ts.map +1 -0
- package/dist/push/request.js +109 -0
- package/dist/push/request.js.map +1 -0
- package/dist/push/utils.d.ts +31 -0
- package/dist/push/utils.d.ts.map +1 -0
- package/dist/push/utils.js +64 -0
- package/dist/push/utils.js.map +1 -0
- package/dist/reporters/base.d.ts +14 -6
- package/dist/reporters/base.d.ts.map +1 -1
- package/dist/reporters/base.js +58 -50
- package/dist/reporters/base.js.map +1 -1
- package/dist/reporters/index.d.ts +18 -8
- package/dist/reporters/index.d.ts.map +1 -1
- package/dist/reporters/index.js.map +1 -1
- package/dist/reporters/json.d.ts +17 -62
- package/dist/reporters/json.d.ts.map +1 -1
- package/dist/reporters/json.js +147 -177
- package/dist/reporters/json.js.map +1 -1
- package/dist/reporters/junit.d.ts +7 -1
- package/dist/reporters/junit.d.ts.map +1 -1
- package/dist/reporters/junit.js +90 -95
- package/dist/reporters/junit.js.map +1 -1
- package/dist/sdk/lh-trace-processor.d.ts +35 -9
- package/dist/sdk/lh-trace-processor.d.ts.map +1 -1
- package/dist/sdk/lh-trace-processor.js +114 -53
- package/dist/sdk/lh-trace-processor.js.map +1 -1
- package/dist/sdk/trace-metrics.d.ts +4 -4
- package/dist/sdk/trace-metrics.d.ts.map +1 -1
- package/dist/sdk/trace-metrics.js +3 -4
- package/dist/sdk/trace-metrics.js.map +1 -1
- package/dist/sdk/trace-processor.d.ts +11 -3
- package/dist/sdk/trace-processor.d.ts.map +1 -1
- package/dist/sdk/trace-processor.js +17 -9
- package/dist/sdk/trace-processor.js.map +1 -1
- package/package.json +38 -30
- package/src/cli.ts +223 -158
- package/src/common_types.ts +191 -34
- package/src/config.ts +1 -1
- package/src/core/expect.ts +58 -24
- package/src/core/gatherer.ts +92 -25
- package/src/core/index.ts +36 -15
- package/src/core/logger.ts +8 -12
- package/src/core/runner.ts +158 -148
- package/src/core/transform.ts +160 -0
- package/src/dsl/journey.ts +41 -21
- package/src/dsl/monitor.ts +152 -0
- package/src/dsl/step.ts +9 -2
- package/src/formatter/javascript.ts +414 -0
- package/src/generator/index.ts +308 -0
- package/src/generator/utils.ts +84 -0
- package/src/helpers.ts +182 -16
- package/src/index.ts +21 -22
- package/src/loader.ts +171 -0
- package/src/locations/index.ts +95 -0
- package/src/{reporters/reporter.ts → locations/public-locations.ts} +12 -9
- package/src/options.ts +175 -0
- package/src/plugins/browser-console.ts +33 -8
- package/src/plugins/network.ts +266 -284
- package/src/plugins/performance.ts +6 -22
- package/src/plugins/plugin-manager.ts +49 -31
- package/src/plugins/tracing.ts +11 -9
- package/src/push/bundler.ts +112 -0
- package/src/push/index.ts +291 -0
- package/src/push/kibana_api.ts +191 -0
- package/src/push/monitor.ts +307 -0
- package/src/push/plugin.ts +66 -0
- package/src/push/request.ts +141 -0
- package/src/push/utils.ts +77 -0
- package/src/reporters/base.ts +63 -52
- package/src/reporters/index.ts +26 -3
- package/src/reporters/json.ts +181 -201
- package/src/reporters/junit.ts +98 -93
- package/src/sdk/lh-trace-processor.ts +132 -68
- package/src/sdk/trace-metrics.ts +8 -4
- package/src/sdk/trace-processor.ts +28 -13
- package/templates/.github/workflows/run-synthetics.yml +27 -0
- package/templates/README.md +21 -0
- package/templates/journeys/advanced-example-helpers.ts +54 -0
- package/templates/journeys/advanced-example.journey.ts +43 -0
- package/templates/journeys/example.journey.ts +18 -0
- package/templates/lightweight/heartbeat.yml +9 -0
- package/templates/synthetics.config.ts +35 -0
- package/CHANGELOG.md +0 -181
- package/NOTICE.txt +0 -221
- package/dist/parse_args.d.ts.map +0 -1
- package/dist/parse_args.js +0 -98
- package/dist/parse_args.js.map +0 -1
- package/dist/reporters/reporter.d.ts.map +0 -1
- package/dist/reporters/reporter.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1895
- package/src/parse_args.ts +0 -146
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.warnIfThrottled = exports.pushLegacy = exports.catchIncorrectSettings = exports.validateSettings = exports.loadSettings = exports.formatDuplicateError = exports.push = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* MIT License
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2020-present, Elastic NV
|
|
11
|
+
*
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
* in the Software without restriction, including without limitation the rights
|
|
15
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
* furnished to do so, subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in
|
|
20
|
+
* all copies or substantial portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
28
|
+
* THE SOFTWARE.
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
const semver_1 = __importDefault(require("semver"));
|
|
32
|
+
const promises_1 = require("fs/promises");
|
|
33
|
+
const enquirer_1 = require("enquirer");
|
|
34
|
+
const colors_1 = require("kleur/colors");
|
|
35
|
+
const monitor_1 = require("./monitor");
|
|
36
|
+
const monitor_2 = require("../dsl/monitor");
|
|
37
|
+
const helpers_1 = require("../helpers");
|
|
38
|
+
const config_1 = require("../config");
|
|
39
|
+
const kibana_api_1 = require("./kibana_api");
|
|
40
|
+
const utils_1 = require("./utils");
|
|
41
|
+
async function push(monitors, options) {
|
|
42
|
+
const duplicates = trackDuplicates(monitors);
|
|
43
|
+
if (duplicates.size > 0) {
|
|
44
|
+
throw (0, helpers_1.error)(formatDuplicateError(duplicates));
|
|
45
|
+
}
|
|
46
|
+
(0, helpers_1.progress)(`Pushing monitors for project: ${options.id}`);
|
|
47
|
+
const stackVersion = await (0, kibana_api_1.getVersion)(options);
|
|
48
|
+
const isV2 = semver_1.default.satisfies(stackVersion, '>=8.6.0');
|
|
49
|
+
if (!isV2) {
|
|
50
|
+
return await pushLegacy(monitors, options, stackVersion);
|
|
51
|
+
}
|
|
52
|
+
const local = (0, monitor_1.getLocalMonitors)(monitors);
|
|
53
|
+
const { monitors: remote } = await (0, kibana_api_1.bulkGetMonitors)(options);
|
|
54
|
+
const { newIDs, changedIDs, removedIDs, unchangedIDs } = (0, monitor_1.diffMonitors)(local, remote);
|
|
55
|
+
(0, utils_1.logDiff)(newIDs, changedIDs, removedIDs, unchangedIDs);
|
|
56
|
+
const updatedMonitors = new Set([...changedIDs, ...newIDs]);
|
|
57
|
+
if (updatedMonitors.size > 0) {
|
|
58
|
+
const toBundle = monitors.filter(m => updatedMonitors.has(m.config.id));
|
|
59
|
+
(0, helpers_1.progress)(`bundling ${toBundle.length} monitors`);
|
|
60
|
+
const schemas = await (0, monitor_1.buildMonitorSchema)(toBundle, true);
|
|
61
|
+
const chunks = (0, utils_1.getChunks)(schemas, kibana_api_1.CHUNK_SIZE);
|
|
62
|
+
for (const chunk of chunks) {
|
|
63
|
+
await (0, helpers_1.liveProgress)((0, kibana_api_1.bulkPutMonitors)(options, chunk), `creating or updating ${chunk.length} monitors`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (removedIDs.size > 0) {
|
|
67
|
+
if (updatedMonitors.size === 0 && unchangedIDs.size === 0) {
|
|
68
|
+
await promptConfirmDeleteAll(options);
|
|
69
|
+
}
|
|
70
|
+
const chunks = (0, utils_1.getChunks)(Array.from(removedIDs), kibana_api_1.CHUNK_SIZE);
|
|
71
|
+
for (const chunk of chunks) {
|
|
72
|
+
await (0, helpers_1.liveProgress)((0, kibana_api_1.bulkDeleteMonitors)(options, chunk), `deleting ${chunk.length} monitors`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
(0, helpers_1.done)(`Pushed: ${(0, colors_1.grey)((0, helpers_1.getMonitorManagementURL)(options.url))}`);
|
|
76
|
+
}
|
|
77
|
+
exports.push = push;
|
|
78
|
+
async function promptConfirmDeleteAll(options) {
|
|
79
|
+
(0, helpers_1.write)('');
|
|
80
|
+
const { deleteAll } = await (0, enquirer_1.prompt)({
|
|
81
|
+
type: 'confirm',
|
|
82
|
+
skip() {
|
|
83
|
+
if (options.yes) {
|
|
84
|
+
this.initial = process.env.TEST_OVERRIDE ?? true;
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
},
|
|
89
|
+
name: 'deleteAll',
|
|
90
|
+
message: `Pushing without any monitors will delete all monitors associated with the project.\n Do you want to continue?`,
|
|
91
|
+
initial: false,
|
|
92
|
+
});
|
|
93
|
+
if (!deleteAll) {
|
|
94
|
+
throw (0, helpers_1.warn)('Push command Aborted');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function trackDuplicates(monitors) {
|
|
98
|
+
const monitorMap = new Map();
|
|
99
|
+
const duplicates = new Set();
|
|
100
|
+
for (const monitor of monitors) {
|
|
101
|
+
const id = monitor.config.id;
|
|
102
|
+
if (monitorMap.has(id)) {
|
|
103
|
+
duplicates.add(monitorMap.get(id));
|
|
104
|
+
duplicates.add(monitor);
|
|
105
|
+
}
|
|
106
|
+
monitorMap.set(id, monitor);
|
|
107
|
+
}
|
|
108
|
+
return duplicates;
|
|
109
|
+
}
|
|
110
|
+
function formatDuplicateError(monitors) {
|
|
111
|
+
let outer = (0, colors_1.bold)(`Aborted: Duplicate monitors found\n`);
|
|
112
|
+
let inner = '';
|
|
113
|
+
for (const monitor of monitors) {
|
|
114
|
+
const { config, source } = monitor;
|
|
115
|
+
inner += `* ${config.id} - ${source.file}:${source.line}:${source.column}\n`;
|
|
116
|
+
}
|
|
117
|
+
outer += (0, helpers_1.indent)(inner);
|
|
118
|
+
return outer;
|
|
119
|
+
}
|
|
120
|
+
exports.formatDuplicateError = formatDuplicateError;
|
|
121
|
+
const INSTALLATION_HELP = `Run 'npx @elastic/synthetics init' to create project with default settings.`;
|
|
122
|
+
async function loadSettings() {
|
|
123
|
+
try {
|
|
124
|
+
const config = await (0, config_1.readConfig)(process.env['NODE_ENV'] || 'development');
|
|
125
|
+
// Missing config file, fake throw to capture as missing file
|
|
126
|
+
if (Object.keys(config).length === 0) {
|
|
127
|
+
throw '';
|
|
128
|
+
}
|
|
129
|
+
return config.project || {};
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
throw (0, helpers_1.error)(`Aborted (missing synthetics config file), Project not set up correctly.
|
|
133
|
+
|
|
134
|
+
${INSTALLATION_HELP}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.loadSettings = loadSettings;
|
|
138
|
+
function validateSettings(opts) {
|
|
139
|
+
const INVALID = 'Aborted. Invalid synthetics project settings.';
|
|
140
|
+
let reason = '';
|
|
141
|
+
if (!opts.id) {
|
|
142
|
+
reason = `Set project id via
|
|
143
|
+
- CLI '--id <id>'
|
|
144
|
+
- Config file 'project.id' field`;
|
|
145
|
+
}
|
|
146
|
+
else if (!opts.locations && !opts.privateLocations) {
|
|
147
|
+
reason = `Set default location for all monitors via
|
|
148
|
+
- CLI '--locations <values...> or --privateLocations <values...>'
|
|
149
|
+
- Config file 'monitors.locations' | 'monitors.privateLocations' field`;
|
|
150
|
+
}
|
|
151
|
+
else if (!opts.schedule) {
|
|
152
|
+
reason = `Set default schedule in minutes for all monitors via
|
|
153
|
+
- CLI '--schedule <mins>'
|
|
154
|
+
- Config file 'monitors.schedule' field`;
|
|
155
|
+
}
|
|
156
|
+
else if (opts.schedule && !monitor_2.ALLOWED_SCHEDULES.includes(opts.schedule)) {
|
|
157
|
+
reason = `Set default schedule(${opts.schedule}) to one of the allowed values - ${monitor_2.ALLOWED_SCHEDULES.join(',')}`;
|
|
158
|
+
}
|
|
159
|
+
if (!reason)
|
|
160
|
+
return;
|
|
161
|
+
throw (0, helpers_1.error)(`${INVALID}
|
|
162
|
+
|
|
163
|
+
${reason}
|
|
164
|
+
|
|
165
|
+
${INSTALLATION_HELP}`);
|
|
166
|
+
}
|
|
167
|
+
exports.validateSettings = validateSettings;
|
|
168
|
+
async function overrideSettings(oldValue, newValue) {
|
|
169
|
+
const cwd = process.cwd();
|
|
170
|
+
const configPath = await (0, config_1.findSyntheticsConfig)(cwd, cwd);
|
|
171
|
+
if (!configPath) {
|
|
172
|
+
throw (0, helpers_1.warn)(`Unable to find synthetics config file: ${configPath}`);
|
|
173
|
+
}
|
|
174
|
+
const config = await (0, promises_1.readFile)(configPath, 'utf-8');
|
|
175
|
+
const updatedConfig = config.replace(`id: '${oldValue}'`, `id: '${newValue}'`);
|
|
176
|
+
await (0, promises_1.writeFile)(configPath, updatedConfig, 'utf-8');
|
|
177
|
+
}
|
|
178
|
+
async function catchIncorrectSettings(settings, options) {
|
|
179
|
+
let override = !settings.id;
|
|
180
|
+
if (settings.id && settings.id !== options.id) {
|
|
181
|
+
// Add an extra line to make it easier to read the prompt
|
|
182
|
+
(0, helpers_1.write)('');
|
|
183
|
+
({ override } = await (0, enquirer_1.prompt)({
|
|
184
|
+
type: 'confirm',
|
|
185
|
+
name: 'override',
|
|
186
|
+
skip() {
|
|
187
|
+
if (options.yes) {
|
|
188
|
+
this.initial = process.env.TEST_OVERRIDE ?? true;
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
return false;
|
|
192
|
+
},
|
|
193
|
+
message: `Monitors were pushed under the '${settings.id}' project. Are you sure you want to push them under the new '${options.id}' (note that this will duplicate the monitors, the old ones being orphaned)`,
|
|
194
|
+
initial: false,
|
|
195
|
+
}));
|
|
196
|
+
if (!override) {
|
|
197
|
+
throw (0, helpers_1.warn)('Push command Aborted');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (override) {
|
|
201
|
+
await overrideSettings(settings.id, options.id);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
exports.catchIncorrectSettings = catchIncorrectSettings;
|
|
205
|
+
async function pushLegacy(monitors, options, version) {
|
|
206
|
+
const noLightWeightSupport = semver_1.default.satisfies(version, '<8.5.0');
|
|
207
|
+
if (noLightWeightSupport &&
|
|
208
|
+
monitors.some(monitor => monitor.type !== 'browser')) {
|
|
209
|
+
throw (0, helpers_1.error)(`Aborted: Lightweight monitors are not supported in ${version}. Please upgrade to 8.5.0 or above.`);
|
|
210
|
+
}
|
|
211
|
+
let schemas = [];
|
|
212
|
+
if (monitors.length > 0) {
|
|
213
|
+
(0, helpers_1.progress)(`bundling ${monitors.length} monitors`);
|
|
214
|
+
schemas = await (0, monitor_1.buildMonitorSchema)(monitors, false);
|
|
215
|
+
const chunks = (0, utils_1.getChunks)(schemas, 10);
|
|
216
|
+
for (const chunk of chunks) {
|
|
217
|
+
await (0, helpers_1.liveProgress)((0, kibana_api_1.createMonitorsLegacy)({ schemas: chunk, keepStale: true, options }), `creating or updating ${chunk.length} monitors`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
await promptConfirmDeleteAll(options);
|
|
222
|
+
}
|
|
223
|
+
await (0, helpers_1.liveProgress)((0, kibana_api_1.createMonitorsLegacy)({ schemas, keepStale: false, options }), `deleting all stale monitors`);
|
|
224
|
+
(0, helpers_1.done)(`Pushed: ${(0, colors_1.grey)((0, helpers_1.getMonitorManagementURL)(options.url))}`);
|
|
225
|
+
}
|
|
226
|
+
exports.pushLegacy = pushLegacy;
|
|
227
|
+
// prints warning if any of the monitors has throttling settings enabled during push
|
|
228
|
+
function warnIfThrottled(monitors) {
|
|
229
|
+
const throttled = monitors.some(monitor => monitor.config.throttling != null);
|
|
230
|
+
if (throttled) {
|
|
231
|
+
(0, helpers_1.warn)(helpers_1.THROTTLING_WARNING_MSG);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
exports.warnIfThrottled = warnIfThrottled;
|
|
235
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/push/index.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,oDAA4B;AAC5B,0CAAkD;AAClD,uCAAkC;AAClC,yCAA0C;AAC1C,uCAKmB;AACnB,4CAA4D;AAC5D,wCAUoB;AAEpB,sCAA6D;AAC7D,6CAOsB;AACtB,mCAA6C;AAEtC,KAAK,UAAU,IAAI,CAAC,QAAmB,EAAE,OAAoB;IAClE,MAAM,UAAU,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC7C,IAAI,UAAU,CAAC,IAAI,GAAG,CAAC,EAAE;QACvB,MAAM,IAAA,eAAK,EAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,CAAC;KAC/C;IACD,IAAA,kBAAQ,EAAC,iCAAiC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;IAExD,MAAM,YAAY,GAAG,MAAM,IAAA,uBAAU,EAAC,OAAO,CAAC,CAAC;IAC/C,MAAM,IAAI,GAAG,gBAAM,CAAC,SAAS,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;IACvD,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,MAAM,UAAU,CAAC,QAAQ,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;KAC1D;IAED,MAAM,KAAK,GAAG,IAAA,0BAAgB,EAAC,QAAQ,CAAC,CAAC;IACzC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,IAAA,4BAAe,EAAC,OAAO,CAAC,CAAC;IAC5D,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,IAAA,sBAAkB,EACzE,KAAK,EACL,MAAM,CAC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,QAAQ,EAAE,KAAK,CAAC,CAAC;QACpD,MAAM,MAAM,GAAG,IAAA,iBAAS,EAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACtC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;YAC1B,MAAM,IAAA,sBAAY,EAChB,IAAA,iCAAoB,EAAC,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAClE,wBAAwB,KAAK,CAAC,MAAM,WAAW,CAChD,CAAC;SACH;KACF;SAAM;QACL,MAAM,sBAAsB,CAAC,OAAO,CAAC,CAAC;KACvC;IACD,MAAM,IAAA,sBAAY,EAChB,IAAA,iCAAoB,EAAC,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,EAC5D,6BAA6B,CAC9B,CAAC;IAEF,IAAA,cAAI,EAAC,WAAW,IAAA,aAAI,EAAC,IAAA,iCAAuB,EAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;AAChE,CAAC;AAnCD,gCAmCC;AAED,oFAAoF;AACpF,SAAgB,eAAe,CAAC,QAAmB;IACjD,MAAM,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,IAAI,IAAI,CAAC,CAAC;IAC9E,IAAI,SAAS,EAAE;QACb,IAAA,cAAI,EAAC,gCAAsB,CAAC,CAAC;KAC9B;AACH,CAAC;AALD,0CAKC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2020-present, Elastic NV
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
|
14
|
+
* all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
* THE SOFTWARE.
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
import { PushOptions } from '../common_types';
|
|
26
|
+
import { MonitorHashID, MonitorSchema } from './monitor';
|
|
27
|
+
import { APIMonitorError } from './request';
|
|
28
|
+
export declare const CHUNK_SIZE = 100;
|
|
29
|
+
export declare type PutResponse = {
|
|
30
|
+
createdMonitors: string[];
|
|
31
|
+
updatedMonitors: string[];
|
|
32
|
+
failedMonitors: APIMonitorError[];
|
|
33
|
+
};
|
|
34
|
+
export declare function bulkPutMonitors(options: PushOptions, schemas: MonitorSchema[]): Promise<PutResponse>;
|
|
35
|
+
export declare type GetResponse = {
|
|
36
|
+
total: number;
|
|
37
|
+
monitors: MonitorHashID[];
|
|
38
|
+
after_key?: string;
|
|
39
|
+
};
|
|
40
|
+
export declare function bulkGetMonitors(options: PushOptions): Promise<GetResponse>;
|
|
41
|
+
export declare type DeleteResponse = {
|
|
42
|
+
deleted_monitors: string[];
|
|
43
|
+
};
|
|
44
|
+
export declare function bulkDeleteMonitors(options: PushOptions, monitorIDs: string[]): Promise<DeleteResponse>;
|
|
45
|
+
export declare function getVersion(options: PushOptions): Promise<number>;
|
|
46
|
+
export declare type LegacyAPISchema = {
|
|
47
|
+
project: string;
|
|
48
|
+
keep_stale: boolean;
|
|
49
|
+
monitors: MonitorSchema[];
|
|
50
|
+
};
|
|
51
|
+
export declare function createMonitorsLegacy({ schemas, keepStale, options, }: {
|
|
52
|
+
schemas: MonitorSchema[];
|
|
53
|
+
keepStale: boolean;
|
|
54
|
+
options: PushOptions;
|
|
55
|
+
}): Promise<void>;
|
|
56
|
+
//# sourceMappingURL=kibana_api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kibana_api.d.ts","sourceRoot":"","sources":["../../src/push/kibana_api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAML,eAAe,EAChB,MAAM,WAAW,CAAC;AAInB,eAAO,MAAM,UAAU,MAAM,CAAC;AAE9B,oBAAY,WAAW,GAAG;IACxB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,cAAc,EAAE,eAAe,EAAE,CAAC;CACnC,CAAC;AAEF,wBAAsB,eAAe,CACnC,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,aAAa,EAAE,wBAazB;AAED,oBAAY,WAAW,GAAG;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAsB,eAAe,CACnC,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,WAAW,CAAC,CAkBtB;AAmBD,oBAAY,cAAc,GAAG;IAC3B,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B,CAAC;AAEF,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,WAAW,EACpB,UAAU,EAAE,MAAM,EAAE,2BAQrB;AAQD,wBAAsB,UAAU,CAAC,OAAO,EAAE,WAAW,mBAOpD;AAED,oBAAY,eAAe,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,aAAa,EAAE,CAAC;CAC3B,CAAC;AAEF,wBAAsB,oBAAoB,CAAC,EACzC,OAAO,EACP,SAAS,EACT,OAAO,GACR,EAAE;IACD,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,WAAW,CAAC;CACtB,iBAoCA"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MIT License
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2020-present, Elastic NV
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in
|
|
15
|
+
* all copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
* THE SOFTWARE.
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.createMonitorsLegacy = exports.getVersion = exports.bulkDeleteMonitors = exports.bulkGetMonitors = exports.bulkPutMonitors = exports.CHUNK_SIZE = void 0;
|
|
28
|
+
const helpers_1 = require("../helpers");
|
|
29
|
+
const request_1 = require("./request");
|
|
30
|
+
const utils_1 = require("./utils");
|
|
31
|
+
// Default chunk size for bulk put / delete
|
|
32
|
+
exports.CHUNK_SIZE = 100;
|
|
33
|
+
async function bulkPutMonitors(options, schemas) {
|
|
34
|
+
const resp = await (0, request_1.sendReqAndHandleError)({
|
|
35
|
+
url: (0, utils_1.generateURL)(options, 'bulk_update') + '/_bulk_update',
|
|
36
|
+
method: 'PUT',
|
|
37
|
+
auth: options.auth,
|
|
38
|
+
body: JSON.stringify({ monitors: schemas }),
|
|
39
|
+
});
|
|
40
|
+
const { failedMonitors } = resp;
|
|
41
|
+
if (failedMonitors && failedMonitors.length > 0) {
|
|
42
|
+
throw (0, request_1.formatFailedMonitors)(failedMonitors);
|
|
43
|
+
}
|
|
44
|
+
return resp;
|
|
45
|
+
}
|
|
46
|
+
exports.bulkPutMonitors = bulkPutMonitors;
|
|
47
|
+
async function bulkGetMonitors(options) {
|
|
48
|
+
const allMonitors = [];
|
|
49
|
+
const resp = await fetchMonitors(options);
|
|
50
|
+
allMonitors.push(...resp.monitors);
|
|
51
|
+
let afterKey = resp.afterKey;
|
|
52
|
+
const total = resp.total;
|
|
53
|
+
while (allMonitors.length < total) {
|
|
54
|
+
const resp = await fetchMonitors(options, afterKey);
|
|
55
|
+
allMonitors.push(...resp.monitors);
|
|
56
|
+
afterKey = resp.afterKey;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
total,
|
|
60
|
+
monitors: allMonitors,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
exports.bulkGetMonitors = bulkGetMonitors;
|
|
64
|
+
const fetchMonitors = async (options, afterKey) => {
|
|
65
|
+
let url = (0, utils_1.generateURL)(options, 'bulk_get');
|
|
66
|
+
if (afterKey) {
|
|
67
|
+
url += `?search_after=${afterKey}`;
|
|
68
|
+
}
|
|
69
|
+
const resp = await (0, request_1.sendReqAndHandleError)({
|
|
70
|
+
url,
|
|
71
|
+
method: 'GET',
|
|
72
|
+
auth: options.auth,
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
afterKey: resp.after_key,
|
|
76
|
+
total: resp.total,
|
|
77
|
+
monitors: resp.monitors,
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
async function bulkDeleteMonitors(options, monitorIDs) {
|
|
81
|
+
return await (0, request_1.sendReqAndHandleError)({
|
|
82
|
+
url: (0, utils_1.generateURL)(options, 'bulk_delete') + '/_bulk_delete',
|
|
83
|
+
method: 'DELETE',
|
|
84
|
+
auth: options.auth,
|
|
85
|
+
body: JSON.stringify({ monitors: monitorIDs }),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
exports.bulkDeleteMonitors = bulkDeleteMonitors;
|
|
89
|
+
async function getVersion(options) {
|
|
90
|
+
const data = await (0, request_1.sendReqAndHandleError)({
|
|
91
|
+
url: (0, utils_1.generateURL)(options, 'status'),
|
|
92
|
+
method: 'GET',
|
|
93
|
+
auth: options.auth,
|
|
94
|
+
});
|
|
95
|
+
return data.version.number;
|
|
96
|
+
}
|
|
97
|
+
exports.getVersion = getVersion;
|
|
98
|
+
async function createMonitorsLegacy({ schemas, keepStale, options, }) {
|
|
99
|
+
const schema = {
|
|
100
|
+
project: options.id,
|
|
101
|
+
keep_stale: keepStale,
|
|
102
|
+
monitors: schemas,
|
|
103
|
+
};
|
|
104
|
+
const url = (0, utils_1.generateURL)(options, 'legacy');
|
|
105
|
+
const { body, statusCode } = await (0, request_1.sendRequest)({
|
|
106
|
+
url,
|
|
107
|
+
method: 'PUT',
|
|
108
|
+
auth: options.auth,
|
|
109
|
+
body: JSON.stringify(schema),
|
|
110
|
+
});
|
|
111
|
+
const resBody = await (0, request_1.handleError)(statusCode, url, body);
|
|
112
|
+
const allchunks = [];
|
|
113
|
+
for await (const data of resBody) {
|
|
114
|
+
allchunks.push(Buffer.from(data));
|
|
115
|
+
}
|
|
116
|
+
const chunks = (0, helpers_1.safeNDJSONParse)(Buffer.concat(allchunks).toString('utf-8'));
|
|
117
|
+
// Its kind of hacky for now where Kibana streams the response by
|
|
118
|
+
// writing the data as NDJSON events (data can be interleaved), we
|
|
119
|
+
// distinguish the final data by checking if the event was a progress vs complete event
|
|
120
|
+
for (const chunk of chunks) {
|
|
121
|
+
if (typeof chunk === 'string') {
|
|
122
|
+
// Ignore the progress from Kibana as we chunk the requests
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const { failedMonitors, failedStaleMonitors } = chunk;
|
|
126
|
+
if (failedMonitors && failedMonitors.length > 0) {
|
|
127
|
+
throw (0, request_1.formatFailedMonitors)(failedMonitors);
|
|
128
|
+
}
|
|
129
|
+
if (failedStaleMonitors.length > 0) {
|
|
130
|
+
throw (0, request_1.formatStaleMonitors)(failedStaleMonitors);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.createMonitorsLegacy = createMonitorsLegacy;
|
|
135
|
+
//# sourceMappingURL=kibana_api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kibana_api.js","sourceRoot":"","sources":["../../src/push/kibana_api.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;A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AC,EAAE;YAClC,MAAM,IAAA,6BAAmB,EAAC,mBAAmB,CAAC,CAAC;SAChD;KACF;AACH,CAAC;AA5CD,oDA4CC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2020-present, Elastic NV
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
|
14
|
+
* all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
* THE SOFTWARE.
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
import { Monitor, MonitorConfig } from '../dsl/monitor';
|
|
26
|
+
import { PushOptions } from '../common_types';
|
|
27
|
+
export declare type MonitorSchema = Omit<MonitorConfig, 'locations'> & {
|
|
28
|
+
locations: string[];
|
|
29
|
+
content?: string;
|
|
30
|
+
filter?: Monitor['filter'];
|
|
31
|
+
hash?: string;
|
|
32
|
+
};
|
|
33
|
+
export declare type MonitorHashID = {
|
|
34
|
+
journey_id?: string;
|
|
35
|
+
hash?: string;
|
|
36
|
+
};
|
|
37
|
+
declare class RemoteDiffResult {
|
|
38
|
+
newIDs: Set<string>;
|
|
39
|
+
changedIDs: Set<string>;
|
|
40
|
+
removedIDs: Set<string>;
|
|
41
|
+
unchangedIDs: Set<string>;
|
|
42
|
+
}
|
|
43
|
+
export declare function diffMonitors(local: MonitorHashID[], remote: MonitorHashID[]): RemoteDiffResult;
|
|
44
|
+
export declare function getLocalMonitors(monitors: Monitor[]): MonitorHashID[];
|
|
45
|
+
export declare function buildMonitorSchema(monitors: Monitor[], isV2: boolean): Promise<MonitorSchema[]>;
|
|
46
|
+
export declare function createLightweightMonitors(workDir: string, options: PushOptions): Promise<Monitor[]>;
|
|
47
|
+
export declare function buildMonitorFromYaml(config: MonitorConfig, options: PushOptions): Monitor;
|
|
48
|
+
export declare const parseAlertConfig: (config: MonitorConfig) => {
|
|
49
|
+
status: {
|
|
50
|
+
enabled: any;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
export declare function parseSchedule(schedule: string): 1 | 3 | 5 | 20 | 10 | 15 | 30 | 60 | 120 | 240;
|
|
54
|
+
export {};
|
|
55
|
+
//# sourceMappingURL=monitor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monitor.d.ts","sourceRoot":"","sources":["../../src/push/monitor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AASH,OAAO,EAAqB,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAK9C,oBAAY,aAAa,GAAG,IAAI,CAAC,aAAa,EAAE,WAAW,CAAC,GAAG;IAC7D,SAAS,EAAE,MAAM,EAAE,CAAC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