Skip to content

vlagent: implement Kubernetes log collector#815

Merged
valyala merged 2 commits into
masterfrom
k8s-collector
Dec 5, 2025
Merged

vlagent: implement Kubernetes log collector#815
valyala merged 2 commits into
masterfrom
k8s-collector

Conversation

@vadimalekseev
Copy link
Copy Markdown
Member

@vadimalekseev vadimalekseev commented Nov 13, 2025

Describe Your Changes

Fixes: #538

Checklist

The following checks are mandatory:

@vadimalekseev vadimalekseev force-pushed the k8s-collector branch 3 times, most recently from 9a03420 to faedb5b Compare November 14, 2025 07:41
Copy link
Copy Markdown
Contributor

@valyala valyala left a comment

Choose a reason for hiding this comment

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

Looks great overall!

@vadimalekseev , please document the added functionality in docs/victorialogs/vlagent.md, and mention it at docs/victorialogs/CHANGELOG.md.

@AndrewChubatiuk
Copy link
Copy Markdown
Contributor

@vadimalekseev vadimalekseev force-pushed the k8s-collector branch 3 times, most recently from 9c17ba6 to b44ea2d Compare November 16, 2025 18:39
@vadimalekseev
Copy link
Copy Markdown
Member Author

vadimalekseev commented Nov 16, 2025

Added documentation.

Please, do not merge this PR until we resolve this issue: #816, because it significantly affects memory usage when collecting pod logs. In my tests, vlagent uses up to 5x more memory because of the double buffering issue.

After this, I need to run final tests to compare the FDs, RAM, CPU usage of vlagent with promtail, Vector and Fluent Bit.

upd:
Fixed by implementing new LogMessageProcessor, see:

type logFileProcessor struct {

Comment thread docs/victorialogs/vlagent.md Outdated
@vadimalekseev vadimalekseev force-pushed the k8s-collector branch 8 times, most recently from e704457 to 4d6b440 Compare November 17, 2025 13:59
@vadimalekseev vadimalekseev marked this pull request as draft November 18, 2025 10:35
@vadimalekseev vadimalekseev force-pushed the k8s-collector branch 3 times, most recently from 4fe8d5f to bedc0a7 Compare November 20, 2025 21:49
@vadimalekseev vadimalekseev force-pushed the k8s-collector branch 6 times, most recently from f9a9997 to 1c3b7b4 Compare December 1, 2025 11:36
@vadimalekseev vadimalekseev force-pushed the k8s-collector branch 4 times, most recently from 8757ae4 to fbc8332 Compare December 1, 2025 13:19
@vadimalekseev vadimalekseev marked this pull request as ready for review December 1, 2025 16:20
@vadimalekseev vadimalekseev requested a review from valyala December 1, 2025 16:21
@valyala valyala merged commit 2aa0ea1 into master Dec 5, 2025
6 checks passed
@valyala valyala deleted the k8s-collector branch December 5, 2025 17:57
@valyala
Copy link
Copy Markdown
Contributor

valyala commented Dec 5, 2025

@vadimalekseev , thank you for implementing discovery and collecting of logs in Kubernetes by vlagent!

valyala added a commit that referenced this pull request Dec 5, 2025
… for the Kubernetes log collector functionality implemented in vlagent at the commit 2aa0ea1

Updates #538
Updates #815
valyala added a commit that referenced this pull request Dec 5, 2025
…s logs via vlagent

This is a follow-up for the commit 2aa0ea1

Updates #815
Updates #538
func (er podWatchStream) readEvents(h func(event watchEvent)) error {
lr := newLineReader(er.r)
for {
line, err := lr.readLine()
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.

It should be easier to use json.Decoder here in the way similar to the code used in Kubernetes service dicsovery for VictoriaMetrics - https://github.com/VictoriaMetrics/VictoriaMetrics/blob/0cb90f91fcb109e895cb34d57a93e9a3e8d5bc01/lib/promscrape/discovery/kubernetes/api_watcher.go#L871-L876 . Then you won't need the code for manual reading of lines before parsing the next JSON-encoded event in the stream.

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.

Also, the readEvents() function always returns non-nil error. I think it shouldn't return io.EOF error when Kubernetes API server closes the response stream. It should return nil in this case, since this is the expected state.

As for the io.UnexpectedEOF handling, could you verify whether it should be treated as io.EOF or it is better to return the io.UnexpectedEOF as is. I think that it must be returned to the caller of the readEvents() function as is, since it usually means that the connection is closed in the middle of reading of JSON-encoded event (e.g. this is an error, which must be reported to the user, so he could decide what to do next).

Copy link
Copy Markdown
Member Author

@vadimalekseev vadimalekseev Dec 22, 2025

Choose a reason for hiding this comment

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

could you verify whether it should be treated as io.EOF or it is better to return the io.UnexpectedEOF as is. I think that it must be returned to the caller of the readEvents() function as is, since it usually means that the connection is closed in the middle of reading of JSON-encoded event (e.g. this is an error, which must be reported to the user, so he could decide what to do next).

In our test environment, all connection interruption errors appeared as io.UnexpectedEOF. This is why a added this commit 5895712 . I'm not sure if we encountered io.EOF errors, as we have been handling those since the initial vlagent release. Therefore, I believe we should handle both cases.

I can deploy a test release with verbose error logging to the test environment to verify which errors we are receiving.

upd:
I couldn't find those logs in our test environment. Most likely, it happened in my local Kubernetes cluster. It's possible my laptop went into sleep mode while the Kubernetes API was streaming JSON.

Copy link
Copy Markdown
Contributor

@valyala valyala left a comment

Choose a reason for hiding this comment

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

See the recommendation about using json.Decoder for reading JSON-encoded event stream without the need to manually read lines from the stream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants