Skip to content

Commit

Permalink
[Heartbeat] Report first synth error on summary (#24194) (#24222)
Browse files Browse the repository at this point in the history
Fixes elastic/kibana#92066

Prior to this for the summary.error field for browser events we'd
report the last encountered error. We now report the first. This
prevents the issue where on a failing run the synthetics library
considers an exit status of 1 to be an error. This will always be the
case when a step fails, meaning that the last error will always be a
status code error stepping on the actual step error.

(cherry picked from commit c5821d9)
  • Loading branch information
andrewvc authored Feb 25, 2021
1 parent b603334 commit 0231262
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 6 additions & 4 deletions x-pack/heartbeat/monitors/browser/synthexec/enrich.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type journeyEnricher struct {
journey *Journey
checkGroup string
errorCount int
lastError error
firstError error
stepCount int
// The first URL we visit is the URL for this journey, which is set on the summary event.
// We store the URL fields here for use on the summary event.
Expand Down Expand Up @@ -69,7 +69,7 @@ func (je *journeyEnricher) enrich(event *beat.Event, se *SynthEvent) error {
// Record start and end so we can calculate journey duration accurately later
switch se.Type {
case "journey/start":
je.lastError = nil
je.firstError = nil
je.checkGroup = makeUuid()
je.journey = se.Journey
je.start = event.Timestamp
Expand Down Expand Up @@ -121,7 +121,9 @@ func (je *journeyEnricher) enrichSynthEvent(event *beat.Event, se *SynthEvent) e
if se.Error != nil {
jobErr = stepError(se.Error)
je.errorCount++
je.lastError = jobErr
if je.firstError == nil {
je.firstError = jobErr
}
}

return jobErr
Expand Down Expand Up @@ -154,7 +156,7 @@ func (je *journeyEnricher) createSummary(event *beat.Event) error {
"down": down,
},
})
return je.lastError
return je.firstError
}

return fmt.Errorf("journey did not finish executing, %d steps ran", je.stepCount)
Expand Down
7 changes: 6 additions & 1 deletion x-pack/heartbeat/monitors/browser/synthexec/enrich_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func TestJourneyEnricher(t *testing.T) {
Name: "my-errname",
Stack: "my\nerr\nstack",
}
otherErr := &SynthError{
Message: "last-errmsg",
Name: "last-errname",
Stack: "last\nerr\nstack",
}
journeyStart := &SynthEvent{
Type: "journey/start",
TimestampEpochMicros: 1000,
Expand Down Expand Up @@ -66,7 +71,7 @@ func TestJourneyEnricher(t *testing.T) {
makeStepEvent("step/start", 21, "Step2", 1, "", nil),
makeStepEvent("step/end", 30, "Step2", 1, url2, syntherr),
makeStepEvent("step/start", 31, "Step3", 1, "", nil),
makeStepEvent("step/end", 40, "Step3", 1, url3, nil),
makeStepEvent("step/end", 40, "Step3", 1, url3, otherErr),
journeyEnd,
}

Expand Down

0 comments on commit 0231262

Please sign in to comment.