From bd31c34b1c283a45a57581107b653faacad01bf0 Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Thu, 27 Sep 2018 10:25:20 -0500 Subject: [PATCH] Add required comments to heartbeat monitors (#8316) (#8362) Some of these functions needed comments to keep inline with go style guides. I also simplified one error by using errors.New instead of a custom error struct. (cherry picked from commit 28977fb440342b7ba56e205be87bfdaada96ad97) --- heartbeat/monitors/monitor.go | 3 +++ heartbeat/monitors/pluginconf.go | 12 ++++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/heartbeat/monitors/monitor.go b/heartbeat/monitors/monitor.go index 5e08bb77e1f..b371e48cf07 100644 --- a/heartbeat/monitors/monitor.go +++ b/heartbeat/monitors/monitor.go @@ -215,6 +215,7 @@ func (m *Monitor) makeWatchTasks(monitorPlugin pluginBuilder) error { return nil } +// Start starts the monitor's execution using its configured scheduler. func (m *Monitor) Start() { m.internalsMtx.Lock() defer m.internalsMtx.Unlock() @@ -228,6 +229,8 @@ func (m *Monitor) Start() { } } +// Stop stops the Monitor's execution in its configured scheduler. +// This is safe to call even if the Monitor was never started. func (m *Monitor) Stop() { m.internalsMtx.Lock() defer m.internalsMtx.Unlock() diff --git a/heartbeat/monitors/pluginconf.go b/heartbeat/monitors/pluginconf.go index 8f9bbc58b70..9f7ea10886b 100644 --- a/heartbeat/monitors/pluginconf.go +++ b/heartbeat/monitors/pluginconf.go @@ -18,19 +18,15 @@ package monitors import ( - "fmt" - "github.com/pkg/errors" "github.com/elastic/beats/libbeat/common" ) -type PluginDisabledError struct{} - -func (e PluginDisabledError) Error() string { - return fmt.Sprintf("Monitor not loaded, plugin is disabled") -} +// ErrPluginDisabled is returned when the monitor plugin is marked as disabled. +var ErrPluginDisabled = errors.New("Monitor not loaded, plugin is disabled") +// MonitorPluginInfo represents the generic configuration options around a monitor plugin. type MonitorPluginInfo struct { Type string `config:"type" validate:"required"` Enabled bool `config:"enabled"` @@ -44,7 +40,7 @@ func pluginInfo(config *common.Config) (MonitorPluginInfo, error) { } if !mpi.Enabled { - return mpi, PluginDisabledError{} + return mpi, ErrPluginDisabled } return mpi, nil