@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,160 @@
|
|
|
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
|
+
|
|
26
|
+
import { addHook } from 'pirates';
|
|
27
|
+
import {
|
|
28
|
+
transformSync,
|
|
29
|
+
Loader,
|
|
30
|
+
CommonOptions,
|
|
31
|
+
TransformOptions,
|
|
32
|
+
} from 'esbuild';
|
|
33
|
+
import path from 'path';
|
|
34
|
+
import sourceMapSupport from 'source-map-support';
|
|
35
|
+
|
|
36
|
+
// Cache that holds the sourcemap content for each file
|
|
37
|
+
const sourceMaps: Map<string, string> = new Map();
|
|
38
|
+
|
|
39
|
+
// Register the source-map-support library to resolve the sourcemaps
|
|
40
|
+
// for the files that are transpiled by esbuild
|
|
41
|
+
/**
|
|
42
|
+
* Register the source-map-support library to resolve the sourcemaps
|
|
43
|
+
* for the files that are transpiled by esbuild and cache the sourcemaps
|
|
44
|
+
* for each file.
|
|
45
|
+
*
|
|
46
|
+
* Caching the sourcemap file is important, as it is used by the Synthetics agent
|
|
47
|
+
* to resolve the stack traces of journey, monitor and step functions.
|
|
48
|
+
*/
|
|
49
|
+
sourceMapSupport.install({
|
|
50
|
+
environment: 'node',
|
|
51
|
+
handleUncaughtExceptions: false,
|
|
52
|
+
retrieveSourceMap(source) {
|
|
53
|
+
if (!sourceMaps.has(source)) return null;
|
|
54
|
+
return {
|
|
55
|
+
map: JSON.parse(sourceMaps.get(source)),
|
|
56
|
+
url: source,
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Default list of files and corresponding loaders we support
|
|
63
|
+
* while pushing project based monitors
|
|
64
|
+
*/
|
|
65
|
+
const LOADERS: Record<string, Loader> = {
|
|
66
|
+
'.ts': 'ts',
|
|
67
|
+
'.js': 'js',
|
|
68
|
+
'.mjs': 'js',
|
|
69
|
+
'.cjs': 'js',
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const getLoader = (filename: string) => {
|
|
73
|
+
const ext = path.extname(filename);
|
|
74
|
+
return LOADERS[ext] || 'default';
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export function commonOptions(): CommonOptions {
|
|
78
|
+
/**
|
|
79
|
+
* We are not minifying the code as we want it to be in sync with previous
|
|
80
|
+
* transformation phase and introduce it later.
|
|
81
|
+
*/
|
|
82
|
+
return {
|
|
83
|
+
minify: false,
|
|
84
|
+
minifyIdentifiers: false,
|
|
85
|
+
minifySyntax: false,
|
|
86
|
+
minifyWhitespace: false,
|
|
87
|
+
sourcemap: 'both',
|
|
88
|
+
sourcesContent: false,
|
|
89
|
+
platform: 'node',
|
|
90
|
+
logLevel: 'silent',
|
|
91
|
+
format: 'cjs',
|
|
92
|
+
target: `node${process.version.slice(1)}`,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Transform the given code using esbuild and save the corresponding
|
|
98
|
+
* map file in memory to be retrived later.
|
|
99
|
+
*/
|
|
100
|
+
export function transform(
|
|
101
|
+
code: string,
|
|
102
|
+
filename: string,
|
|
103
|
+
options: TransformOptions = {}
|
|
104
|
+
) {
|
|
105
|
+
const result = transformSync(code, {
|
|
106
|
+
...commonOptions(),
|
|
107
|
+
sourcefile: filename,
|
|
108
|
+
loader: getLoader(filename),
|
|
109
|
+
/**
|
|
110
|
+
* Add this only for the transformation phase, using it on
|
|
111
|
+
* bundling phase would disable tree shaking and uncessary bloat
|
|
112
|
+
*
|
|
113
|
+
* Ensures backwards compatability with tsc's implicit strict behaviour
|
|
114
|
+
*/
|
|
115
|
+
tsconfigRaw: {
|
|
116
|
+
compilerOptions: {
|
|
117
|
+
alwaysStrict: true,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
...options,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const warnings = result.warnings;
|
|
124
|
+
if (warnings && warnings.length > 0) {
|
|
125
|
+
for (const warning of warnings) {
|
|
126
|
+
console.log(warning.location);
|
|
127
|
+
console.log(warning.text);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Cache the sourcemap contents in memory, so we can look it up
|
|
133
|
+
* later when we try to resolve the sourcemap for a given file.
|
|
134
|
+
*
|
|
135
|
+
* Every time the synthetics agent is started, we register the source-map-support
|
|
136
|
+
* library to resolve the sourcemaps for the files that are transpiled by esbuild.
|
|
137
|
+
*/
|
|
138
|
+
if (result.map) {
|
|
139
|
+
sourceMaps.set(filename, result.map);
|
|
140
|
+
}
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Install the pirates hook to transform the code on the fly
|
|
146
|
+
* for all of the imported files.
|
|
147
|
+
*/
|
|
148
|
+
export function installTransform() {
|
|
149
|
+
const revertPirates = addHook(
|
|
150
|
+
(source: string, filename: string) => {
|
|
151
|
+
const { code } = transform(source, filename);
|
|
152
|
+
return code;
|
|
153
|
+
},
|
|
154
|
+
{ exts: ['.ts', '.js', '.mjs', '.cjs'] }
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
return () => {
|
|
158
|
+
revertPirates();
|
|
159
|
+
};
|
|
160
|
+
}
|
package/src/dsl/journey.ts
CHANGED
|
@@ -23,10 +23,17 @@
|
|
|
23
23
|
*
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import {
|
|
27
|
-
|
|
26
|
+
import {
|
|
27
|
+
Browser,
|
|
28
|
+
Page,
|
|
29
|
+
BrowserContext,
|
|
30
|
+
CDPSession,
|
|
31
|
+
APIRequestContext,
|
|
32
|
+
} from 'playwright-chromium';
|
|
28
33
|
import { Step } from './step';
|
|
29
|
-
import { VoidCallback, HooksCallback, Params } from '../common_types';
|
|
34
|
+
import { VoidCallback, HooksCallback, Params, Location } from '../common_types';
|
|
35
|
+
import { Monitor, MonitorConfig } from './monitor';
|
|
36
|
+
import { isMatch } from '../helpers';
|
|
30
37
|
|
|
31
38
|
export type JourneyOptions = {
|
|
32
39
|
name: string;
|
|
@@ -42,6 +49,7 @@ export type JourneyCallback = (options: {
|
|
|
42
49
|
browser: Browser;
|
|
43
50
|
client: CDPSession;
|
|
44
51
|
params: Params;
|
|
52
|
+
request: APIRequestContext;
|
|
45
53
|
}) => void;
|
|
46
54
|
|
|
47
55
|
export class Journey {
|
|
@@ -49,18 +57,26 @@ export class Journey {
|
|
|
49
57
|
id?: string;
|
|
50
58
|
tags?: string[];
|
|
51
59
|
callback: JourneyCallback;
|
|
60
|
+
location?: Location;
|
|
52
61
|
steps: Step[] = [];
|
|
53
62
|
hooks: Hooks = { before: [], after: [] };
|
|
63
|
+
monitor: Monitor;
|
|
54
64
|
|
|
55
|
-
constructor(
|
|
65
|
+
constructor(
|
|
66
|
+
options: JourneyOptions,
|
|
67
|
+
callback: JourneyCallback,
|
|
68
|
+
location?: Location
|
|
69
|
+
) {
|
|
56
70
|
this.name = options.name;
|
|
57
|
-
this.id = options.id;
|
|
71
|
+
this.id = options.id || options.name;
|
|
58
72
|
this.tags = options.tags;
|
|
59
73
|
this.callback = callback;
|
|
74
|
+
this.location = location;
|
|
75
|
+
this.updateMonitor({});
|
|
60
76
|
}
|
|
61
77
|
|
|
62
|
-
addStep(name: string, callback: VoidCallback) {
|
|
63
|
-
const step = new Step(name, this.steps.length + 1, callback);
|
|
78
|
+
addStep(name: string, callback: VoidCallback, location?: Location) {
|
|
79
|
+
const step = new Step(name, this.steps.length + 1, callback, location);
|
|
64
80
|
this.steps.push(step);
|
|
65
81
|
return step;
|
|
66
82
|
}
|
|
@@ -68,23 +84,27 @@ export class Journey {
|
|
|
68
84
|
addHook(type: HookType, callback: HooksCallback) {
|
|
69
85
|
this.hooks[type].push(callback);
|
|
70
86
|
}
|
|
87
|
+
|
|
88
|
+
updateMonitor(config: MonitorConfig) {
|
|
89
|
+
/**
|
|
90
|
+
* Use defaults values from journey for monitor object (id, name and tags)
|
|
91
|
+
*/
|
|
92
|
+
this.monitor = new Monitor({
|
|
93
|
+
name: this.name,
|
|
94
|
+
id: this.id,
|
|
95
|
+
type: 'browser',
|
|
96
|
+
tags: this.tags ?? [],
|
|
97
|
+
...config,
|
|
98
|
+
});
|
|
99
|
+
this.monitor.setSource(this.location);
|
|
100
|
+
this.monitor.setContent(this.callback.toString());
|
|
101
|
+
this.monitor.setFilter({ match: this.name });
|
|
102
|
+
}
|
|
103
|
+
|
|
71
104
|
/**
|
|
72
105
|
* Matches journeys based on the provided args. Proitize tags over match
|
|
73
|
-
* - tags pattern that matches only tags
|
|
74
|
-
* - match pattern that matches both name and tags
|
|
75
106
|
*/
|
|
76
107
|
isMatch(matchPattern: string, tagsPattern: Array<string>) {
|
|
77
|
-
|
|
78
|
-
return this.tagsMatch(tagsPattern);
|
|
79
|
-
}
|
|
80
|
-
if (matchPattern) {
|
|
81
|
-
return isMatch(this.name, matchPattern) || this.tagsMatch(matchPattern);
|
|
82
|
-
}
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
tagsMatch(pattern) {
|
|
87
|
-
const matchess = micromatch(this.tags || ['*'], pattern);
|
|
88
|
-
return matchess.length > 0;
|
|
108
|
+
return isMatch(this.tags, this.name, tagsPattern, matchPattern);
|
|
89
109
|
}
|
|
90
110
|
}
|
|
@@ -0,0 +1,152 @@
|
|
|
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
|
+
|
|
26
|
+
import { createHash } from 'crypto';
|
|
27
|
+
import merge from 'deepmerge';
|
|
28
|
+
import { bold, red } from 'kleur/colors';
|
|
29
|
+
import {
|
|
30
|
+
ThrottlingOptions,
|
|
31
|
+
Location,
|
|
32
|
+
ScreenshotOptions,
|
|
33
|
+
Params,
|
|
34
|
+
PlaywrightOptions,
|
|
35
|
+
} from '../common_types';
|
|
36
|
+
import { indent } from '../helpers';
|
|
37
|
+
import { LocationsMap } from '../locations/public-locations';
|
|
38
|
+
|
|
39
|
+
export type SyntheticsLocationsType = keyof typeof LocationsMap;
|
|
40
|
+
export const SyntheticsLocations = Object.keys(
|
|
41
|
+
LocationsMap
|
|
42
|
+
) as SyntheticsLocationsType[];
|
|
43
|
+
export const ALLOWED_SCHEDULES = [
|
|
44
|
+
1, 3, 5, 10, 15, 20, 30, 60, 120, 240,
|
|
45
|
+
] as const;
|
|
46
|
+
|
|
47
|
+
export type MonitorConfig = {
|
|
48
|
+
id?: string;
|
|
49
|
+
name?: string;
|
|
50
|
+
type?: string;
|
|
51
|
+
tags?: string[];
|
|
52
|
+
schedule?: typeof ALLOWED_SCHEDULES[number];
|
|
53
|
+
enabled?: boolean;
|
|
54
|
+
locations?: SyntheticsLocationsType[];
|
|
55
|
+
privateLocations?: string[];
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated This option is ignored.
|
|
58
|
+
* Network throttling via chrome devtools is ignored at the moment.
|
|
59
|
+
* See https://github.com/elastic/synthetics/blob/main/docs/throttling.md for more details.
|
|
60
|
+
*/
|
|
61
|
+
throttling?: boolean | ThrottlingOptions;
|
|
62
|
+
screenshot?: ScreenshotOptions;
|
|
63
|
+
params?: Params;
|
|
64
|
+
playwrightOptions?: PlaywrightOptions;
|
|
65
|
+
alert?: {
|
|
66
|
+
status: {
|
|
67
|
+
enabled: boolean;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
type MonitorFilter = {
|
|
73
|
+
match: string;
|
|
74
|
+
tags?: string[];
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export class Monitor {
|
|
78
|
+
content?: string;
|
|
79
|
+
source?: Location;
|
|
80
|
+
filter: MonitorFilter;
|
|
81
|
+
constructor(public config: MonitorConfig = {}) {}
|
|
82
|
+
/**
|
|
83
|
+
* Treat the creation time config with `monitor.use` as source of truth by
|
|
84
|
+
* merging the values coming from CLI and Synthetics config file
|
|
85
|
+
*/
|
|
86
|
+
update(globalOpts: MonitorConfig = {}) {
|
|
87
|
+
this.config = merge(globalOpts, this.config, {
|
|
88
|
+
arrayMerge(target, source) {
|
|
89
|
+
return [...new Set(source)];
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
get type() {
|
|
95
|
+
return this.config.type;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
setSource(source: Location) {
|
|
99
|
+
this.source = source;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The underlying journey code of the monitor
|
|
104
|
+
*/
|
|
105
|
+
setContent(content = '') {
|
|
106
|
+
this.content = content;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* If journey files are colocated within the same file during
|
|
111
|
+
* push command, when we invoke synthetics from HB we rely on
|
|
112
|
+
* this filter for running that specific journey alone instead of
|
|
113
|
+
* all journeys on the file
|
|
114
|
+
*/
|
|
115
|
+
setFilter(filter: MonitorFilter) {
|
|
116
|
+
this.filter = filter;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Hash is used to identify if the monitor has changed since the last time
|
|
121
|
+
* it was pushed to Kibana. Change is based on three factors:
|
|
122
|
+
* - Monitor configuration
|
|
123
|
+
* - Code changes
|
|
124
|
+
* - File path changes
|
|
125
|
+
*/
|
|
126
|
+
hash(): string {
|
|
127
|
+
const hash = createHash('sha256');
|
|
128
|
+
return hash
|
|
129
|
+
.update(JSON.stringify(this.config))
|
|
130
|
+
.update(this.content || '')
|
|
131
|
+
.update(this.source?.file || '')
|
|
132
|
+
.digest('base64');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
validate() {
|
|
136
|
+
const schedule = this.config.schedule;
|
|
137
|
+
if (ALLOWED_SCHEDULES.includes(schedule)) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const { config, source } = this;
|
|
141
|
+
let outer = bold(
|
|
142
|
+
`Invalid schedule: ${schedule}, allowed values are ${ALLOWED_SCHEDULES.join(
|
|
143
|
+
','
|
|
144
|
+
)}\n`
|
|
145
|
+
);
|
|
146
|
+
if (source) {
|
|
147
|
+
const inner = `* ${config.id} - ${source.file}:${source.line}:${source.column}\n`;
|
|
148
|
+
outer += indent(inner);
|
|
149
|
+
}
|
|
150
|
+
throw red(outer);
|
|
151
|
+
}
|
|
152
|
+
}
|
package/src/dsl/step.ts
CHANGED
|
@@ -23,16 +23,23 @@
|
|
|
23
23
|
*
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import { VoidCallback } from '../common_types';
|
|
26
|
+
import { Location, VoidCallback } from '../common_types';
|
|
27
27
|
|
|
28
28
|
export class Step {
|
|
29
29
|
name: string;
|
|
30
30
|
index: number;
|
|
31
31
|
callback: VoidCallback;
|
|
32
|
+
location?: Location;
|
|
32
33
|
|
|
33
|
-
constructor(
|
|
34
|
+
constructor(
|
|
35
|
+
name: string,
|
|
36
|
+
index: number,
|
|
37
|
+
callback: VoidCallback,
|
|
38
|
+
location: Location
|
|
39
|
+
) {
|
|
34
40
|
this.name = name;
|
|
35
41
|
this.index = index;
|
|
36
42
|
this.callback = callback;
|
|
43
|
+
this.location = location;
|
|
37
44
|
}
|
|
38
45
|
}
|