fix(api) Improve reporting of log backend failures - #1489
Conversation
Log retrieval flattened every backend failure to codes.Internal, so the HTTP handler always returned 500. After a run's namespace is deleted the LokiStack gateway returns 403, which surfaced as an opaque 500 with no indication that the failure was an authorization decision. Map backend HTTP status codes to the corresponding gRPC codes for the Loki, Splunk and Blob backends, map transport-level failures to DeadlineExceeded or Unavailable, and have LogMux derive the HTTP status from the resulting gRPC code instead of hardcoding 500. Backend 400 responses and blob InvalidArgument errors are deliberately reported as Internal: the queries and object keys are built by the API server from its own configuration, never from caller input, so a rejected request is a server-side defect rather than a bad request. Also correct a logging statement in the Splunk fetch-log path that reported the job-creation status code instead of the fetch response's. Signed-off-by: Emil Natan <ena@redhat.com> Assisted-by: Claude Opus 5 <noreply@anthropic.com>
The gRPC GetLog handler logged errors returned by the log backend and then returned nil, so clients received an empty but successful stream when log retrieval failed. Return the error instead, preserving the status code produced by the backend, and normalise errors that carry no gRPC status to Internal rather than letting gRPC default them to Unknown. Signed-off-by: Emil Natan <ena@redhat.com> Assisted-by: Claude Opus 5 <noreply@anthropic.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
🟡 Changes recommended
Blob HTTP streaming can retain status 200 after failures, while Splunk polling errors remain misclassified.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Improves log-backend failure reporting across gRPC and HTTP APIs.
Changes:
- Maps HTTP, transport, and blob failures to appropriate gRPC/HTTP statuses.
- Propagates streaming
GetLogerrors. - Adds error-mapping and integration tests.
File summaries
| File | Description |
|---|---|
plugin_logs.go |
Implements backend error mapping and propagation. |
plugin_logs_getlog_test.go |
Tests gRPC error propagation. |
plugin_logs_errorcodes_test.go |
Tests mappings and backend failures. |
export_test.go |
Exposes internal helpers to external tests. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 3
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if err != nil { | ||
| s.logger.Errorf("error creating bucket reader: %s for log part: %s", err, part) | ||
| return err | ||
| return blobError(err, "error reading log storage object") |
| return status.Errorf(httpStatusToCode(resp.StatusCode), | ||
| "splunk log backend search job creation failed with HTTP %d (%s)", resp.StatusCode, http.StatusText(resp.StatusCode)) |
| mock := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| if r.URL.Path == "/services/search/v2/jobs" { | ||
| w.WriteHeader(tc.httpStatus) | ||
| return | ||
| } | ||
| w.WriteHeader(http.StatusOK) | ||
| })) |
Changes
The PR intentionally includes two commits. First one improves the reporting of log backend failures with accurate status codes. The second one improves propagation of the log backend errors from streaming GetLog. Check the actual commit messages for more details.
/kind misc
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you review them:
/kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tepRelease Notes