Skip to content

[logs] Aggregates long lines when tailing in a k8s env - part #1#6265

Merged
truthbk merged 12 commits intomasterfrom
prognant/aggregates-long-lines-k8s-file-tailing
Sep 18, 2020
Merged

[logs] Aggregates long lines when tailing in a k8s env - part #1#6265
truthbk merged 12 commits intomasterfrom
prognant/aggregates-long-lines-k8s-file-tailing

Conversation

@prognant
Copy link
Copy Markdown
Contributor

@prognant prognant commented Aug 20, 2020

What does this PR do?

It isolates the parsing logic in the log pipeline (when tailing from file):
It changes

[...] -> decoder -> line_handler -> [...]

by

[...] -> decoder -> line_parser -> line_handler -> [...]

Motivation

Make room for additional parsing+buffering logic to support split lines (usecase: log tailing in a k8s environment with explicit tailing from file, lines are split in 16k chunks) and keeps other feature intact.

Additional Notes

It will add a slight overhead.
See subsequent PR #6266 for the release note.

Describe your test plan

Existing UT adjusted.
New UT.
IRL tests.

@prognant prognant added do-not-merge/WIP [deprecated] team/agent-core Deprecated. Use metrics-logs / shared-components labels instead.. labels Aug 20, 2020
@prognant prognant added this to the 7.23.0 milestone Aug 20, 2020
@prognant prognant requested review from a team as code owners August 20, 2020 09:30
@prognant prognant added the changelog/no-changelog No changelog entry needed label Aug 20, 2020
@prognant prognant changed the title [WIP][logs] Aggregates long lines k8s file tailing - part #1 [WIP][logs] Aggregates long lines when tailing in a k8s env - part #1 Aug 21, 2020
@prognant prognant force-pushed the prognant/aggregates-long-lines-k8s-file-tailing branch from 5164e89 to 262d561 Compare August 25, 2020 15:28
@prognant prognant changed the title [WIP][logs] Aggregates long lines when tailing in a k8s env - part #1 [logs] Aggregates long lines when tailing in a k8s env - part #1 Aug 25, 2020
@prognant prognant force-pushed the prognant/aggregates-long-lines-k8s-file-tailing branch from 262d561 to 10b9ae7 Compare August 28, 2020 15:34
Copy link
Copy Markdown
Contributor

@ogaca-dd ogaca-dd left a comment

Choose a reason for hiding this comment

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

LGTM. I am not familiar with this code and so requesting another review might be a good idea. In particular, it is hard to track the logic of rawDataLen.

Note: Test failed.

Comment thread pkg/logs/decoder/decoder.go
@prognant prognant force-pushed the prognant/aggregates-long-lines-k8s-file-tailing branch from 10b9ae7 to 19d6b97 Compare September 2, 2020 09:29
@prognant
Copy link
Copy Markdown
Contributor Author

prognant commented Sep 2, 2020

LGTM. I am not familiar with this code and so requesting another review might be a good idea. In particular, it is hard to track the logic of rawDataLen.

Note: Test failed.

The logic behind rawDataLen is to keep track of the current position while tailing to be able to restart the agent and start tailing at the exact place where the agent stopped tailing. I rebased and double checked the PR, tests are now 🟢 .

Copy link
Copy Markdown
Member

@truthbk truthbk left a comment

Choose a reason for hiding this comment

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

Looks good to me! Just a couple of questions, and maybe a before and after benchmark after the changes to the pipeline would be nice to get a sense of the impact due to new allocations.

}

if parser.SupportsPartialLine() {
lineParser = NewSingleLineParser(parser, lineHandler)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Am I missing something? These two lines in the if and else blocks are identical?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They are, the subsequent PR add an alternate path cf. #6266

Comment thread pkg/logs/decoder/decoder_test.go Outdated
Comment thread pkg/logs/decoder/line_parser.go
if err != nil {
log.Debug(err)
}
p.lineHandler.Handle(NewMessage(content, status, input.rawDataLen, timestamp))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not entirely sure, but I feel like the new pipeline (which is way cleaner by the way) might be a little heavier on the allocations side. Any chance we could benchmark or profile the two approaches - just to get a sense of potential performance/memory impact?

Copy link
Copy Markdown
Contributor Author

@prognant prognant Sep 9, 2020

Choose a reason for hiding this comment

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

I totally agree that it is likely to be a bit (I will try to find out how much and share numbers) slower. Initially I thought about having some kind of fast path dropping unnecessary step (like the no-op parser) on certain condition. However in the current code base it would have either end up in something a bit hacky, or IMHO a too big change for a single PR. After thinking about the second option I tried to write the current PR a step to a more generic pipeline that would ultimately look like :
[decoder]-(*Message)-> step #1 -(*Message)-> [...] -(*Message)->step #n -(*Message)->[output/forwarder]
So only mandatory block for a given source would then be instantiated, with a unique type circulating between blocks and then we won't get useless allocation for blocks that wouldn't ever be instantiated, and in that extend we should be able, for base cases (like flat file tailing, noop parser, no multiline log), to keep the same performance as we have today.
One "new" block we could implement once that's done ; there have been (surprisingly) a high number of request to support utf-16 encoded log, I think if we rework the pipeline, we could then have an "encoding" block usable for all log sources easily, only enabled based on a to-be-defined config knob value.
This is really opened for discussion, I was about to start an RFC on the topic with the idea of streamlining the logs processing pipeline to describe & discuss what's written above.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interested on this RFC!

Comment thread pkg/logs/decoder/line_parser_test.go Outdated
@prognant
Copy link
Copy Markdown
Contributor Author

prognant commented Sep 15, 2020

Small benchmark (ec2 t2.medium single file on a ramdisk, set offset to 0 in registry to tail it from the beginning) metrics emitted with this PR are on the left, metrics emitted with master branch are on the right:
image

Overall the processed log per second seems to be stable, the total memory footprint is stable. There is logically a bit more allocations (around 5-7% from what I can tell).

@prognant prognant requested a review from truthbk September 15, 2020 10:16
Comment thread pkg/logs/decoder/decoder.go Outdated
@prognant prognant modified the milestones: 7.23.0, 7.24.0 Sep 18, 2020
@truthbk truthbk modified the milestones: 7.24.0, 7.23.0 Sep 18, 2020
@truthbk truthbk force-pushed the prognant/aggregates-long-lines-k8s-file-tailing branch from 6ff1b7b to 08291d4 Compare September 18, 2020 19:14
@prognant prognant requested a review from a team as a code owner September 18, 2020 19:25
@truthbk truthbk force-pushed the prognant/aggregates-long-lines-k8s-file-tailing branch from 5fcedcf to e41caf9 Compare September 18, 2020 19:57
@truthbk truthbk force-pushed the prognant/aggregates-long-lines-k8s-file-tailing branch from e41caf9 to 9d94385 Compare September 18, 2020 20:22
@truthbk truthbk force-pushed the prognant/aggregates-long-lines-k8s-file-tailing branch from 9d94385 to 93b8256 Compare September 18, 2020 20:38
@truthbk truthbk merged commit ea7e888 into master Sep 18, 2020
@truthbk truthbk deleted the prognant/aggregates-long-lines-k8s-file-tailing branch September 18, 2020 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/no-changelog No changelog entry needed [deprecated] team/agent-core Deprecated. Use metrics-logs / shared-components labels instead..

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants