Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Heartbeat] Add sandbox options, defaulted to off #24172

Merged
merged 5 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d

- Add mime type detection for http responses. {pull}22976[22976]
- Bundle synthetics deps with heartbeat docker image. {pull}23274[23274]
- Add --sandbox option for browser monitor. {pull}24172[24172]

*Journalbeat*

Expand Down
9 changes: 7 additions & 2 deletions x-pack/heartbeat/monitors/browser/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,21 @@ func create(name string, cfg *common.Config) (p plugin.Plugin, err error) {
return plugin.Plugin{}, err
}

extraArgs := []string{}
if ss.suiteCfg.Sandbox {
extraArgs = append(extraArgs, "--sandbox")
}

var j jobs.Job
if src, ok := ss.InlineSource(); ok {
j = synthexec.InlineJourneyJob(context.TODO(), src, ss.Params())
j = synthexec.InlineJourneyJob(context.TODO(), src, ss.Params(), extraArgs...)
} else {
j = func(event *beat.Event) ([]jobs.Job, error) {
err := ss.Fetch()
if err != nil {
return nil, fmt.Errorf("could not fetch for suite job: %w", err)
}
sj, err := synthexec.SuiteJob(context.TODO(), ss.Workdir(), ss.Params())
sj, err := synthexec.SuiteJob(context.TODO(), ss.Workdir(), ss.Params(), extraArgs...)
if err != nil {
return nil, err
}
Expand Down
9 changes: 8 additions & 1 deletion x-pack/heartbeat/monitors/browser/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import (
"github.com/elastic/beats/v7/x-pack/heartbeat/monitors/browser/source"
)

func DefaultConfig() *Config {
return &Config{
Sandbox: false,
}
}

type Config struct {
Schedule string `config:"schedule"`
Params map[string]interface{} `config:"params"`
Expand All @@ -19,7 +25,8 @@ type Config struct {
// Name is optional for lightweight checks but required for browsers
Name string `config:"name"`
// Id is optional for lightweight checks but required for browsers
Id string `config:"id"`
Id string `config:"id"`
Sandbox bool `config:"sandbox"`
}

var ErrNameRequired = fmt.Errorf("config 'name' must be specified for this monitor")
Expand Down
2 changes: 1 addition & 1 deletion x-pack/heartbeat/monitors/browser/suite_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type SyntheticSuite struct {
func NewSuite(rawCfg *common.Config) (*SyntheticSuite, error) {
ss := &SyntheticSuite{
rawCfg: rawCfg,
suiteCfg: &Config{},
suiteCfg: DefaultConfig(),
}
err := rawCfg.Unpack(ss.suiteCfg)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions x-pack/heartbeat/monitors/browser/synthexec/synthexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import (
const debugSelector = "synthexec"

// SuiteJob will run a single journey by name from the given suite.
func SuiteJob(ctx context.Context, suitePath string, params common.MapStr) (jobs.Job, error) {
func SuiteJob(ctx context.Context, suitePath string, params common.MapStr, extraArgs ...string) (jobs.Job, error) {
// Run the command in the given suitePath, use '.' as the first arg since the command runs
// in the correct dir
newCmd, err := suiteCommandFactory(suitePath, ".", "--screenshots")
newCmd, err := suiteCommandFactory(suitePath, append(extraArgs, ".", "--screenshots")...)
if err != nil {
return nil, err
}
Expand All @@ -55,9 +55,9 @@ func suiteCommandFactory(suitePath string, args ...string) (func() *exec.Cmd, er
}

// InlineJourneyJob returns a job that runs the given source as a single journey.
func InlineJourneyJob(ctx context.Context, script string, params common.MapStr) jobs.Job {
func InlineJourneyJob(ctx context.Context, script string, params common.MapStr, extraArgs ...string) jobs.Job {
newCmd := func() *exec.Cmd {
return exec.Command("elastic-synthetics", "--inline", "--screenshots")
return exec.Command("elastic-synthetics", append(extraArgs, "--inline", "--screenshots")...)
}

return startCmdJob(ctx, newCmd, &script, params)
Expand Down