Skip to content

Commit

Permalink
[Synthetics] allow disabling throttling for project monitors (#148669)
Browse files Browse the repository at this point in the history
## Summary

Resolves #148344

Allows for disabling throttling by adjusting the request types for
project monitors

### Testing
1. Checkout the synthetics agent PR. Be sure to link the development
version of the package to the your test project directory via `npm
link`. If you don't already have a test directory, create one via `npm
run init`.
2. In a test project monitor, set `monitor.use({ throttling: false })`. 
3. Ensure no errors are reported back to the synthetics agent. 
4. In Uptime, navigate to the edit monitor page for the monitor you're
testing. Scroll down to Advanced browser options. Open the accordion and
confirm throttling is disabled
<img width="1752" alt="Screen Shot 2023-01-10 at 2 20 24 PM"
src="https://user-images.githubusercontent.com/11356435/211642237-de2d0ba3-2822-4ad4-beb4-a4404b9caae9.png">
  • Loading branch information
dominiqueclarke committed Jan 11, 2023
1 parent c7f91b2 commit 04c5e65
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import * as t from 'io-ts';
import { AlertConfigsCodec } from './alert_config';
import { ScreenshotOptionCodec } from './monitor_configs';

export const ProjectMonitorThrottlingConfigCodec = t.interface({
download: t.number,
upload: t.number,
latency: t.number,
});
export const ProjectMonitorThrottlingConfigCodec = t.union([
t.interface({
download: t.number,
upload: t.number,
latency: t.number,
}),
t.boolean,
]);

export const ProjectMonitorCodec = t.intersection([
t.interface({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ describe('browser normalizers', () => {
name: 'test-name-3',
content: 'test content 3',
schedule: 10,
throttling: {
latency: 18,
upload: 15,
download: 10,
},
throttling: false,
params,
playwrightOptions,
locations: ['us_central', 'us_east'],
Expand Down Expand Up @@ -261,11 +257,11 @@ describe('browser normalizers', () => {
'service.name': '',
'source.project.content': 'test content 3',
tags: ['tag3', 'tag4'],
'throttling.config': '10d/15u/18l',
'throttling.download_speed': '10',
'throttling.is_enabled': true,
'throttling.latency': '18',
'throttling.upload_speed': '15',
'throttling.config': '5d/3u/20l',
'throttling.download_speed': '5',
'throttling.is_enabled': false,
'throttling.latency': '20',
'throttling.upload_speed': '3',
type: 'browser',
project_id: projectId,
namespace: 'test_space',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,27 @@ export const getNormalizeBrowserFields = ({
[ConfigKey.FORM_MONITOR_TYPE]: FormMonitorType.MULTISTEP,
[ConfigKey.SOURCE_PROJECT_CONTENT]:
monitor.content || defaultFields[ConfigKey.SOURCE_PROJECT_CONTENT],
[ConfigKey.THROTTLING_CONFIG]: monitor.throttling
? `${monitor.throttling.download}d/${monitor.throttling.upload}u/${monitor.throttling.latency}l`
: defaultFields[ConfigKey.THROTTLING_CONFIG],
[ConfigKey.THROTTLING_CONFIG]:
typeof monitor.throttling !== 'boolean'
? `${monitor.throttling?.download}d/${monitor.throttling?.upload}u/${monitor.throttling?.latency}l`
: defaultFields[ConfigKey.THROTTLING_CONFIG],
[ConfigKey.DOWNLOAD_SPEED]: `${
monitor.throttling?.download || defaultFields[ConfigKey.DOWNLOAD_SPEED]
typeof monitor.throttling !== 'boolean'
? monitor.throttling?.download
: defaultFields[ConfigKey.DOWNLOAD_SPEED]
}`,
[ConfigKey.UPLOAD_SPEED]: `${
monitor.throttling?.upload || defaultFields[ConfigKey.UPLOAD_SPEED]
typeof monitor.throttling !== 'boolean'
? monitor.throttling?.upload
: defaultFields[ConfigKey.UPLOAD_SPEED]
}`,
[ConfigKey.IS_THROTTLING_ENABLED]:
Boolean(monitor.throttling) ?? defaultFields[ConfigKey.IS_THROTTLING_ENABLED],
[ConfigKey.LATENCY]: `${monitor.throttling?.latency || defaultFields[ConfigKey.LATENCY]}`,
[ConfigKey.LATENCY]: `${
typeof monitor.throttling !== 'boolean'
? monitor.throttling?.latency
: defaultFields[ConfigKey.LATENCY]
}`,
[ConfigKey.IGNORE_HTTPS_ERRORS]:
monitor.ignoreHTTPSErrors || defaultFields[ConfigKey.IGNORE_HTTPS_ERRORS],
[ConfigKey.SCREENSHOTS]: monitor.screenshot || defaultFields[ConfigKey.SCREENSHOTS],
Expand Down
43 changes: 43 additions & 0 deletions x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,49 @@ export default function ({ getService }: FtrProviderContext) {
}
});

it('project monitors - allows throttling false for browser monitors', async () => {
const successfulMonitors = [projectMonitors.monitors[0]];
const project = `test-project-${uuid.v4()}`;

try {
const { body } = await supertest
.put(API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project))
.set('kbn-xsrf', 'true')
.send({
...projectMonitors,
monitors: [{ ...projectMonitors.monitors[0], throttling: false }],
})
.expect(200);
expect(body).eql({
updatedMonitors: [],
createdMonitors: successfulMonitors.map((monitor) => monitor.id),
failedMonitors: [],
});

for (const monitor of successfulMonitors) {
const journeyId = monitor.id;
const createdMonitorsResponse = await supertest
.get(API_URLS.SYNTHETICS_MONITORS)
.query({ filter: `${syntheticsMonitorType}.attributes.journey_id: ${journeyId}` })
.set('kbn-xsrf', 'true')
.expect(200);

const decryptedCreatedMonitor = await supertest
.get(`${API_URLS.SYNTHETICS_MONITORS}/${createdMonitorsResponse.body.monitors[0].id}`)
.set('kbn-xsrf', 'true')
.expect(200);

expect(decryptedCreatedMonitor.body.attributes['throttling.is_enabled']).to.eql(false);
}
} finally {
await Promise.all([
successfulMonitors.map((monitor) => {
return deleteMonitor(monitor.id, project);
}),
]);
}
});

it('project monitors - handles http monitors', async () => {
const kibanaVersion = await kibanaServer.version.get();
const successfulMonitors = [httpProjectMonitors.monitors[1]];
Expand Down

0 comments on commit 04c5e65

Please sign in to comment.