Skip to content

Commit

Permalink
Heartbeat: control network throttling in synthetics (#28462)
Browse files Browse the repository at this point in the history
* Heartbeat: control network throttling in synthetics

* Update heartbeat/docs/monitors/monitor-browser.asciidoc

Co-authored-by: Andrew Cholakian <andrew@andrewvc.com>

Co-authored-by: Andrew Cholakian <andrew@andrewvc.com>
  • Loading branch information
vigneshshanmugam and andrewvc committed Oct 19, 2021
1 parent d2569fd commit af602c2
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
30 changes: 29 additions & 1 deletion heartbeat/docs/monitors/monitor-browser.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand All @@ -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`
Expand Down
1 change: 1 addition & 0 deletions x-pack/heartbeat/monitors/browser/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
10 changes: 10 additions & 0 deletions x-pack/heartbeat/monitors/browser/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 15 additions & 0 deletions x-pack/heartbeat/monitors/browser/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit af602c2

Please sign in to comment.