Files
e012135bda [1/N][Feature][history server] support endpoint /api/v0/logs/file (#4411)
* feat: support logs/file endpoint

Signed-off-by: machichima <[email protected]>

* refactor: redundant log & var name

Signed-off-by: machichima <[email protected]>

* feat: get the last N lines logs

Signed-off-by: machichima <[email protected]>

* refactor: typo & unused comment

Signed-off-by: machichima <[email protected]>

* feat: set default and max log lines

Signed-off-by: machichima <[email protected]>

* feat: prevent path traversal attacks

Signed-off-by: machichima <[email protected]>

* feat: check path traversal attacks for each ele

Signed-off-by: machichima <[email protected]>

* fix: raise err if cannot parse lines

Signed-off-by: machichima <[email protected]>

* fix: add content type for resp as text

Signed-off-by: machichima <[email protected]>

* fix: return internal server error

Signed-off-by: machichima <[email protected]>

* refactor: use ValidPath func

Signed-off-by: machichima <[email protected]>

* feat: add e2e test for live cluster

Signed-off-by: machichima <[email protected]>

* fix: set ray-cluster-id when inject collect in test raycluster

Signed-off-by: machichima <[email protected]>

* test: add logs/file dead cluster test

Signed-off-by: machichima <[email protected]>

* test: enable parse res from both dead and live cluster

This is a hacky method for now and we should update the response format
for dead cluster in the follow-up

Signed-off-by: machichima <[email protected]>

* fix: set context type at router level

Signed-off-by: machichima <[email protected]>

* fix: validate sessionName to prevent path traversal

Signed-off-by: machichima <[email protected]>

* docs: add todo comments

Signed-off-by: machichima <[email protected]>

* feat: add new HTTPError with status code

Signed-off-by: machichima <[email protected]>

* test: hard-code filename to make it deterministic

Signed-off-by: machichima <[email protected]>

* fix: pass namespace name as cluster name ID in collector test

Signed-off-by: machichima <[email protected]>

* fix: unused import

Signed-off-by: machichima <[email protected]>

* refactor: update test func name and add comment

Signed-off-by: machichima <[email protected]>

* refactor: remove /api/v0/logs/file comment in HistoryServerEndpoints

Signed-off-by: machichima <[email protected]>

* refactor: extract /api/v0/logs/file to constant

Signed-off-by: machichima <[email protected]>

* refactor: move loop outside g.Eventually

Signed-off-by: machichima <[email protected]>

* fix: drain the body before close

Signed-off-by: machichima <[email protected]>

* refactor: rename to GetOneOfNodeID

Co-authored-by: Han-Ju Chen (Future-Outlier) <[email protected]>
Signed-off-by: Nary Yeh <[email protected]>

* fix: update to use GetOneOfNodeID

Signed-off-by: machichima <[email protected]>

* fix: add path traversal validation for cookie values

Signed-off-by: machichima <[email protected]>

---------

Signed-off-by: machichima <[email protected]>
Signed-off-by: Nary Yeh <[email protected]>
Co-authored-by: Han-Ju Chen (Future-Outlier) <[email protected]>
2026-01-26 11:37:12 -08:00

33 lines
846 B
Go

package utils
// HTTPError represents an error with an associated HTTP status code.
type HTTPError struct {
internalError error // Original error
message string // Error message from internalError
statusCode int // HTTP status code
}
// NewHTTPError creates a new HTTPError with the given error and status code.
func NewHTTPError(err error, statusCode int) *HTTPError {
return &HTTPError{
internalError: err,
message: err.Error(),
statusCode: statusCode,
}
}
// Error implements the error interface.
func (e *HTTPError) Error() string {
return e.message
}
// Unwrap returns the wrapped error for use with errors.Is and errors.As.
func (e *HTTPError) Unwrap() error {
return e.internalError
}
// StatusCode returns the status code in HTTPError.
func (e *HTTPError) StatusCode() int {
return e.statusCode
}