@elastic/synthetics 1.2.0 → 1.4.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.js +23 -17
- package/dist/cli.js.map +1 -1
- package/dist/common_types.d.ts +42 -47
- package/dist/common_types.d.ts.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/core/runner.d.ts +6 -6
- package/dist/core/runner.d.ts.map +1 -1
- package/dist/core/runner.js +2 -3
- package/dist/core/runner.js.map +1 -1
- package/dist/core/transform.d.ts +62 -2
- package/dist/core/transform.d.ts.map +1 -1
- package/dist/dsl/journey.d.ts +4 -4
- package/dist/dsl/journey.d.ts.map +1 -1
- package/dist/dsl/journey.js +0 -1
- package/dist/dsl/journey.js.map +1 -1
- package/dist/dsl/monitor.d.ts +13 -8
- package/dist/dsl/monitor.d.ts.map +1 -1
- package/dist/dsl/monitor.js +5 -1
- package/dist/dsl/monitor.js.map +1 -1
- package/dist/formatter/javascript.d.ts +6 -6
- package/dist/formatter/javascript.d.ts.map +1 -1
- package/dist/generator/index.d.ts +1 -1
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +1 -1
- package/dist/generator/index.js.map +1 -1
- package/dist/helpers.d.ts +1 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/locations/index.d.ts +13 -5
- package/dist/locations/index.d.ts.map +1 -1
- package/dist/locations/index.js +30 -14
- package/dist/locations/index.js.map +1 -1
- package/dist/options.d.ts +5 -4
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +26 -10
- package/dist/options.js.map +1 -1
- package/dist/plugins/plugin-manager.d.ts +3 -3
- package/dist/plugins/plugin-manager.d.ts.map +1 -1
- package/dist/plugins/tracing.d.ts +1 -1
- package/dist/plugins/tracing.d.ts.map +1 -1
- package/dist/push/index.d.ts +2 -1
- package/dist/push/index.d.ts.map +1 -1
- package/dist/push/index.js +13 -7
- package/dist/push/index.js.map +1 -1
- package/dist/push/kibana_api.d.ts +5 -5
- package/dist/push/kibana_api.d.ts.map +1 -1
- package/dist/push/monitor.d.ts +7 -8
- package/dist/push/monitor.d.ts.map +1 -1
- package/dist/push/monitor.js +57 -24
- package/dist/push/monitor.js.map +1 -1
- package/dist/push/request.d.ts +2 -2
- package/dist/push/request.d.ts.map +1 -1
- package/dist/push/utils.d.ts +3 -3
- package/dist/push/utils.d.ts.map +1 -1
- package/dist/reporters/index.d.ts +3 -3
- package/dist/reporters/index.d.ts.map +1 -1
- package/dist/reporters/json.d.ts +5 -5
- package/dist/reporters/json.d.ts.map +1 -1
- package/dist/sdk/trace-processor.d.ts +4 -4
- package/dist/sdk/trace-processor.d.ts.map +1 -1
- package/package.json +9 -8
- package/src/cli.ts +27 -32
- package/src/common_types.ts +11 -14
- package/src/core/runner.ts +4 -4
- package/src/dsl/journey.ts +0 -1
- package/src/dsl/monitor.ts +15 -6
- package/src/generator/index.ts +2 -1
- package/src/index.ts +2 -0
- package/src/locations/index.ts +37 -12
- package/src/options.ts +31 -17
- package/src/push/index.ts +17 -6
- package/src/push/kibana_api.ts +1 -1
- package/src/push/monitor.ts +72 -25
- package/src/push/utils.ts +2 -2
package/src/push/monitor.ts
CHANGED
|
@@ -28,9 +28,14 @@ import { extname, join } from 'path';
|
|
|
28
28
|
import { LineCounter, parseDocument, YAMLSeq, YAMLMap } from 'yaml';
|
|
29
29
|
import { bold, red } from 'kleur/colors';
|
|
30
30
|
import { Bundler } from './bundler';
|
|
31
|
-
import { SYNTHETICS_PATH, totalist, indent, warn
|
|
31
|
+
import { SYNTHETICS_PATH, totalist, indent, warn } from '../helpers';
|
|
32
32
|
import { LocationsMap } from '../locations/public-locations';
|
|
33
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
AlertConfig,
|
|
35
|
+
ALLOWED_SCHEDULES,
|
|
36
|
+
Monitor,
|
|
37
|
+
MonitorConfig,
|
|
38
|
+
} from '../dsl/monitor';
|
|
34
39
|
import { PushOptions } from '../common_types';
|
|
35
40
|
import { isParamOptionSupported } from './utils';
|
|
36
41
|
|
|
@@ -105,12 +110,12 @@ export function diffMonitors(
|
|
|
105
110
|
return result;
|
|
106
111
|
}
|
|
107
112
|
|
|
108
|
-
export function getLocalMonitors(
|
|
113
|
+
export function getLocalMonitors(schemas: MonitorSchema[]) {
|
|
109
114
|
const data: MonitorHashID[] = [];
|
|
110
|
-
for (const
|
|
115
|
+
for (const schema of schemas) {
|
|
111
116
|
data.push({
|
|
112
|
-
journey_id:
|
|
113
|
-
hash:
|
|
117
|
+
journey_id: schema.id,
|
|
118
|
+
hash: schema.hash,
|
|
114
119
|
});
|
|
115
120
|
}
|
|
116
121
|
return data;
|
|
@@ -132,14 +137,20 @@ export async function buildMonitorSchema(monitors: Monitor[], isV2: boolean) {
|
|
|
132
137
|
...config,
|
|
133
138
|
locations: translateLocation(config.locations),
|
|
134
139
|
};
|
|
135
|
-
|
|
136
|
-
schema.hash = monitor.hash();
|
|
137
|
-
}
|
|
140
|
+
|
|
138
141
|
if (type === 'browser') {
|
|
139
142
|
const outPath = join(bundlePath, config.name + '.zip');
|
|
140
143
|
const content = await bundler.build(source.file, outPath);
|
|
144
|
+
monitor.setContent(content);
|
|
141
145
|
Object.assign(schema, { content, filter });
|
|
142
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Generate hash only after the bundled content is created
|
|
149
|
+
* to capture code changes in imported files
|
|
150
|
+
*/
|
|
151
|
+
if (isV2) {
|
|
152
|
+
schema.hash = monitor.hash();
|
|
153
|
+
}
|
|
143
154
|
schemas.push(schema);
|
|
144
155
|
}
|
|
145
156
|
|
|
@@ -198,10 +209,6 @@ export async function createLightweightMonitors(
|
|
|
198
209
|
continue;
|
|
199
210
|
}
|
|
200
211
|
const config = monNode.toJSON();
|
|
201
|
-
// Filter based on matched tags and name
|
|
202
|
-
if (!isMatch(config.tags, config.name, options.tags, options.match)) {
|
|
203
|
-
continue;
|
|
204
|
-
}
|
|
205
212
|
const { line, col } = lineCounter.linePos(monNode.srcToken.offset);
|
|
206
213
|
try {
|
|
207
214
|
const mon = buildMonitorFromYaml(config, options);
|
|
@@ -232,12 +239,14 @@ export function buildMonitorFromYaml(
|
|
|
232
239
|
}
|
|
233
240
|
const schedule = config.schedule && parseSchedule(String(config.schedule));
|
|
234
241
|
const privateLocations =
|
|
235
|
-
config['private_locations'] ||
|
|
242
|
+
config['private_locations'] ||
|
|
243
|
+
config.privateLocations ||
|
|
244
|
+
options.privateLocations;
|
|
236
245
|
delete config['private_locations'];
|
|
237
|
-
|
|
238
|
-
const alertConfig = parseAlertConfig(config);
|
|
246
|
+
const alertConfig = parseAlertConfig(config, options.alert);
|
|
239
247
|
const mon = new Monitor({
|
|
240
248
|
locations: options.locations,
|
|
249
|
+
tags: options.tags,
|
|
241
250
|
...config,
|
|
242
251
|
privateLocations,
|
|
243
252
|
schedule: schedule || options.schedule,
|
|
@@ -254,18 +263,56 @@ export function buildMonitorFromYaml(
|
|
|
254
263
|
return mon;
|
|
255
264
|
}
|
|
256
265
|
|
|
257
|
-
export const parseAlertConfig = (
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
266
|
+
export const parseAlertConfig = (
|
|
267
|
+
config: MonitorConfig,
|
|
268
|
+
gConfig?: AlertConfig
|
|
269
|
+
) => {
|
|
270
|
+
// If the user has provided a global alert config, merge it with the monitor alert config
|
|
271
|
+
const status = getAlertKeyValue('status', config, gConfig);
|
|
272
|
+
const tls = getAlertKeyValue('tls', config, gConfig);
|
|
273
|
+
const result = {};
|
|
274
|
+
if (status) {
|
|
275
|
+
result['status'] = status;
|
|
276
|
+
}
|
|
277
|
+
if (tls) {
|
|
278
|
+
result['tls'] = tls;
|
|
279
|
+
}
|
|
280
|
+
return Object.keys(result).length > 0 ? result : undefined;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
export function getAlertKeyValue(
|
|
284
|
+
key: 'status' | 'tls',
|
|
285
|
+
config: MonitorConfig,
|
|
286
|
+
alertConfig?: AlertConfig
|
|
287
|
+
): { enabled: boolean } {
|
|
288
|
+
const value = config.alert;
|
|
289
|
+
if (value?.[key]?.enabled !== undefined) {
|
|
261
290
|
return {
|
|
262
|
-
|
|
263
|
-
enabled: value,
|
|
264
|
-
},
|
|
291
|
+
enabled: value[key].enabled,
|
|
265
292
|
};
|
|
266
293
|
}
|
|
267
|
-
|
|
268
|
-
}
|
|
294
|
+
|
|
295
|
+
if (value?.[`${key}.enabled`] !== undefined) {
|
|
296
|
+
const val = value?.[`${key}.enabled`];
|
|
297
|
+
delete value?.[`${key}.enabled`];
|
|
298
|
+
if (Object.keys(value).length === 0) {
|
|
299
|
+
delete config.alert;
|
|
300
|
+
}
|
|
301
|
+
return {
|
|
302
|
+
enabled: val,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
const rootKey = `alert.${key}.enabled`;
|
|
306
|
+
if (config[rootKey] !== undefined) {
|
|
307
|
+
const enabled = config[rootKey];
|
|
308
|
+
delete config[rootKey];
|
|
309
|
+
return {
|
|
310
|
+
enabled,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return alertConfig?.[key];
|
|
315
|
+
}
|
|
269
316
|
|
|
270
317
|
export function parseSchedule(schedule: string) {
|
|
271
318
|
const EVERY_SYNTAX = '@every';
|
package/src/push/utils.ts
CHANGED
|
@@ -81,7 +81,7 @@ export function generateURL(options: PushOptions, operation: Operation) {
|
|
|
81
81
|
/**
|
|
82
82
|
* Bulk API is supported for push monitors only from 8.6.0 and above
|
|
83
83
|
*/
|
|
84
|
-
export function isBulkAPISupported(version:
|
|
84
|
+
export function isBulkAPISupported(version: string) {
|
|
85
85
|
return semver.satisfies(version, '>=8.6.0');
|
|
86
86
|
}
|
|
87
87
|
|
|
@@ -103,6 +103,6 @@ export function isLightweightMonitorSupported(
|
|
|
103
103
|
* Lighweight monitor param options are supported only from
|
|
104
104
|
* 8.7.2 and above
|
|
105
105
|
*/
|
|
106
|
-
export function isParamOptionSupported(version:
|
|
106
|
+
export function isParamOptionSupported(version: string) {
|
|
107
107
|
return semver.satisfies(version, '>=8.7.2');
|
|
108
108
|
}
|