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

Allow for long log lines #265

Merged
merged 5 commits into from
Nov 13, 2023
Merged

Conversation

luoxiaohei
Copy link
Contributor

This pull request introduces a new feature to the ClientConfig in the client.go. The main change involves the addition of a LogBufferSize field, which will serve as the buffer size for reading stderr logs.

Currently, the stdErrBufferSize is set to a default value of 64 KB. When a log line exceeds this size, the client will not perform json unmarshal and subsequent processing for that line. This behavior can be unfriendly for certain use cases that involve lengthy logs.

To address this limitation, the proposed solution is to add the LogBufferSize field to the ClientConfig, allowing users to customize their own buffer size when creating a client. If the user doesn't specify a value, the default of 64 KB will be used to maintain compatibility with the current implementation.

An alternative approach would be to handle oversized logs by creating a new buffer to retain truncated data, concatenating it with historical data on the next read, and then proceeding with the complete log unmarshal. However, this method introduces added complexity and could lead to performance overhead in scenarios where logs consistently exceed the buffer size.

Considering simplicity and ease of implementation, the configuration-based solution is preferred. Users can now effortlessly fine-tune the buffer size to suit their specific logging needs.

@hashicorp-cla
Copy link

hashicorp-cla commented Jul 26, 2023

CLA assistant check
All committers have signed the CLA.

@luoxiaohei
Copy link
Contributor Author

@tomhjp Excuse me, Can you help me check this pr? Do you have any suggestions?

@tomhjp
Copy link
Contributor

tomhjp commented Sep 21, 2023

Hey @luoxiaohei - my plate is pretty full atm, but just wanted to say this looks like something we should be able to land and I'll try to revisit it soon. Thanks for putting this together, I can see it's been very thoughtfully constructed.

@luoxiaohei
Copy link
Contributor Author

Hey @luoxiaohei - my plate is pretty full atm, but just wanted to say this looks like something we should be able to land and I'll try to revisit it soon. Thanks for putting this together, I can see it's been very thoughtfully constructed.

Thanks for your positive feedback on my pr, I look forward to seeing it merged soon.

@tomhjp
Copy link
Contributor

tomhjp commented Oct 25, 2023

Thinking out loud a bit, an alternative solution would be to allow lines that cross the buffer threshold to build up in memory and deserialise them once continuation is false. After all, there's no fundamental reason why we can't deserialise the long lines, it's just not what the current implementation does. However, that would allow plugins to make clients consume arbitrary amounts of memory by printing arbitrary amounts of data to stderr, which seems like an undesirable property to introduce into a relatively stable and widely used library.

Instead, this PR allows clients to opt into behaviour that increases memory consumption, and still keeps a hard cap on it at the increased level. It's more fiddly because now clients have to be aware of the maximum log size they expect from a plugin, but also safer so I think the correct decision. Does that reasoning track with you @luoxiaohei, or am I missing an opportunity to simplify here?

@luoxiaohei
Copy link
Contributor Author

@tomhjp Yes, your reasoning tracks with me. I think the configurable option is a good balance between flexibility and safety.

Copy link
Contributor

@tomhjp tomhjp left a comment

Choose a reason for hiding this comment

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

Thanks! I just re-read the PR description and saw you already discussed my previous question 🤦‍♂️

Looks good, but one naming nit and I'd like to make sure we very explicitly cover the intent of the change in unit tests.

client.go Outdated Show resolved Hide resolved
client_test.go Outdated Show resolved Hide resolved
…ing test

- Renamed `LogBufferSize` to `PluginLogBufferSize` to better reflect its purpose.
- Updated all references of `LogBufferSize` to `PluginLogBufferSize`.
- Added a new test `TestClient_logStderrParseJSON` to verify the parsing of JSON formatted logs.
@luoxiaohei
Copy link
Contributor Author

@tomhjp I've refining the naming and enhancing the unit tests to explicitly cover the intent of the changes. Please take another look when you have a moment. Thanks!

Copy link
Contributor

@tomhjp tomhjp left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@tomhjp tomhjp merged commit 7c313e4 into hashicorp:main Nov 13, 2023
1 check passed
@tomhjp tomhjp mentioned this pull request Nov 13, 2023
Copy link

@Sec32fun32 Sec32fun32 left a comment

Choose a reason for hiding this comment

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

Sec32fun32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants