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

Implement logic for disabled groups #5295

Merged
merged 1 commit into from
Oct 3, 2017
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
7 changes: 7 additions & 0 deletions libbeat/kibana/testdata/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
Contains common beat fields available in all event types.
fields:

- name: group_disabled
type: group
enabled: false
fields:
- name: message
type: text

- name: beat.name
description: >
The name of the Beat sending the log messages. If the Beat name is
Expand Down
4 changes: 3 additions & 1 deletion libbeat/kibana/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ func (t *Transformer) transformFields(commonFields common.Fields, path string) {
}

if f.Type == "group" {
t.transformFields(f.Fields, f.Path)
if f.Enabled == nil || *f.Enabled {
t.transformFields(f.Fields, f.Path)
}
} else {
// set default values (as done in python script)
t.keys[f.Path] = true
Expand Down
68 changes: 68 additions & 0 deletions libbeat/kibana/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,71 @@ func TestTransformFieldFormatMap(t *testing.T) {
assert.Equal(t, test.expected, out, fmt.Sprintf("Failed for idx %v", idx))
}
}
func TestTransformGroupAndEnabled(t *testing.T) {
tests := []struct {
commonFields common.Fields
expected []string
}{
{
commonFields: common.Fields{common.Field{Name: "context", Path: "something"}},
expected: []string{"context"},
},
{
commonFields: common.Fields{
common.Field{
Name: "context",
Type: "group",
Fields: common.Fields{
common.Field{Name: "type", Type: ""},
common.Field{
Name: "metric",
Type: "group",
Fields: common.Fields{
common.Field{Name: "object"},
},
},
},
},
},
expected: []string{"context.type", "context.metric.object"},
},
{
commonFields: common.Fields{
common.Field{Name: "enabledField"},
common.Field{Name: "disabledField", Enabled: &falsy}, //enabled is ignored for Type!=group
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I wonder if for this case we should even return an error as we already know it's false? Or is this only for Kibana?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only for kibana

common.Field{
Name: "enabledGroup",
Type: "group",
Enabled: &truthy,
Fields: common.Fields{
common.Field{Name: "type", Type: ""},
},
},
common.Field{
Name: "context",
Type: "group",
Enabled: &falsy,
Fields: common.Fields{
common.Field{Name: "type", Type: ""},
common.Field{
Name: "metric",
Type: "group",
Fields: common.Fields{
common.Field{Name: "object"},
},
},
},
},
},
expected: []string{"enabledField", "disabledField", "enabledGroup.type"},
},
}
for idx, test := range tests {
trans := NewTransformer("name", "title", test.commonFields)
out := trans.TransformFields()["fields"].([]common.MapStr)
assert.Equal(t, len(test.expected)+ctMetaData, len(out))
for i, e := range test.expected {
assert.Equal(t, e, out[i]["name"], fmt.Sprintf("Failed for idx %v", idx))
}
}
}