Skip to content
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 exit on disabled monitor #22829

Merged
merged 3 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
*Heartbeat*

- The `service_name` monitor option is being replaced with `service.name` which is more correct. We will support the old option till 8.0. {pull}20330[20330]
- Fix exit on monitors with `enabled: false` {pull}22829[22829]

*Journalbeat*

Expand Down
9 changes: 7 additions & 2 deletions heartbeat/beater/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import (
"fmt"
"time"

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

"github.com/pkg/errors"

"github.com/elastic/beats/v7/heartbeat/config"
"github.com/elastic/beats/v7/heartbeat/hbregistry"
"github.com/elastic/beats/v7/heartbeat/monitors"
"github.com/elastic/beats/v7/heartbeat/monitors/stdfields"
"github.com/elastic/beats/v7/heartbeat/scheduler"
"github.com/elastic/beats/v7/libbeat/autodiscover"
"github.com/elastic/beats/v7/libbeat/beat"
Expand Down Expand Up @@ -127,8 +127,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