Skip to content

Commit

Permalink
[Heartbeat] Fix exit on disabled monitor
Browse files Browse the repository at this point in the history
Fixes a bug where when `enabled: false` was set on a monitor heartbeat
would refuse to start.

Fixes elastic#22665
  • Loading branch information
andrewvc committed Dec 1, 2020
1 parent e390658 commit 8a2c85b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
7 changes: 7 additions & 0 deletions heartbeat/beater/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"time"

"github.com/elastic/beats/v7/heartbeat/monitors/stdfields"

"github.com/elastic/beats/v7/heartbeat/hbregistry"

"github.com/pkg/errors"
Expand Down Expand Up @@ -127,8 +129,13 @@ func (bt *Heartbeat) RunStaticMonitors(b *beat.Beat) error {
for _, cfg := range bt.config.Monitors {
created, err := factory.Create(b.Publisher, cfg)
if err != nil {
if err == stdfields.ErrPluginDisabled {
continue // don't stop loading monitors just because they're disabled
}

return errors.Wrap(err, "could not create monitor")
}

created.Start()
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion heartbeat/monitors/stdfields/stdfields.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

// ErrPluginDisabled is returned when the monitor plugin is marked as disabled.
var ErrPluginDisabled = errors.New("Monitor not loaded, plugin is disabled")
var ErrPluginDisabled = errors.New("monitor not loaded, plugin is disabled")

type ServiceFields struct {
Name string `config:"name"`
Expand Down
24 changes: 24 additions & 0 deletions heartbeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@ def test_base(self):
self.wait_until(lambda: self.log_contains("heartbeat is running"))
heartbeat_proc.check_kill_and_wait()

def test_disabled(self):
"""
Basic test against a disabled monitor
"""

config = {
"monitors": [
{
"type": "http",
"enabled": "false",
"urls": ["http://localhost:9200"],
}
]
}

self.render_config_template(
path=os.path.abspath(self.working_dir) + "/log/*",
**config
)

heartbeat_proc = self.start_beat()
self.wait_until(lambda: self.log_contains("heartbeat is running"))
heartbeat_proc.check_kill_and_wait()

def test_fields_under_root(self):
"""
Basic test with fields and tags in monitor
Expand Down

0 comments on commit 8a2c85b

Please sign in to comment.