Skip to content

Commit

Permalink
[Heartbeat] Fix enabled flag usage in case of streams (#33293)
Browse files Browse the repository at this point in the history
Fixes usage of Enabled incase of data streams

Fixes #33270
  • Loading branch information
shahzad31 authored Oct 10, 2022
1 parent 8dfa4d4 commit 7bddf80
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ https://github.com/elastic/beats/compare/v8.2.0\...main[Check the HEAD diff]
- Fix handling of empty array in httpjson input. {pull}32001[32001]

*Heartbeat*
- Fix broken disable feature for kibana configured monitors. {pull}33293[33293]


*Metricbeat*
Expand Down
8 changes: 4 additions & 4 deletions heartbeat/monitors/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ func (NoopRunner) Stop() {

// Create makes a new Runner for a new monitor with the given Config.
func (f *RunnerFactory) Create(p beat.Pipeline, c *conf.C) (cfgfile.Runner, error) {
if !c.Enabled() {
return NoopRunner{}, nil
}

c, err := stdfields.UnnestStream(c)
if err != nil {
return nil, err
}

if !c.Enabled() {
return NoopRunner{}, nil
}

configEditor, err := newCommonPublishConfigs(f.info, f.beatLocation, c)
if err != nil {
return nil, err
Expand Down
42 changes: 28 additions & 14 deletions heartbeat/monitors/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,24 +207,38 @@ func TestPreProcessors(t *testing.T) {
}

func TestDisabledMonitor(t *testing.T) {
confMap := map[string]interface{}{
"type": "test",
"enabled": "false",
testConfigs := []map[string]interface{}{
{
"type": "test",
"enabled": "false",
"schedule": "@every 10s",
},
{
"streams": []map[string]interface{}{
{
"type": "test",
"enabled": "false",
"schedule": "@every 10s",
},
},
},
}

conf, err := config.NewConfigFrom(confMap)
require.NoError(t, err)
for _, confMap := range testConfigs {
conf, err := config.NewConfigFrom(confMap)
require.NoError(t, err)

reg, built, closed := mockPluginsReg()
f, sched, fClose := makeMockFactory(reg)
defer fClose()
defer sched.Stop()
runner, err := f.Create(&MockPipeline{}, conf)
require.NoError(t, err)
require.IsType(t, runner, NoopRunner{})
reg, built, closed := mockPluginsReg()
f, sched, fClose := makeMockFactory(reg)
defer fClose()
defer sched.Stop()
runner, err := f.Create(&MockPipeline{}, conf)
require.NoError(t, err)
require.IsType(t, NoopRunner{}, runner)

require.Equal(t, 0, built.Load())
require.Equal(t, 0, closed.Load())
require.Equal(t, 0, built.Load())
require.Equal(t, 0, closed.Load())
}
}

func TestDuplicateMonitorIDs(t *testing.T) {
Expand Down

0 comments on commit 7bddf80

Please sign in to comment.