@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.
Files changed (76) hide show
  1. package/dist/cli.js +23 -17
  2. package/dist/cli.js.map +1 -1
  3. package/dist/common_types.d.ts +42 -47
  4. package/dist/common_types.d.ts.map +1 -1
  5. package/dist/config.d.ts +1 -1
  6. package/dist/config.d.ts.map +1 -1
  7. package/dist/core/runner.d.ts +6 -6
  8. package/dist/core/runner.d.ts.map +1 -1
  9. package/dist/core/runner.js +2 -3
  10. package/dist/core/runner.js.map +1 -1
  11. package/dist/core/transform.d.ts +62 -2
  12. package/dist/core/transform.d.ts.map +1 -1
  13. package/dist/dsl/journey.d.ts +4 -4
  14. package/dist/dsl/journey.d.ts.map +1 -1
  15. package/dist/dsl/journey.js +0 -1
  16. package/dist/dsl/journey.js.map +1 -1
  17. package/dist/dsl/monitor.d.ts +13 -8
  18. package/dist/dsl/monitor.d.ts.map +1 -1
  19. package/dist/dsl/monitor.js +5 -1
  20. package/dist/dsl/monitor.js.map +1 -1
  21. package/dist/formatter/javascript.d.ts +6 -6
  22. package/dist/formatter/javascript.d.ts.map +1 -1
  23. package/dist/generator/index.d.ts +1 -1
  24. package/dist/generator/index.d.ts.map +1 -1
  25. package/dist/generator/index.js +1 -1
  26. package/dist/generator/index.js.map +1 -1
  27. package/dist/helpers.d.ts +1 -1
  28. package/dist/helpers.d.ts.map +1 -1
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/locations/index.d.ts +13 -5
  32. package/dist/locations/index.d.ts.map +1 -1
  33. package/dist/locations/index.js +30 -14
  34. package/dist/locations/index.js.map +1 -1
  35. package/dist/options.d.ts +5 -4
  36. package/dist/options.d.ts.map +1 -1
  37. package/dist/options.js +26 -10
  38. package/dist/options.js.map +1 -1
  39. package/dist/plugins/plugin-manager.d.ts +3 -3
  40. package/dist/plugins/plugin-manager.d.ts.map +1 -1
  41. package/dist/plugins/tracing.d.ts +1 -1
  42. package/dist/plugins/tracing.d.ts.map +1 -1
  43. package/dist/push/index.d.ts +2 -1
  44. package/dist/push/index.d.ts.map +1 -1
  45. package/dist/push/index.js +13 -7
  46. package/dist/push/index.js.map +1 -1
  47. package/dist/push/kibana_api.d.ts +5 -5
  48. package/dist/push/kibana_api.d.ts.map +1 -1
  49. package/dist/push/monitor.d.ts +7 -8
  50. package/dist/push/monitor.d.ts.map +1 -1
  51. package/dist/push/monitor.js +57 -24
  52. package/dist/push/monitor.js.map +1 -1
  53. package/dist/push/request.d.ts +2 -2
  54. package/dist/push/request.d.ts.map +1 -1
  55. package/dist/push/utils.d.ts +3 -3
  56. package/dist/push/utils.d.ts.map +1 -1
  57. package/dist/reporters/index.d.ts +3 -3
  58. package/dist/reporters/index.d.ts.map +1 -1
  59. package/dist/reporters/json.d.ts +5 -5
  60. package/dist/reporters/json.d.ts.map +1 -1
  61. package/dist/sdk/trace-processor.d.ts +4 -4
  62. package/dist/sdk/trace-processor.d.ts.map +1 -1
  63. package/package.json +9 -8
  64. package/src/cli.ts +27 -32
  65. package/src/common_types.ts +11 -14
  66. package/src/core/runner.ts +4 -4
  67. package/src/dsl/journey.ts +0 -1
  68. package/src/dsl/monitor.ts +15 -6
  69. package/src/generator/index.ts +2 -1
  70. package/src/index.ts +2 -0
  71. package/src/locations/index.ts +37 -12
  72. package/src/options.ts +31 -17
  73. package/src/push/index.ts +17 -6
  74. package/src/push/kibana_api.ts +1 -1
  75. package/src/push/monitor.ts +72 -25
  76. package/src/push/utils.ts +2 -2
@@ -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, isMatch } from '../helpers';
31
+ import { SYNTHETICS_PATH, totalist, indent, warn } from '../helpers';
32
32
  import { LocationsMap } from '../locations/public-locations';
33
- import { ALLOWED_SCHEDULES, Monitor, MonitorConfig } from '../dsl/monitor';
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(monitors: Monitor[]) {
113
+ export function getLocalMonitors(schemas: MonitorSchema[]) {
109
114
  const data: MonitorHashID[] = [];
110
- for (const monitor of monitors) {
115
+ for (const schema of schemas) {
111
116
  data.push({
112
- journey_id: monitor.config.id,
113
- hash: monitor.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
- if (isV2) {
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'] || options.privateLocations;
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 = (config: MonitorConfig) => {
258
- if (config['alert.status.enabled'] !== undefined) {
259
- const value = config['alert.status.enabled'];
260
- delete config['alert.status.enabled'];
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
- status: {
263
- enabled: value,
264
- },
291
+ enabled: value[key].enabled,
265
292
  };
266
293
  }
267
- return config.alert;
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: number) {
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: number) {
106
+ export function isParamOptionSupported(version: string) {
107
107
  return semver.satisfies(version, '>=8.7.2');
108
108
  }