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

Fix module config defaults in light modules #12674

Merged
merged 2 commits into from
Jun 27, 2019
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
22 changes: 12 additions & 10 deletions metricbeat/mb/lightmetricset.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,23 @@ func (m *LightMetricSet) Registration(r *Register) (MetricSetRegistration, error
// baseModule does the configuration overrides in the base module configuration
// taking into account the light metric set default configurations
func (m *LightMetricSet) baseModule(from Module) (*BaseModule, error) {
baseModule := BaseModule{
name: m.Module,
}
var err error
// Set defaults
if baseModule.rawConfig, err = common.NewConfigFrom(m.Input.Defaults); err != nil {
// Initialize config using input defaults as raw config
rawConfig, err := common.NewConfigFrom(m.Input.Defaults)
if err != nil {
return nil, errors.Wrap(err, "invalid input defaults")
}

// Copy values from user configuration
if err = from.UnpackConfig(baseModule.rawConfig); err != nil {
if err = from.UnpackConfig(rawConfig); err != nil {
return nil, errors.Wrap(err, "failed to copy values from user configuration")
}
// Update module configuration
if err = baseModule.UnpackConfig(&baseModule.config); err != nil {
return nil, errors.Wrap(err, "failed to set module configuration")

// Create the base module
baseModule, err := newBaseModuleFromConfig(rawConfig)
if err != nil {
return nil, errors.Wrap(err, "failed to create base module")
}
baseModule.name = m.Module

return &baseModule, nil
}
7 changes: 4 additions & 3 deletions x-pack/metricbeat/mb/lightmodules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ func TestNewModuleFromConfig(t *testing.T) {
"normal module": {
config: common.MapStr{"module": "foo", "metricsets": []string{"bar"}},
expectedOption: "default",
expectedPeriod: mb.DefaultModuleConfig().Period,
},
"light module": {
config: common.MapStr{"module": "service", "metricsets": []string{"metricset"}},
Expand Down Expand Up @@ -247,9 +246,11 @@ func TestNewModuleFromConfig(t *testing.T) {
require.True(t, ok)
assert.Equal(t, c.expectedOption, ms.Option)
assert.Equal(t, c.expectedQuery, ms.Module().Config().Query)
if c.expectedPeriod > 0 {
assert.Equal(t, c.expectedPeriod, ms.Module().Config().Period)
expectedPeriod := c.expectedPeriod
if expectedPeriod == 0 {
expectedPeriod = mb.DefaultModuleConfig().Period
}
assert.Equal(t, expectedPeriod, ms.Module().Config().Period)
})
}
})
Expand Down