Skip to content

fix(nodes): omit tailLines for file log queries - #1279

Open
ychampion wants to merge 1 commit into
containers:mainfrom
ychampion:fix-nodes-log-file-query
Open

fix(nodes): omit tailLines for file log queries#1279
ychampion wants to merge 1 commit into
containers:mainfrom
ychampion:fix-nodes-log-file-query

Conversation

@ychampion

Copy link
Copy Markdown
Contributor

Summary

  • stop forwarding tailLines for file-based node log queries
  • document file paths relative to /var/log and cover service/file behavior

Why

The kubelet rejects options on file queries, so nodes_log returned 406 whenever a file path was used with tailLines. The existing examples also double-prefixed /var/log.

Fixes #1262.

Validation

  • go test -p 1 ./pkg/mcp -run 'TestNodes/TestNodesLog' -count=1
  • go test -p 1 -count=1 ./...
  • make lint
  • make build

Kubelet resolves file paths under /var/log and rejects log options for file queries. Keep tailing for services while allowing file queries to succeed, and publish corrected tool examples.

Fixes: containers#1262
Constraint: Kubelet only accepts tailLines for service-style queries.
Rejected: Forward tailLines for every query | kubelet returns 406 for files
Confidence: high
Scope-risk: narrow
Directive: Keep file-query detection aligned with kubelet path semantics.
Tested: go test -p 1 -count=1 ./...; make lint; make build
Not-tested: Full race suite could not link all packages within local disk.
Signed-off-by: ychampion <ychampion@users.noreply.github.com>
@Cali0707

Copy link
Copy Markdown
Collaborator

@2uasimojo mind reviewing this one?

@2uasimojo 2uasimojo left a comment

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.

This looks right to me based on the issue. Couple questions inline.

Comment thread pkg/kubernetes/nodes.go
// Query parameters for tail
if tailLines > 0 {
// The kubelet only supports tailLines for service log queries.
if tailLines > 0 && !strings.ContainsAny(query, `/\`) {

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.

Do you think we should at least warn when ignoring an input parameter? (I'm actually curious why we don't just error.)

Comment thread pkg/mcp/nodes_test.go
Comment on lines +54 to +58
if req.URL.Query().Get("tailLines") != "2" {
w.WriteHeader(http.StatusNotAcceptable)
return
}
logContent = "Line 4\nLine 5\n"

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.

I'm not fully understanding how this test is structured, but this seems tightly coupled to the test case by requiring an exact tailLines value. Would it be too painful to do something like (pseudo):

logLines = "Line 1\nLine 2\nLine 3\nLine 4\nLine 5\n".Split("\n")
switch tailLines, err := atoi(req.URL.Query().Get("tailLines")) {
case (err != nil, tailLines <= 0): // Is zero acceptable?
  w.WriteHeader(http.StatusNotAcceptable) // invalid numeric input
  return
case tailLines > len(logLines):
  tailLines = len(logLines)
  fallthrough
default:
  logContent = logLines[len(logLines)-tailLines:].Join("\n") // Possible off-by-one; I didn't try too hard :)
}

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.

nodes_log fails on file queries: /var/log prefix double-join and tailLines rejected by kubelet

3 participants