Skip to content

Conversation

Mangaal
Copy link

@Mangaal Mangaal commented Sep 16, 2025

This PR introduces a unidirectional(agent → principal) log streaming service and wires it into the resource-proxy path so the Principal can serve Kubernetes pod logs to the Argo CD UI. The Agent handles both static logs (follow=false) and live streaming (follow=true) with resume support.

What’s included:

  • New LogStreaming service (gRPC) — Agent opens a client-streaming RPC and pushes log chunks keyed by request_uuid; Principal writes directly to the HTTP response stream and returns a final status when the stream ends.
  • Principal resource-proxy integration — /…/pods/{name}/log requests are recognised, the HTTP writer is registered, and a log event is enqueued to the Agent.
  • Agent log workers — static and live log handlers; time-window flush or 64KiB chunk flush; live streaming has resume (SinceTime) on transient errors.

Key feature:

  • Principal LogStream gRPC server & HTTP bridge.
  • Agent log streaming implementation (static + live + resume).
  • Principal resource proxy: log-subresource branch & handoff to LogStream.

Assisted-by: Cursor/Gemini etc

logs.mov

@Mangaal Mangaal force-pushed the log-streaming branch 2 times, most recently from 4d5e132 to 30aab14 Compare September 16, 2025 14:58
@Mangaal Mangaal closed this Sep 16, 2025
@Mangaal Mangaal reopened this Sep 16, 2025
Signed-off-by: Mangaal <[email protected]>
(cherry picked from commit 2a08301)
Signed-off-by: Mangaal <[email protected]>
(cherry picked from commit d07df62)
Signed-off-by: Mangaal <[email protected]>
(cherry picked from commit 161f2a4)
Signed-off-by: Mangaal <[email protected]>
(cherry picked from commit 30aab14)
Signed-off-by: Mangaal <[email protected]>
(cherry picked from commit f8a6666)
Signed-off-by: Mangaal <[email protected]>
(cherry picked from commit e820c35)
@codecov-commenter
Copy link

codecov-commenter commented Sep 17, 2025

Codecov Report

❌ Patch coverage is 44.00000% with 434 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.56%. Comparing base (427206b) to head (7bd5564).

Files with missing lines Patch % Lines
agent/log.go 36.82% 249 Missing and 22 partials ⚠️
principal/resource.go 12.50% 63 Missing and 7 partials ⚠️
internal/event/event.go 0.00% 56 Missing ⚠️
principal/apis/logstream/logstream.go 82.92% 31 Missing and 4 partials ⚠️
agent/inbound.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #569      +/-   ##
==========================================
- Coverage   45.63%   45.56%   -0.07%     
==========================================
  Files          90       92       +2     
  Lines       12020    12777     +757     
==========================================
+ Hits         5485     5822     +337     
- Misses       6090     6482     +392     
- Partials      445      473      +28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Mangaal Mangaal marked this pull request as ready for review September 17, 2025 12:01
@chetan-rns
Copy link
Collaborator

@Mangaal I see this error intermittently on the UI. Works fine after requesting the logs again. I guess we are not handling EOF somewhere?

Get "https://rathole-container-internal:9090/api/v1/namespaces/
guestbook/pods/kustomize-guestbook-ui-7689b675bc-cbv8h/log?container=guestbook-ui&follow=true&
tailLines=1000&timestamps=true": EOF

@@ -0,0 +1,586 @@
package agent
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some of the files are missing the Copyright headers. Please include them.

agent/log.go Outdated
}

line, err := br.ReadString('\n')
switch err {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't the argocd server process the logs before streaming to the UI? Just want to make sure the agent does not repeat the same work since it's only supposed to send back the responses from the k8s API. Can we directly send the chunks back and let the argocd server handle the raw logs? Then the agent doesn't have to go through the logs line by line.

Copy link
Author

@Mangaal Mangaal Sep 29, 2025

Choose a reason for hiding this comment

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

In my first approach, I have tried sending raw log chunks back to the server since the argocd server handles them, but on the ui, they were displayed unprocessed. I will revisit.

"namespace": requestedNamespace,
"pod": requestedName,
"params": reqParams,
"agent": agentName,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add these fields above so that they are also available for the previous log statements?

// Unique identifier matching the original request/event UUID
string request_uuid = 1;
// Log data content. Recommended to be a single line including trailing newline
string data = 2;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we use bytes as a data type instead of a string? Prevents the overhead of conversion at both the agent and the principal.

@Mangaal
Copy link
Author

Mangaal commented Sep 30, 2025

@chetan-rns, Thanks for reviewing my PR. I’ve updated it and addressed your suggestions. Please take a look when you get a chance.

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