-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Allow ConcatFields for nodes of type object #10959
Conversation
Return false if field contains a nodes parent key but not the node itself.
jenkins, retest this please |
libbeat/common/field.go
Outdated
@@ -304,7 +344,7 @@ func ConcatFields(a, b Fields) (Fields, error) { | |||
|
|||
// check for duplicates | |||
for _, k := range b.GetKeys() { | |||
if a.HasNode(k) { | |||
if !a.CanConcat(k) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the only caller of HasNode
, can that be removed now? Can this implementation replace the previous one instead of introducing a new function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't remove it as it is an exported method, and we should backport the bugfix to 6.x (best 6.6).
@@ -27,6 +27,58 @@ import ( | |||
"github.com/elastic/go-ucfg/yaml" | |||
) | |||
|
|||
func TestFieldsHasNode(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this actually supposed to test CanConcat
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, will change.
There were no explicit tests for HasNode
so I added them. Will add dedicated CanConcat
tests though to make it more clear.
@elastic/beats could someone please review and lmk if you are fine with backporting to 7.0, 6.7 and 6.6 branches? |
libbeat/common/field.go
Outdated
@@ -292,6 +292,46 @@ func (f Fields) getKeys(namespace string) []string { | |||
return keys | |||
} | |||
|
|||
// canConcat checks if inside fields the given node can be concatenated. | |||
// If the node already exists, this is only allowed for nodes of type object. | |||
func (f Fields) CanConcat(key string) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we clarify the comment for when fields are concatenable. How about naming it conflicts
? This is what the for loop on ConcatFields
does, look for conflicts between 2 field arrays.
canConcat
checks that no node is reachable by key AND that the common prefix between all fields and the path given by key resolves into an object-node. Did I get this right?
We should return an error describing why key
conflicts with f
. Moving the loop from ConcatFields into a separate loop allows us to cleanly collect N errors into a multierror.
Do we need to export CanConcat
? We seem to export too many symbols already. Let's try to not export symbols unless we know we will need them.
libbeat/common/field.go
Outdated
//// It's the last key to compare | ||
if len(keys) == 0 { | ||
return false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
////
- lets not add extra whitespace between for and if statements or beginning of function body. In most cases indentation should be enough to distinguish blocks.
Logic LGTM. |
Jenkins, test this. |
@urso I followed your suggestions, please have a look again. |
Note: Metricbeat windows tests didn't run due to build failure. All other tests have been green. |
Checks if given field conflicts with current fields. Fixes an error where `append_fields` could not add valid field.
Checks if given field conflicts with current fields. Fixes an error where `append_fields` could not add valid field.
Checks if given field conflicts with current fields. Fixes an error where `append_fields` could not add valid field.
…11094) Checks if given field conflicts with current fields. Fixes an error where `append_fields` could not add valid field.
Allow
ConcatFields
to concatenate two fields when the first field contains a node's parent key but not the node itself and it is of type object.Current behaviour (simplified):
Behaviour after merging this PR:
This needs to be backported to
>=6.6
as it leads to a concrete bug in APM, see apm-server#1959