Skip to content

feat: ensure that log batches don't exceed 1MiB in logSender #12048

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

Merged
merged 1 commit into from
Feb 9, 2024

Conversation

spikecurtis
Copy link
Contributor

@spikecurtis spikecurtis commented Feb 7, 2024

Protobuf messages are designed to be about 1MiB or less, so this PR ensures that even if we get a lot of logs or logs with huge payloads we don't send more than 1MiB at a time.

We straight up drop logs that themselves exceed 1MiB, and batch up logs so that each request is less than 1MiB if we have a lot of small logs.

agent/logs.go Outdated
const (
flushInterval = time.Second
logOutputMaxBytes = 1 << 20 // 1MiB
overheadPerLog = 21 // found by testing
Copy link
Member

Choose a reason for hiding this comment

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

We should probably also have an upper bound of buffered logs since these will take up memory, or alternatively, store logs on disk until they can be sent.

If something goes wrong with a command, there's really no telling how much it will spit out, it could be KiB's or it could be GiB's (in extreme cases). We also have limits in place in the API that limit the output to 1 MiB, although I can't recall the details if we store both the head and tail end of logs or simply cutoff at 1 MiB.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a bad idea. Can address in a follow on PR.

agent/logs.go Outdated
break
}
req.Logs = append(req.Logs, log)
n++
Copy link
Member

Choose a reason for hiding this comment

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

I think this change here demonstrates a downside of using PR stacking too much. I don't think it's a good idea to split up an implementation like this, especially a new one (I might be of a different opinion for something much bigger).

Here is a change that introduces more advanced logic in a place where I left a simple suggestion in the previous PR. I think that comment applies here too (as in we don't need a clone of the slice, we can utilize the backing array/append semantics). But based on the comment from my previous PR, this may be easily overlooked due to the change in this one.

agent/logs.go Outdated
if len(log.Output) > logOutputMaxBytes {
logger.Warn(ctx, "dropping log line that exceeds our limit")
n++
continue
Copy link
Member

Choose a reason for hiding this comment

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

How about truncating instead of dropping entirely?

@spikecurtis spikecurtis force-pushed the spike/10534-log-sender branch from 0f99947 to 15855f4 Compare February 9, 2024 11:54
@spikecurtis spikecurtis force-pushed the spike/10534-log-batch-size branch from 27b55aa to e941fbc Compare February 9, 2024 11:54
@spikecurtis spikecurtis changed the base branch from spike/10534-log-sender to spike/10534-log-sender-handle-log-limit-exceeded February 9, 2024 11:54
@spikecurtis spikecurtis force-pushed the spike/10534-log-sender-handle-log-limit-exceeded branch from 89ce3e7 to c8e7282 Compare February 9, 2024 12:05
@spikecurtis spikecurtis force-pushed the spike/10534-log-batch-size branch from e941fbc to ede6f2f Compare February 9, 2024 12:05
@spikecurtis spikecurtis force-pushed the spike/10534-log-sender-handle-log-limit-exceeded branch from c8e7282 to 0515169 Compare February 9, 2024 12:53
@spikecurtis spikecurtis force-pushed the spike/10534-log-batch-size branch from ede6f2f to 743f5f3 Compare February 9, 2024 12:53
Base automatically changed from spike/10534-log-sender-handle-log-limit-exceeded to spike/10534-log-sender February 9, 2024 12:57
@spikecurtis spikecurtis merged commit 743f5f3 into spike/10534-log-sender Feb 9, 2024
@spikecurtis spikecurtis deleted the spike/10534-log-batch-size branch February 9, 2024 12:57
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.

3 participants