-
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
Fix flattened data_stream.* fields under Elastic-Agent #36607
Conversation
If the data_stream is not flattened, Beats will receive it twice, in the Config.Source and as DataStream, that is the normal behaviour when the Elastic-Agent is managed by Fleet and was causing a duplicated key error. This commit fixes that by only returning the error if the values in Config.Source and DataStream are different. The tests now cover this case.
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
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 think the root cause is likely that the Elastic Agent itself doesn't parse the flattened variant into the DataStream protobuf structure.
The point of that DataStream object is so that inputs don't actually have to parse the yaml, it is pre-parsed by the Elastic Agent. Doing this in the Elastic Agent also avoids requiring each input to know about and handle the syntax variations, they should just be able to look at the DataStream
object as an abstraction for the YAML.
There should be no difference in the protocol messaging regardless of which syntax is used in the underlying configuration.
// If the data_stream is not flattened, Beats will receive | ||
// it twice, in the Config.Source and as DataStream, that is the | ||
// normal behaviour when the Elastic-Agent is managed by Fleet. | ||
// So we also add the DataStream here to make sure there will be | ||
// no conflict. |
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 because the DataStream
object from the Elastic Agent doesn't parse the flattened variant? There is no reason for these two cases to be different in the protocol.
It's good to defend against this problem, but the protocol should be consistent or other developers are going to have this exact same bug.
I think we should follow up and fix this in the agent as well so that there is no inconsistency here.
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 because the DataStream object from the Elastic Agent doesn't parse the flattened variant?
Yes. If I recall correctly, the Agent parses it directly into the Protobuf type that does not support the flattened syntax.
It's good to defend against this problem, but the protocol should be consistent or other developers are going to have this exact same bug.
I think we should follow up and fix this in the agent as well so that there is no inconsistency here.
Should we then revert the original commit supporting flattened keys on Beats and re-implement it on Elastic-Agent?
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.
Should we then revert the original commit supporting flattened keys on Beats and re-implement it on Elastic-Agent?
Yes, we need to change the agent as well or every input is going to need to handle these two cases which is definitely result in bugs.
@@ -118,15 +118,15 @@ func deDotDataStream(raw dataStreamAndSource) (*proto.DataStream, error) { | |||
return nil, fmt.Errorf("cannot unpack source field into struct: %w", err) | |||
} | |||
|
|||
if ds.Dataset != "" && tmp.DataStream.Dataset != "" { | |||
if ds.Dataset != "" && tmp.DataStream.Dataset != "" && (ds.Dataset != tmp.DataStream.Dataset) { |
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.
The error message here isn't really right anymore, the key is supposed to be in both places. The only error is if they don't match.
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.
If they're the same it's not a problem, that's how the Elastic-Agent sends the data when the data_stream
object is not flattened.
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.
The error is duplicated key 'datastream.dataset
but the key being in both places actually the correct and expected result. The error now is only if they don't match, which the Elastic Agent should guarantee is impossible because the DataStream
object is parsed out of the Source
on the agent side but being defensive is fine.
Co-authored-by: Craig MacKenzie <[email protected]>
This pull request is now in conflicts. Could you fix it? 🙏
|
Closing as we decided to revert the commit that introduced the bug and re-implement it in Elastic-Agent. Revert PR: #36610 |
Proposed commit message
If the data_stream is not flattened, Beats will receive it twice, in the Config.Source and as DataStream, that is the normal behaviour when the Elastic-Agent is managed by Fleet and was causing a duplicated key error.
This commit fixes that by only returning the error if the values in Config.Source and DataStream are different.
The tests now cover this case.
Checklist
- [ ] I have made corresponding changes to the documentation- [ ] I have made corresponding change to the default configuration files- [ ] I have added an entry inCHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.## Author's Checklist## How to test this PR locally## Related issuesCloses elastic/elastic-agent#3191
## Use cases## Screenshots## Logs