-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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] Fix missing monitor status on 1 of 2 attempts #36704
Changes from 5 commits
dfa3651
949343d
088c896
b9c0dc1
01181f5
7bc02fa
017cea7
a51b909
f0ca003
890a4dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,20 +56,24 @@ 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) | ||
|
||
// 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"}) | ||
vigneshshanmugam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return res | ||
} | ||
|
||
func (ssp *BrowserStateStatusPlugin) BeforeRetry() { | ||
// noop | ||
ssp.cssp.BeforeRetry() | ||
} | ||
|
||
// LightweightStateStatusPlugin encapsulates the writing of the primary fields used by the summary, | ||
|
@@ -108,7 +112,7 @@ func (ssp *LightweightStateStatusPlugin) BeforeSummary(event *beat.Event) Before | |
} | ||
|
||
func (ssp *LightweightStateStatusPlugin) BeforeRetry() { | ||
// noop | ||
ssp.cssp.BeforeRetry() | ||
} | ||
|
||
type commonSSP struct { | ||
|
@@ -162,15 +166,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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add last vs current status and attempts. Felt more descriptive -
|
||
|
||
|
@@ -180,3 +177,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() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We now run these tests with both 1 and 2 max_attempts |
||
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.RunTag(t, "browser", func(t *testing.T, mtr *framework.MonitorTestRun, err error) { | ||
scenarioDB.RunTagWithSeparateTwists(t, "browser", StdAttemptTwists, func(t *testing.T, mtr *framework.MonitorTestRun, err error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We now run these tests with both 1 and 2 max_attempts |
||
all := mtr.Events() | ||
lastEvent, firstEvents := all[len(all)-1], all[:len(all)-1] | ||
lastEvent := all[len(all)-1] | ||
|
||
testslike.Test(t, | ||
lookslike.Compose( | ||
|
@@ -126,13 +124,30 @@ func TestBrowserSummaries(t *testing.T) { | |
), | ||
lastEvent.Fields) | ||
|
||
for _, e := range firstEvents { | ||
summary, _ := e.GetValue("summary") | ||
require.Nil(t, summary) | ||
} | ||
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) | ||
|
||
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) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we already set the Status here, it can be safely removed from the common BeforeSummary -
beats/heartbeat/monitors/wrappers/summarizer/plugstatestat.go
Lines 144 to 148 in a51b909
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do it the other way and leave that in common since we still need that for common