-
Notifications
You must be signed in to change notification settings - Fork 5k
[Heartbeat] Add managed status reporter at monitor factory level #41077
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ import ( | |
| "github.com/elastic/beats/v7/heartbeat/monitors/wrappers" | ||
| "github.com/elastic/beats/v7/heartbeat/scheduler" | ||
| "github.com/elastic/beats/v7/libbeat/beat" | ||
| "github.com/elastic/beats/v7/libbeat/management/status" | ||
| ) | ||
|
|
||
| // ErrMonitorDisabled is returned when the monitor plugin is marked as disabled. | ||
|
|
@@ -71,6 +72,12 @@ type Monitor struct { | |
| stats plugin.RegistryRecorder | ||
|
|
||
| monitorStateTracker *monitorstate.Tracker | ||
| statusReporter status.StatusReporter | ||
| } | ||
|
|
||
| // SetStatusReporter | ||
| func (m *Monitor) SetStatusReporter(statusReporter status.StatusReporter) { | ||
| m.statusReporter = statusReporter | ||
| } | ||
|
|
||
| // String prints a description of the monitor in a threadsafe way. It is important that this use threadsafe | ||
|
|
@@ -175,6 +182,9 @@ func newMonitorUnsafe( | |
|
|
||
| logp.L().Error(fullErr) | ||
| p.Jobs = []jobs.Job{func(event *beat.Event) ([]jobs.Job, error) { | ||
| // if statusReporter is set, as it is for running managed-mode, update the input status | ||
| // to failed, specifying the error | ||
| m.updateStatus(status.Failed, fmt.Sprintf("monitor could not be started: %s, err: %s", m.stdFields.ID, fullErr)) | ||
|
Member
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. Reading this Could this cause other HB to stop and also other monitors from running? Is this intended?
Contributor
Author
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.
It probably won't (it doesn't, as of now). Even if that were the case, since the status is scoped at monitor level, it should only filter the failed integrations, but I'm speculating here. There are also multiple status layers, this change only affects the stream (not even the integration) status.
Member
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. I was worried if it could stop the other monitors. But if thats not the case, I am not super inclined towards changing this. |
||
| return nil, fullErr | ||
| }} | ||
|
|
||
|
|
@@ -237,6 +247,7 @@ func (m *Monitor) Start() { | |
|
|
||
| m.stats.StartMonitor(int64(m.endpoints)) | ||
| m.state = MON_STARTED | ||
| m.updateStatus(status.Running, "") | ||
| } | ||
|
|
||
| // Stop stops the monitor without freeing it in global dedup | ||
|
|
@@ -262,4 +273,11 @@ func (m *Monitor) Stop() { | |
|
|
||
| m.stats.StopMonitor(int64(m.endpoints)) | ||
| m.state = MON_STOPPED | ||
| m.updateStatus(status.Stopped, "") | ||
| } | ||
|
|
||
| func (m *Monitor) updateStatus(status status.Status, msg string) { | ||
| if m.statusReporter != nil { | ||
| m.statusReporter.UpdateStatus(status, msg) | ||
| } | ||
| } | ||
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.
Since its set on the Monitor level, what happens if multiple monitors were configured, does the errors get accumulated or there is upper limit to how its shown in the UI ?
Uh oh!
There was an error while loading. Please reload this page.
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.
Every monitor will map 1:1 to an agent integration, which Fleet UI already shows individually:
