Skip to content

Commit

Permalink
[Heartbeat] Dedupe screenshots / Extra Args (backport #25808) (#26192)
Browse files Browse the repository at this point in the history
* [Heartbeat] Dedupe screenshots / Extra Args (#25808)

(cherry picked from commit db6738e)

# Conflicts:
#	heartbeat/_meta/fields.common.yml
#	heartbeat/docs/fields.asciidoc
#	heartbeat/include/fields.go
#	x-pack/heartbeat/include/fields.go

* Fix merge

* Update fields docs

Co-authored-by: Andrew Cholakian <[email protected]>
  • Loading branch information
mergify[bot] and andrewvc authored Jun 8, 2021
1 parent 8a79a3c commit 35d41be
Show file tree
Hide file tree
Showing 15 changed files with 467 additions and 123 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Deprecated the cyberark module (replaced by cyberarkpas). {issue}25261[25261] {pull}25505[25505]

*Heartbeat*
- Add support for screenshot blocks and use newer synthetics flags that only works in newer synthetics betas. {pull}25808[25808]

*Journalbeat*

Expand Down
63 changes: 63 additions & 0 deletions heartbeat/_meta/fields.common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,69 @@
type: text
- name: stack
type: text
- name: screenshot_ref
type: group
dynamic: false
fields:
- name: width
type: integer
description: Width of the full screenshot in pixels.
- name: height
type: integer
description: Height of the full screenshot in pixels
- name: blocks
type: group
description: Attributes representing individual screenshot blocks. Only hash is indexed since it's the only one we'd query on.
fields:
- name: hash
type: keyword
description: Hash that uniquely identifies this image by content. Corresponds to block document id.
- name: browser
type: group
fields:
- name: experience
type: group
fields:
- name: name
type: keyword
- name: type
type: text
description: >
denotes the 'mark' event
- name: start
type: long
description: >
offset of time relative to journey start in milliseconds
- name: user_timing
type: group
fields:
- name: name
type: keyword
- name: type
type: text
description: >
could be one of mark or measure event types.
- name: start
type: long
description: >
offset of time relative to journey start in milliseconds
- name: end
type: long
description: >
offset of time relative to journey start in milliseconds
- name: layout_shift
type: group
fields:
- name: name
type: keyword
- name: score
type: integer
- name: exists
type: boolean
description: >
flag that indicates if there was any layout shift events
present on the page.
- key: http
title: "HTTP monitor"
description:
Expand Down
126 changes: 126 additions & 0 deletions heartbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -10497,6 +10497,132 @@ type: text
--
*`synthetics.screenshot_ref.width`*::
+
--
Width of the full screenshot in pixels.
type: integer
--
*`synthetics.screenshot_ref.height`*::
+
--
Height of the full screenshot in pixels
type: integer
--
[float]
=== blocks
Attributes representing individual screenshot blocks. Only hash is indexed since it's the only one we'd query on.
*`synthetics.screenshot_ref.blocks.hash`*::
+
--
Hash that uniquely identifies this image by content. Corresponds to block document id.
type: keyword
--
*`synthetics.browser.experience.name`*::
+
--
type: keyword
--
*`synthetics.browser.experience.type`*::
+
--
denotes the 'mark' event
type: text
--
*`synthetics.browser.experience.start`*::
+
--
offset of time relative to journey start in milliseconds
type: long
--
*`synthetics.browser.user_timing.name`*::
+
--
type: keyword
--
*`synthetics.browser.user_timing.type`*::
+
--
could be one of mark or measure event types.
type: text
--
*`synthetics.browser.user_timing.start`*::
+
--
offset of time relative to journey start in milliseconds
type: long
--
*`synthetics.browser.user_timing.end`*::
+
--
offset of time relative to journey start in milliseconds
type: long
--
*`synthetics.browser.layout_shift.name`*::
+
--
type: keyword
--
*`synthetics.browser.layout_shift.score`*::
+
--
type: integer
--
*`synthetics.browser.layout_shift.exists`*::
+
--
flag that indicates if there was any layout shift events present on the page.
type: boolean
--
[[exported-fields-tcp]]
== TCP layer fields
Expand Down
12 changes: 12 additions & 0 deletions heartbeat/docs/monitors/monitor-browser.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,15 @@ Example configuration:
local:
path: "/path/to/synthetics/journeys"
-------------------------------------------------------------------------------

[float]
[[monitor-browser-sandbox]]
==== `sandbox`

Set this option to `true` to enable the normally disabled chromium sandbox. Defaults to false.

[float]
[[monitor-browser-synthetics-args]]
==== `synthetics_args`

Extra arguments to pass to the synthetics agent package. Takes a list of strings.
2 changes: 1 addition & 1 deletion heartbeat/include/fields.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion x-pack/heartbeat/include/fields.go

Large diffs are not rendered by default.

38 changes: 4 additions & 34 deletions x-pack/heartbeat/monitors/browser/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@
package browser

import (
"context"
"fmt"
"os"
"os/user"
"sync"

"github.com/elastic/beats/v7/heartbeat/monitors/jobs"
"github.com/elastic/beats/v7/heartbeat/monitors/plugin"
"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/logp"
"github.com/elastic/beats/v7/x-pack/heartbeat/monitors/browser/synthexec"
)

func init() {
Expand All @@ -25,14 +21,14 @@ func init() {

var showExperimentalOnce = sync.Once{}

var NotSyntheticsCapableError = fmt.Errorf("synthetic monitors cannot be created outside the official elastic docker image")
var ErrNotSyntheticsCapableError = fmt.Errorf("synthetic monitors cannot be created outside the official elastic docker image")

func create(name string, cfg *common.Config) (p plugin.Plugin, err error) {
// We don't want users running synthetics in environments that don't have the required GUI libraries etc, so we check
// this flag. When we're ready to support the many possible configurations of systems outside the docker environment
// we can remove this check.
if os.Getenv("ELASTIC_SYNTHETICS_CAPABLE") != "true" {
return plugin.Plugin{}, NotSyntheticsCapableError
return plugin.Plugin{}, ErrNotSyntheticsCapableError
}

showExperimentalOnce.Do(func() {
Expand All @@ -47,36 +43,10 @@ func create(name string, cfg *common.Config) (p plugin.Plugin, err error) {
return plugin.Plugin{}, fmt.Errorf("script monitors cannot be run as root! Current UID is %s", curUser.Uid)
}

ss, err := NewSuite(cfg)
s, err := NewSuite(cfg)
if err != nil {
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(), 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(), extraArgs...)
if err != nil {
return nil, err
}
return sj(event)
}
}

return plugin.Plugin{
Jobs: []jobs.Job{j},
Close: ss.Close,
Endpoints: 1,
}, nil
return s.plugin(), nil
}
5 changes: 3 additions & 2 deletions x-pack/heartbeat/monitors/browser/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ 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"`
Sandbox bool `config:"sandbox"`
Id string `config:"id"`
Sandbox bool `config:"sandbox"`
SyntheticsArgs []string `config:"synthetics_args"`
}

var ErrNameRequired = fmt.Errorf("config 'name' must be specified for this monitor")
Expand Down
Loading

0 comments on commit 35d41be

Please sign in to comment.