From dfa3651d0126bdf0fa99f0d3f3aff4fc7b46fac4 Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Fri, 29 Sep 2023 00:38:31 +0000 Subject: [PATCH 1/8] Fix the summarizer tests --- .../wrappers/summarizer/summarizer_test.go | 74 +++++++++++-------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/heartbeat/monitors/wrappers/summarizer/summarizer_test.go b/heartbeat/monitors/wrappers/summarizer/summarizer_test.go index 64472eb1c9a..610181e637f 100644 --- a/heartbeat/monitors/wrappers/summarizer/summarizer_test.go +++ b/heartbeat/monitors/wrappers/summarizer/summarizer_test.go @@ -32,15 +32,10 @@ import ( "github.com/elastic/elastic-agent-libs/mapstr" ) +var errDummy = fmt.Errorf("dummyerr") + func TestSummarizer(t *testing.T) { t.Parallel() - charToStatus := func(c uint8) monitorstate.StateStatus { - if c == 'u' { - return monitorstate.StatusUp - } else { - return monitorstate.StatusDown - } - } testURL := "https://example.net" // these tests use strings to describe sequences of events @@ -66,6 +61,15 @@ func TestSummarizer(t *testing.T) { 2, testURL, }, + { + "start down, stay down, then up", + 2, + "ddddu", + "ddddu", + "12121", + 5, + testURL, + }, { "start up, stay up", 2, @@ -126,29 +130,8 @@ func TestSummarizer(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - dummyErr := fmt.Errorf("dummyerr") - - // The job runs through each char in the status sequence and - // returns an error if it's set to 'd' - pos := 0 - job := func(event *beat.Event) (j []jobs.Job, retErr error) { - status := charToStatus(tt.statusSequence[pos]) - if status == monitorstate.StatusDown { - retErr = dummyErr - } - event.Fields = mapstr.M{ - "monitor": mapstr.M{ - "id": "test", - "status": string(status), - }, - } - - pos++ - return nil, retErr - } - tracker := monitorstate.NewTracker(monitorstate.NilStateLoader, false) - sf := stdfields.StdMonitorFields{ID: "testmon", Name: "testmon", Type: "http", MaxAttempts: uint16(tt.maxAttempts)} + job, tracker, sf := setupTest(tt.statusSequence, tt.maxAttempts) rcvdStatuses := "" rcvdStates := "" @@ -219,3 +202,36 @@ func TestSummarizer(t *testing.T) { }) } } + +func setupTest(statusSequence string, maxAttempts int) (job jobs.Job, tracker *monitorstate.Tracker, sf stdfields.StdMonitorFields) { + // The job runs through each char in the status sequence and + // returns an error if it's set to 'd' + pos := 0 + job = func(event *beat.Event) (j []jobs.Job, retErr error) { + status := charToStatus(statusSequence[pos]) + if status == monitorstate.StatusDown { + retErr = errDummy + } + event.Fields = mapstr.M{ + "monitor": mapstr.M{ + "id": "test", + "status": string(status), + }, + } + + pos++ + return nil, retErr + } + + tracker = monitorstate.NewTracker(monitorstate.NilStateLoader, false) + sf = stdfields.StdMonitorFields{ID: "testmon", Name: "testmon", Type: "http", MaxAttempts: uint16(maxAttempts)} + return job, tracker, sf +} + +func charToStatus(c uint8) monitorstate.StateStatus { + if c == 'u' { + return monitorstate.StatusUp + } else { + return monitorstate.StatusDown + } +} From 949343d4de96dabeb6ee3164de287d0f52bff6e5 Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Fri, 29 Sep 2023 00:56:23 +0000 Subject: [PATCH 2/8] tests are now red --- .../wrappers/summarizer/summarizer_test.go | 29 +++++++++++++++++-- x-pack/heartbeat/scenarios/basics_test.go | 7 ++++- .../heartbeat/scenarios/browserscenarios.go | 2 +- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/heartbeat/monitors/wrappers/summarizer/summarizer_test.go b/heartbeat/monitors/wrappers/summarizer/summarizer_test.go index 610181e637f..47db4737059 100644 --- a/heartbeat/monitors/wrappers/summarizer/summarizer_test.go +++ b/heartbeat/monitors/wrappers/summarizer/summarizer_test.go @@ -131,7 +131,7 @@ func TestSummarizer(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() - job, tracker, sf := setupTest(tt.statusSequence, tt.maxAttempts) + job, tracker, sf := setupHTTPJob(tt.statusSequence, tt.maxAttempts) rcvdStatuses := "" rcvdStates := "" @@ -203,7 +203,7 @@ func TestSummarizer(t *testing.T) { } } -func setupTest(statusSequence string, maxAttempts int) (job jobs.Job, tracker *monitorstate.Tracker, sf stdfields.StdMonitorFields) { +func setupHTTPJob(statusSequence string, maxAttempts int) (job jobs.Job, tracker *monitorstate.Tracker, sf stdfields.StdMonitorFields) { // The job runs through each char in the status sequence and // returns an error if it's set to 'd' pos := 0 @@ -228,6 +228,31 @@ func setupTest(statusSequence string, maxAttempts int) (job jobs.Job, tracker *m return job, tracker, sf } +func setupBrowserJob(statusSequence string, maxAttempts int) (job jobs.Job, tracker *monitorstate.Tracker, sf stdfields.StdMonitorFields) { + // The job runs through each char in the status sequence and + // returns an error if it's set to 'd' + pos := 0 + job = func(event *beat.Event) (j []jobs.Job, retErr error) { + status := charToStatus(statusSequence[pos]) + if status == monitorstate.StatusDown { + retErr = errDummy + } + event.Fields = mapstr.M{ + "monitor": mapstr.M{ + "id": "test", + "status": string(status), + }, + } + + pos++ + return nil, retErr + } + + tracker = monitorstate.NewTracker(monitorstate.NilStateLoader, false) + sf = stdfields.StdMonitorFields{ID: "testmon", Name: "testmon", Type: "browser", MaxAttempts: uint16(maxAttempts)} + return job, tracker, sf +} + func charToStatus(c uint8) monitorstate.StateStatus { if c == 'u' { return monitorstate.StatusUp diff --git a/x-pack/heartbeat/scenarios/basics_test.go b/x-pack/heartbeat/scenarios/basics_test.go index a8b39dbfaf1..2305b280114 100644 --- a/x-pack/heartbeat/scenarios/basics_test.go +++ b/x-pack/heartbeat/scenarios/basics_test.go @@ -115,7 +115,7 @@ func TestLightweightSummaries(t *testing.T) { func TestBrowserSummaries(t *testing.T) { t.Parallel() - scenarioDB.RunTag(t, "browser", func(t *testing.T, mtr *framework.MonitorTestRun, err error) { + scenarioDB.RunTagWithATwist(t, "browser-down", TwistMaxAttempts(2), func(t *testing.T, mtr *framework.MonitorTestRun, err error) { all := mtr.Events() lastEvent, firstEvents := all[len(all)-1], all[:len(all)-1] @@ -126,6 +126,11 @@ func TestBrowserSummaries(t *testing.T) { ), lastEvent.Fields) + monStatus, _ := lastEvent.GetValue("monitor.status") + summaryIface, _ := lastEvent.GetValue("summary") + summary := summaryIface.(*jobsummary.JobSummary) + require.Equal(t, string(summary.Status), monStatus, "expected summary status and mon status to be equal in event: %v", lastEvent.Fields) + for _, e := range firstEvents { summary, _ := e.GetValue("summary") require.Nil(t, summary) diff --git a/x-pack/heartbeat/scenarios/browserscenarios.go b/x-pack/heartbeat/scenarios/browserscenarios.go index 1760ef58750..e15a150db5f 100644 --- a/x-pack/heartbeat/scenarios/browserscenarios.go +++ b/x-pack/heartbeat/scenarios/browserscenarios.go @@ -51,7 +51,7 @@ func init() { framework.Scenario{ Name: "failing-browser", Type: "browser", - Tags: []string{"browser", "browser-inline", "down"}, + Tags: []string{"browser", "browser-inline", "down", "browser-down"}, Runner: func(t *testing.T) (config mapstr.M, meta framework.ScenarioRunMeta, close func(), err error) { err = os.Setenv("ELASTIC_SYNTHETICS_CAPABLE", "true") if err != nil { From 088c896f3ce95bcc852cd554c552221ccc30e548 Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Fri, 29 Sep 2023 01:13:29 +0000 Subject: [PATCH 3/8] Refine tests and fix retries --- .../wrappers/summarizer/plugstatestat.go | 35 +++++++++++-------- x-pack/heartbeat/scenarios/basics_test.go | 34 +++++++++++------- .../scenarios/framework/framework.go | 6 ++++ x-pack/heartbeat/scenarios/twists.go | 3 ++ 4 files changed, 52 insertions(+), 26 deletions(-) diff --git a/heartbeat/monitors/wrappers/summarizer/plugstatestat.go b/heartbeat/monitors/wrappers/summarizer/plugstatestat.go index f38c22d32ab..9cbc05f9350 100644 --- a/heartbeat/monitors/wrappers/summarizer/plugstatestat.go +++ b/heartbeat/monitors/wrappers/summarizer/plugstatestat.go @@ -56,20 +56,26 @@ func (ssp *BrowserStateStatusPlugin) EachEvent(event *beat.Event, jobErr error) } func (ssp *BrowserStateStatusPlugin) BeforeSummary(event *beat.Event) BeforeSummaryActions { + ssp.cssp.js.Status = monitorstate.StatusDown if ssp.cssp.js.Down == 0 { // Browsers don't have a prior increment of this, so set it to some // non-zero value ssp.cssp.js.Up = 1 + ssp.cssp.js.Status = monitorstate.StatusUp } - res := ssp.cssp.BeforeSummary(event) + res := ssp.cssp.BeforeSummary(event, true) - _, _ = event.PutValue("monitor.status", string(ssp.cssp.js.Status)) + if ssp.cssp.js.Status == monitorstate.StatusEmpty { + panic("Nil status") + } + + _, _ = event.PutValue("synthetics", mapstr.M{"type": "heartbeat/summary"}) return res } func (ssp *BrowserStateStatusPlugin) BeforeRetry() { - // noop + ssp.cssp.BeforeRetry() } // LightweightStateStatusPlugin encapsulates the writing of the primary fields used by the summary, @@ -104,11 +110,11 @@ func (ssp *LightweightStateStatusPlugin) EachEvent(event *beat.Event, jobErr err } func (ssp *LightweightStateStatusPlugin) BeforeSummary(event *beat.Event) BeforeSummaryActions { - return ssp.cssp.BeforeSummary(event) + return ssp.cssp.BeforeSummary(event, false) } func (ssp *LightweightStateStatusPlugin) BeforeRetry() { - // noop + ssp.cssp.BeforeRetry() } type commonSSP struct { @@ -136,12 +142,15 @@ func (ssp *commonSSP) BeforeEach(event *beat.Event, err error) { _, _ = event.PutValue("monitor.check_group", fmt.Sprintf("%s-%d", ssp.checkGroup, ssp.js.Attempt)) } -func (ssp *commonSSP) BeforeSummary(event *beat.Event) BeforeSummaryActions { +func (ssp *commonSSP) BeforeSummary(event *beat.Event, setSummary bool) BeforeSummaryActions { if ssp.js.Down > 0 { ssp.js.Status = monitorstate.StatusDown } else { ssp.js.Status = monitorstate.StatusUp } + if setSummary { + _, _ = event.PutValue("monitor.status", string(ssp.js.Status)) + } // Get the last status of this monitor, we use this later to // determine if a retry is needed @@ -162,15 +171,8 @@ func (ssp *commonSSP) BeforeSummary(event *beat.Event) BeforeSummaryActions { "summary": &jsCopy, "state": ms, } - if ssp.sf.Type == "browser" { - fields["synthetics"] = mapstr.M{"type": "heartbeat/summary"} - } - eventext.MergeEventFields(event, fields) - if retry { - // mutate the js into the state for the next attempt - ssp.js.BumpAttempt() - } + eventext.MergeEventFields(event, fields) logp.L().Debugf("attempt info: %v == %v && %d < %d", ssp.js.Status, lastStatus, ssp.js.Attempt, ssp.js.MaxAttempts) @@ -180,3 +182,8 @@ func (ssp *commonSSP) BeforeSummary(event *beat.Event) BeforeSummaryActions { return 0 } + +func (ssp *commonSSP) BeforeRetry() { + // mutate the js into the state for the next attempt + ssp.js.BumpAttempt() +} diff --git a/x-pack/heartbeat/scenarios/basics_test.go b/x-pack/heartbeat/scenarios/basics_test.go index 2305b280114..08794c12146 100644 --- a/x-pack/heartbeat/scenarios/basics_test.go +++ b/x-pack/heartbeat/scenarios/basics_test.go @@ -22,6 +22,7 @@ import ( "github.com/elastic/beats/v7/heartbeat/monitors/wrappers/monitorstate" "github.com/elastic/beats/v7/heartbeat/monitors/wrappers/summarizer/jobsummary" "github.com/elastic/beats/v7/heartbeat/monitors/wrappers/summarizer/summarizertesthelper" + "github.com/elastic/beats/v7/libbeat/beat" "github.com/elastic/beats/v7/x-pack/heartbeat/scenarios/framework" ) @@ -99,25 +100,22 @@ func TestLightweightUrls(t *testing.T) { func TestLightweightSummaries(t *testing.T) { t.Parallel() - scenarioDB.RunTag(t, "lightweight", func(t *testing.T, mtr *framework.MonitorTestRun, err error) { + scenarioDB.RunTagWithSeparateTwists(t, "lightweight", StdAttemptTwists, func(t *testing.T, mtr *framework.MonitorTestRun, err error) { all := mtr.Events() - lastEvent, firstEvents := all[len(all)-1], all[:len(all)-1] + lastEvent := all[len(all)-1] testslike.Test(t, SummaryValidatorForStatus(mtr.Meta.Status), lastEvent.Fields) - for _, e := range firstEvents { - summary, _ := e.GetValue("summary") - require.Nil(t, summary) - } + requireOneSummaryPerAttempt(t, all) }) } func TestBrowserSummaries(t *testing.T) { t.Parallel() - scenarioDB.RunTagWithATwist(t, "browser-down", TwistMaxAttempts(2), func(t *testing.T, mtr *framework.MonitorTestRun, err error) { + scenarioDB.RunTagWithSeparateTwists(t, "browser", StdAttemptTwists, func(t *testing.T, mtr *framework.MonitorTestRun, err error) { all := mtr.Events() - lastEvent, firstEvents := all[len(all)-1], all[:len(all)-1] + lastEvent := all[len(all)-1] testslike.Test(t, lookslike.Compose( @@ -131,13 +129,25 @@ func TestBrowserSummaries(t *testing.T) { summary := summaryIface.(*jobsummary.JobSummary) require.Equal(t, string(summary.Status), monStatus, "expected summary status and mon status to be equal in event: %v", lastEvent.Fields) - for _, e := range firstEvents { - summary, _ := e.GetValue("summary") - require.Nil(t, summary) - } + requireOneSummaryPerAttempt(t, all) + }) } +func requireOneSummaryPerAttempt(t *testing.T, events []*beat.Event) { + attemptCounter := uint16(1) + // ensure we only have one summary per attempt + for _, e := range events { + summaryIface, _ := e.GetValue("summary") + if summaryIface != nil { + summary := summaryIface.(*jobsummary.JobSummary) + require.Equal(t, attemptCounter, summary.Attempt) + require.LessOrEqual(t, summary.Attempt, summary.MaxAttempts) + attemptCounter++ + } + } +} + func TestRunFromOverride(t *testing.T) { t.Parallel() scenarioDB.RunAllWithATwist(t, TwistAddRunFrom, func(t *testing.T, mtr *framework.MonitorTestRun, err error) { diff --git a/x-pack/heartbeat/scenarios/framework/framework.go b/x-pack/heartbeat/scenarios/framework/framework.go index c4e3e54b5bc..c6dc0ae9ad6 100644 --- a/x-pack/heartbeat/scenarios/framework/framework.go +++ b/x-pack/heartbeat/scenarios/framework/framework.go @@ -214,6 +214,12 @@ func (sdb *ScenarioDB) RunTagWithATwist(t *testing.T, tagName string, twist *Twi } } +func (sdb *ScenarioDB) RunTagWithSeparateTwists(t *testing.T, tagName string, twists []*Twist, callback func(*testing.T, *MonitorTestRun, error)) { + for _, twist := range twists { + sdb.RunTagWithATwist(t, tagName, twist, callback) + } +} + type MonitorTestRun struct { StdFields stdfields.StdMonitorFields Meta ScenarioRunMeta diff --git a/x-pack/heartbeat/scenarios/twists.go b/x-pack/heartbeat/scenarios/twists.go index 5f4d1093020..a31d9980950 100644 --- a/x-pack/heartbeat/scenarios/twists.go +++ b/x-pack/heartbeat/scenarios/twists.go @@ -36,6 +36,9 @@ func TwistMultiRun(times int) *framework.Twist { }) } +// Test with both one and two twists +var StdAttemptTwists = []*framework.Twist{TwistMaxAttempts(1), TwistMaxAttempts(2)} + func TwistMaxAttempts(maxAttempts int) *framework.Twist { return framework.MakeTwist(fmt.Sprintf("run with %d max_attempts", maxAttempts), func(s framework.Scenario) framework.Scenario { s.Tags = append(s.Tags, "retry") From b9c0dc19223d4fafa4ba4157e97a7b00df659334 Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Fri, 29 Sep 2023 01:15:25 +0000 Subject: [PATCH 4/8] Revert unnecessary summarizer test changes --- .../wrappers/summarizer/summarizer_test.go | 99 ++++++------------- 1 file changed, 29 insertions(+), 70 deletions(-) diff --git a/heartbeat/monitors/wrappers/summarizer/summarizer_test.go b/heartbeat/monitors/wrappers/summarizer/summarizer_test.go index 47db4737059..64472eb1c9a 100644 --- a/heartbeat/monitors/wrappers/summarizer/summarizer_test.go +++ b/heartbeat/monitors/wrappers/summarizer/summarizer_test.go @@ -32,10 +32,15 @@ import ( "github.com/elastic/elastic-agent-libs/mapstr" ) -var errDummy = fmt.Errorf("dummyerr") - func TestSummarizer(t *testing.T) { t.Parallel() + charToStatus := func(c uint8) monitorstate.StateStatus { + if c == 'u' { + return monitorstate.StatusUp + } else { + return monitorstate.StatusDown + } + } testURL := "https://example.net" // these tests use strings to describe sequences of events @@ -61,15 +66,6 @@ func TestSummarizer(t *testing.T) { 2, testURL, }, - { - "start down, stay down, then up", - 2, - "ddddu", - "ddddu", - "12121", - 5, - testURL, - }, { "start up, stay up", 2, @@ -130,8 +126,29 @@ func TestSummarizer(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() + dummyErr := fmt.Errorf("dummyerr") + + // The job runs through each char in the status sequence and + // returns an error if it's set to 'd' + pos := 0 + job := func(event *beat.Event) (j []jobs.Job, retErr error) { + status := charToStatus(tt.statusSequence[pos]) + if status == monitorstate.StatusDown { + retErr = dummyErr + } + event.Fields = mapstr.M{ + "monitor": mapstr.M{ + "id": "test", + "status": string(status), + }, + } + + pos++ + return nil, retErr + } - job, tracker, sf := setupHTTPJob(tt.statusSequence, tt.maxAttempts) + tracker := monitorstate.NewTracker(monitorstate.NilStateLoader, false) + sf := stdfields.StdMonitorFields{ID: "testmon", Name: "testmon", Type: "http", MaxAttempts: uint16(tt.maxAttempts)} rcvdStatuses := "" rcvdStates := "" @@ -202,61 +219,3 @@ func TestSummarizer(t *testing.T) { }) } } - -func setupHTTPJob(statusSequence string, maxAttempts int) (job jobs.Job, tracker *monitorstate.Tracker, sf stdfields.StdMonitorFields) { - // The job runs through each char in the status sequence and - // returns an error if it's set to 'd' - pos := 0 - job = func(event *beat.Event) (j []jobs.Job, retErr error) { - status := charToStatus(statusSequence[pos]) - if status == monitorstate.StatusDown { - retErr = errDummy - } - event.Fields = mapstr.M{ - "monitor": mapstr.M{ - "id": "test", - "status": string(status), - }, - } - - pos++ - return nil, retErr - } - - tracker = monitorstate.NewTracker(monitorstate.NilStateLoader, false) - sf = stdfields.StdMonitorFields{ID: "testmon", Name: "testmon", Type: "http", MaxAttempts: uint16(maxAttempts)} - return job, tracker, sf -} - -func setupBrowserJob(statusSequence string, maxAttempts int) (job jobs.Job, tracker *monitorstate.Tracker, sf stdfields.StdMonitorFields) { - // The job runs through each char in the status sequence and - // returns an error if it's set to 'd' - pos := 0 - job = func(event *beat.Event) (j []jobs.Job, retErr error) { - status := charToStatus(statusSequence[pos]) - if status == monitorstate.StatusDown { - retErr = errDummy - } - event.Fields = mapstr.M{ - "monitor": mapstr.M{ - "id": "test", - "status": string(status), - }, - } - - pos++ - return nil, retErr - } - - tracker = monitorstate.NewTracker(monitorstate.NilStateLoader, false) - sf = stdfields.StdMonitorFields{ID: "testmon", Name: "testmon", Type: "browser", MaxAttempts: uint16(maxAttempts)} - return job, tracker, sf -} - -func charToStatus(c uint8) monitorstate.StateStatus { - if c == 'u' { - return monitorstate.StatusUp - } else { - return monitorstate.StatusDown - } -} From 01181f510edc82d31e594293d11c2bcf681284bb Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Fri, 29 Sep 2023 01:26:54 +0000 Subject: [PATCH 5/8] Various fixes and cleanups --- .../monitors/wrappers/summarizer/plugstatestat.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/heartbeat/monitors/wrappers/summarizer/plugstatestat.go b/heartbeat/monitors/wrappers/summarizer/plugstatestat.go index 9cbc05f9350..f17f6ea8254 100644 --- a/heartbeat/monitors/wrappers/summarizer/plugstatestat.go +++ b/heartbeat/monitors/wrappers/summarizer/plugstatestat.go @@ -64,11 +64,9 @@ func (ssp *BrowserStateStatusPlugin) BeforeSummary(event *beat.Event) BeforeSumm ssp.cssp.js.Status = monitorstate.StatusUp } - res := ssp.cssp.BeforeSummary(event, true) - - if ssp.cssp.js.Status == monitorstate.StatusEmpty { - panic("Nil status") - } + res := ssp.cssp.BeforeSummary(event) + // Browsers don't set this prior, so we set this here, as opposed to lightweight monitors + _, _ = event.PutValue("monitor.status", string(ssp.cssp.js.Status)) _, _ = event.PutValue("synthetics", mapstr.M{"type": "heartbeat/summary"}) return res @@ -110,7 +108,7 @@ func (ssp *LightweightStateStatusPlugin) EachEvent(event *beat.Event, jobErr err } func (ssp *LightweightStateStatusPlugin) BeforeSummary(event *beat.Event) BeforeSummaryActions { - return ssp.cssp.BeforeSummary(event, false) + return ssp.cssp.BeforeSummary(event) } func (ssp *LightweightStateStatusPlugin) BeforeRetry() { @@ -142,15 +140,12 @@ func (ssp *commonSSP) BeforeEach(event *beat.Event, err error) { _, _ = event.PutValue("monitor.check_group", fmt.Sprintf("%s-%d", ssp.checkGroup, ssp.js.Attempt)) } -func (ssp *commonSSP) BeforeSummary(event *beat.Event, setSummary bool) BeforeSummaryActions { +func (ssp *commonSSP) BeforeSummary(event *beat.Event) BeforeSummaryActions { if ssp.js.Down > 0 { ssp.js.Status = monitorstate.StatusDown } else { ssp.js.Status = monitorstate.StatusUp } - if setSummary { - _, _ = event.PutValue("monitor.status", string(ssp.js.Status)) - } // Get the last status of this monitor, we use this later to // determine if a retry is needed From 017cea7d5cb9440f8f59500dbbb767c5f6586ad1 Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Fri, 29 Sep 2023 02:27:16 +0000 Subject: [PATCH 6/8] Make linter happy --- x-pack/heartbeat/scenarios/twists.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/heartbeat/scenarios/twists.go b/x-pack/heartbeat/scenarios/twists.go index a31d9980950..ad24b8a42f9 100644 --- a/x-pack/heartbeat/scenarios/twists.go +++ b/x-pack/heartbeat/scenarios/twists.go @@ -36,7 +36,7 @@ func TwistMultiRun(times int) *framework.Twist { }) } -// Test with both one and two twists +// StdAttemptTwists is a list of real world attempt numbers, that is to say both one and two twists. var StdAttemptTwists = []*framework.Twist{TwistMaxAttempts(1), TwistMaxAttempts(2)} func TwistMaxAttempts(maxAttempts int) *framework.Twist { From f0ca00379133a08eeca89f2e925b21dfaa86da16 Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Fri, 29 Sep 2023 13:02:48 +0000 Subject: [PATCH 7/8] Improve logging --- heartbeat/monitors/wrappers/summarizer/plugstatestat.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/heartbeat/monitors/wrappers/summarizer/plugstatestat.go b/heartbeat/monitors/wrappers/summarizer/plugstatestat.go index f17f6ea8254..145df2f63b6 100644 --- a/heartbeat/monitors/wrappers/summarizer/plugstatestat.go +++ b/heartbeat/monitors/wrappers/summarizer/plugstatestat.go @@ -169,7 +169,7 @@ func (ssp *commonSSP) BeforeSummary(event *beat.Event) BeforeSummaryActions { eventext.MergeEventFields(event, fields) - logp.L().Debugf("attempt info: %v == %v && %d < %d", ssp.js.Status, lastStatus, ssp.js.Attempt, ssp.js.MaxAttempts) + logp.L().Debugf("attempt info: current(%v) == lastStatus(%v) && attempts(%d < %d)", ssp.js.Status, lastStatus, ssp.js.Attempt, ssp.js.MaxAttempts) if retry { return RetryBeforeSummary From 890a4dc41f084bb257f7c69dc61c8a489e00eec7 Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Fri, 29 Sep 2023 13:30:09 +0000 Subject: [PATCH 8/8] PR feedback --- heartbeat/monitors/wrappers/summarizer/plugstatestat.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/heartbeat/monitors/wrappers/summarizer/plugstatestat.go b/heartbeat/monitors/wrappers/summarizer/plugstatestat.go index 145df2f63b6..62a1c8ee5b8 100644 --- a/heartbeat/monitors/wrappers/summarizer/plugstatestat.go +++ b/heartbeat/monitors/wrappers/summarizer/plugstatestat.go @@ -56,12 +56,10 @@ func (ssp *BrowserStateStatusPlugin) EachEvent(event *beat.Event, jobErr error) } func (ssp *BrowserStateStatusPlugin) BeforeSummary(event *beat.Event) BeforeSummaryActions { - ssp.cssp.js.Status = monitorstate.StatusDown if ssp.cssp.js.Down == 0 { // Browsers don't have a prior increment of this, so set it to some // non-zero value ssp.cssp.js.Up = 1 - ssp.cssp.js.Status = monitorstate.StatusUp } res := ssp.cssp.BeforeSummary(event)