From af602c2b0df38bfc3fb5cfcfabcab1145b558022 Mon Sep 17 00:00:00 2001 From: Vignesh Shanmugam Date: Tue, 19 Oct 2021 14:56:37 -0700 Subject: [PATCH] Heartbeat: control network throttling in synthetics (#28462) * Heartbeat: control network throttling in synthetics * Update heartbeat/docs/monitors/monitor-browser.asciidoc Co-authored-by: Andrew Cholakian Co-authored-by: Andrew Cholakian --- .../docs/monitors/monitor-browser.asciidoc | 30 ++++++++++++++++++- x-pack/heartbeat/monitors/browser/config.go | 1 + x-pack/heartbeat/monitors/browser/suite.go | 10 +++++++ .../heartbeat/monitors/browser/suite_test.go | 15 ++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/heartbeat/docs/monitors/monitor-browser.asciidoc b/heartbeat/docs/monitors/monitor-browser.asciidoc index aa1a2ee1ceb..b01fa4437f4 100644 --- a/heartbeat/docs/monitors/monitor-browser.asciidoc +++ b/heartbeat/docs/monitors/monitor-browser.asciidoc @@ -164,7 +164,7 @@ Example configuration: ==== `ignore_https_errors` Set this option to `true` to disable TLS/SSL validation in the synthetics browser. This is useful for testing -sites that use self-signed certs. This option can also be used to test certs from non-standard CAs, +sites that use self-signed certs. This option can also be used to test certs from non-standard CAs, though you will no longer get errors if there is anything wrong with the certificate. @@ -175,6 +175,34 @@ though you will no longer get errors if there is anything wrong with the certifi Set this option to `true` to enable the normally disabled chromium sandbox. Defaults to false. +[float] +[[monitor-browser-throttling]] +==== `throttling` + +Set this option to control the network throttling. By default, all journeys are +run with 5Mbps download, 3Mbps upload and 20ms latency which emulates a standard +Cabel connection. + +Users can control the throttling parameters, Below is an example of emulating a +3G connection with 1.6Mbps download, 750Kbps upload and 150ms round trip time. + +[source,yaml] +------------------------------------------------------------------------------- +- type: browser + schedule: '@every 1m' + throttling: "1.6d/0.75u/150l" +------------------------------------------------------------------------------- + +Network throttling can be completely disabled by passing `false` + +[source,yaml] +------------------------------------------------------------------------------- +- type: browser + schedule: '@every 1m' + throttling: false +------------------------------------------------------------------------------- + + [float] [[monitor-browser-filter-journeys]] ==== `filter_journeys` diff --git a/x-pack/heartbeat/monitors/browser/config.go b/x-pack/heartbeat/monitors/browser/config.go index 339c11f181a..a0ac61def25 100644 --- a/x-pack/heartbeat/monitors/browser/config.go +++ b/x-pack/heartbeat/monitors/browser/config.go @@ -29,6 +29,7 @@ type Config struct { // Id is optional for lightweight checks but required for browsers Id string `config:"id"` Sandbox bool `config:"sandbox"` + Throttling interface{} `config:"throttling"` Screenshots string `config:"screenshots"` SyntheticsArgs []string `config:"synthetics_args"` FilterJourneys synthexec.FilterJourneyConfig `config:"filter_journeys"` diff --git a/x-pack/heartbeat/monitors/browser/suite.go b/x-pack/heartbeat/monitors/browser/suite.go index 0347f419ab5..aff137baeca 100644 --- a/x-pack/heartbeat/monitors/browser/suite.go +++ b/x-pack/heartbeat/monitors/browser/suite.go @@ -85,6 +85,16 @@ func (s *Suite) extraArgs() []string { if s.suiteCfg.Screenshots != "" { extraArgs = append(extraArgs, "--screenshots", s.suiteCfg.Screenshots) } + if s.suiteCfg.Throttling != nil { + switch t := s.suiteCfg.Throttling.(type) { + case bool: + if !t { + extraArgs = append(extraArgs, "--no-throttling") + } + case string: + extraArgs = append(extraArgs, "--throttling", fmt.Sprintf("%v", s.suiteCfg.Throttling)) + } + } return extraArgs } diff --git a/x-pack/heartbeat/monitors/browser/suite_test.go b/x-pack/heartbeat/monitors/browser/suite_test.go index 5ac5946a0d9..db495e676fa 100644 --- a/x-pack/heartbeat/monitors/browser/suite_test.go +++ b/x-pack/heartbeat/monitors/browser/suite_test.go @@ -142,6 +142,21 @@ func TestExtraArgs(t *testing.T) { &Config{Sandbox: true}, []string{"--sandbox"}, }, + { + "throttling truthy", + &Config{Throttling: true}, + nil, + }, + { + "disable throttling", + &Config{Throttling: false}, + []string{"--no-throttling"}, + }, + { + "override throttling", + &Config{Throttling: "10d/3u/20l"}, + []string{"--throttling", "10d/3u/20l"}, + }, { "ignore_https_errors", &Config{IgnoreHTTPSErrors: true},