Skip to content

Commit

Permalink
[Heartbeat] Fix zip monitors (#33723)
Browse files Browse the repository at this point in the history
* [Heartbeat] Fix zip monitors by changing the check group after summary docs

Fixes #33698

* Add null chuck

* More robust check groups

* Add nil check

* Make linter happy

* Remove accidental config

* Fix heartbeat.yml

* Update x-pack/heartbeat/monitors/browser/synthexec/enrich.go

Co-authored-by: Emilio Alvarez Piñeiro <95703246+emilioalvap@users.noreply.github.com>

* Add changelog

Co-authored-by: Emilio Alvarez Piñeiro <95703246+emilioalvap@users.noreply.github.com>
(cherry picked from commit 453dfcb)
  • Loading branch information
andrewvc authored and mergify[bot] committed Nov 21, 2022
1 parent 1f1ccd8 commit 415b0bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ https://github.com/elastic/beats/compare/v8.2.0\...main[Check the HEAD diff]
- Fix Google workspace pagination and document ID generation. {pull}33666[33666]

*Heartbeat*
- Fix broken zip URL monitors. NOTE: Zip URL Monitors will be removed in version 8.7 and replaced with project monitors. {pull}33723[33723]
- Fix bug affecting let's encrypt and other users of cross-signed certs, where cert expiration was incorrectly calculated. {issue}33215[33215]
- Fix broken disable feature for kibana configured monitors. {pull}33293[33293]
- Fix states client support for output options. {pull}33405[33405]
Expand Down
22 changes: 13 additions & 9 deletions x-pack/heartbeat/monitors/browser/synthexec/enrich.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import (
type enricher func(event *beat.Event, se *SynthEvent) error

type streamEnricher struct {
je *journeyEnricher
sFields stdfields.StdMonitorFields
checkGroup string
je *journeyEnricher
journeyCount int
sFields stdfields.StdMonitorFields
checkGroup string
}

func newStreamEnricher(sFields stdfields.StdMonitorFields) *streamEnricher {
Expand All @@ -39,8 +40,15 @@ func (senr *streamEnricher) enrich(event *beat.Event, se *SynthEvent) error {
senr.je = newJourneyEnricher(senr)
}

eventext.MergeEventFields(event, map[string]interface{}{"monitor": map[string]interface{}{"check_group": senr.checkGroup}})
// TODO: Remove this when zip monitors are removed and we have 1:1 monitor / journey
if se != nil && se.Type == JourneyStart {
senr.journeyCount++
if senr.journeyCount > 1 {
senr.checkGroup = makeUuid()
}
}

eventext.MergeEventFields(event, map[string]interface{}{"monitor": map[string]interface{}{"check_group": senr.checkGroup}})
return senr.je.enrich(event, se)
}

Expand Down Expand Up @@ -153,7 +161,7 @@ func (je *journeyEnricher) enrichSynthEvent(event *beat.Event, se *SynthEvent) e

eventext.MergeEventFields(event, se.ToMap())

if je.urlFields == nil {
if len(je.urlFields) == 0 {
if urlFields, err := event.GetValue("url"); err == nil {
if ufMap, ok := urlFields.(mapstr.M); ok {
je.urlFields = ufMap
Expand Down Expand Up @@ -206,10 +214,6 @@ func (je *journeyEnricher) createSummary(event *beat.Event) error {
if je.journeyComplete {
return je.error
}

// create a new check group for the next journey
je.streamEnricher.checkGroup = makeUuid()

return fmt.Errorf("journey did not finish executing, %d steps ran: %w", je.stepCount, je.error)
}

Expand Down

0 comments on commit 415b0bc

Please sign in to comment.