Skip to content

Commit

Permalink
Add required comments to heartbeat monitors (elastic#8316)
Browse files Browse the repository at this point in the history
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 28977fb)
  • Loading branch information
andrewvc committed Sep 19, 2018
1 parent c5dba9d commit e21e596
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
3 changes: 3 additions & 0 deletions heartbeat/monitors/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
12 changes: 4 additions & 8 deletions heartbeat/monitors/pluginconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -44,7 +40,7 @@ func pluginInfo(config *common.Config) (MonitorPluginInfo, error) {
}

if !mpi.Enabled {
return mpi, PluginDisabledError{}
return mpi, ErrPluginDisabled
}

return mpi, nil
Expand Down

0 comments on commit e21e596

Please sign in to comment.