feat(webui): read a task's log through the State Store and let it be downloaded
The dashboard's attempt-log panel answered every read with "task logging is
optional and was not enabled for this run". That message was false: logging is
wired unconditionally in the daemon, and the log files exist. The dashboard
process simply had no reader -- composition left TaskLogs absent because no
contract carried it -- so the handler saw a nil registry and reported the
disabled shape, which the page rendered as a claim about configuration.
internal/logging now answers whether an attempt has a log at all: Tail sets
Result.Found, so "this attempt has no log" is a value rather than an empty
list indistinguishable from a read that never happened. Its registry gains
TaskLog (a decoded page) and TaskLogContent (the file verbatim, streamed,
because a log is unbounded input), and an absent reader reports
ErrTaskLogsUnavailable rather than an empty page -- a process that cannot read
logs must not implicate the attempt.
Those two answers travel the State Store contract as storecontract.TaskLogStore
(ReadTaskLog, StreamTaskLogContent) and are rehydrated on the client by
(Unavailable, canonical message), so archie-ui composes the reader from its own
store client instead of opening another process's files. The daemon's registry
is wired as the server-side reader in the State Store process only.
On top of that read, GET /api/tasks/{id}/logs/download serves the attempt's log
as a Content-Disposition attachment named task-<id>-attempt-<n>.log, and the
panel offers it. The JSON route keeps its shape and gains found, so the page
states the attempt has no log instead of blaming a setting.
Task log files stay owned by their directory's owner: archiving still removes a
task's log directory, and that removal is the daemon's, not the dashboard's.
This commit is contained in:
1 parent
781358c862
commit
21d8250cde
19 files changed
+1266
-83
No files matched your search
@@ -56,7 +56,12 @@ type daemonActions struct {
|
||||
// cfg is the daemon's configuration, held by the stand-in daemon
|
||||
// rather than by the dashboard: retry caps are the task owner's
|
||||
// policy and the dashboard does not hold configuration.
|
||||
cfg *config.Holder
|
||||
cfg *config.Holder
|
||||
// logs is the daemon's own task-log registry. Archiving removes a
|
||||
// task's log files, and that is the daemon's cleanup over the state
|
||||
// directory it owns -- the dashboard reads logs through a contract and
|
||||
// has no directory to remove anything from.
|
||||
logs *logging.TaskRegistry
|
||||
issues *recordingCloser
|
||||
stopper *recordingTaskStopper
|
||||
// scopes records the identity each action arrived with, one per call.
|
||||
@@ -97,10 +102,10 @@ func (d *daemonActions) closeIssue() func(context.Context, string, string, int,
|
||||
}
|
||||
|
||||
func (d *daemonActions) removeLogs() func(int64) error {
|
||||
if d.srv.TaskLogs == nil {
|
||||
if d.logs == nil {
|
||||
return nil
|
||||
}
|
||||
return d.srv.TaskLogs.Remove
|
||||
return d.logs.Remove
|
||||
}
|
||||
|
||||
func (d *daemonActions) publish() func(events.Event) {
|
||||
@@ -701,11 +706,17 @@ func TestArchiveRemovesOnlyOneTerminalTask(t *testing.T) {
|
||||
// logging: without this, an archived task's log files (and every rotated
|
||||
// generation under it) would accumulate on disk forever, since nothing else
|
||||
// in the system ever visits a task again once it leaves the active board.
|
||||
//
|
||||
// The removal is the task owner's, not the dashboard's: the log files live in
|
||||
// the state directory, which the daemon owns, so the stand-in daemon holds the
|
||||
// registry the way the real one does. The dashboard reads logs through a
|
||||
// contract and has no directory to remove anything from.
|
||||
func TestArchiveRemovesTheTaskLogDirectory(t *testing.T) {
|
||||
srv := newTestServer(t)
|
||||
ctx := t.Context()
|
||||
baseDir := t.TempDir()
|
||||
srv.TaskLogs = logging.NewTaskRegistry(baseDir, logging.NewFeed(10), logging.TaskSinkOptions{})
|
||||
logs := logging.NewTaskRegistry(baseDir, logging.NewFeed(10), logging.TaskSinkOptions{})
|
||||
operatorActions(t, srv).logs = logs
|
||||
|
||||
if _, err := srv.Store.EnqueueIssue(ctx, "acme", "widget", 1, "done", "", "", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -715,11 +726,11 @@ func TestArchiveRemovesTheTaskLogDirectory(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := srv.TaskLogs.Open(task.ID, task.Attempt); err != nil {
|
||||
if err := logs.Open(task.ID, task.Attempt); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
srv.TaskLogs.Write(task.ID, logging.Entry{Message: "line"})
|
||||
if err := srv.TaskLogs.Close(task.ID); err != nil {
|
||||
logs.Write(task.ID, logging.Entry{Message: "line"})
|
||||
if err := logs.Close(task.ID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dir := logging.TaskLogDir(baseDir, task.ID)
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/logging"
|
||||
)
|
||||
|
||||
// TestHandleTaskLogsDistinguishesNoLogForTheAttempt covers the dashboard's
|
||||
// misleading report. A process that HAS a task-log reader and an attempt that
|
||||
// genuinely has no file on disk is a different answer from a process that
|
||||
// cannot read logs at all, and only the second one is "logging is not enabled
|
||||
// here". The response has to carry that difference or the page cannot state it.
|
||||
func TestHandleTaskLogsDistinguishesNoLogForTheAttempt(t *testing.T) {
|
||||
srv := newTestServer(t)
|
||||
ctx := t.Context()
|
||||
srv.TaskLogs = logging.NewTaskRegistry(t.TempDir(), logging.NewFeed(10), logging.TaskSinkOptions{})
|
||||
|
||||
if _, err := srv.Store.EnqueueIssue(ctx, "acme", "widget", 1, "task", "", "", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
task, err := srv.Store.TaskByIssue(ctx, "acme", "widget", 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// No log is ever opened for this task: the reader works, the attempt has
|
||||
// no file.
|
||||
|
||||
w := getTaskLogs(t, srv, task.ID, nil)
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d, body %s", w.Code, w.Body)
|
||||
}
|
||||
var body struct {
|
||||
Disabled bool `json:"disabled"`
|
||||
Found bool `json:"found"`
|
||||
}
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &body); err != nil {
|
||||
t.Fatalf("decode response: %v (%s)", err, w.Body)
|
||||
}
|
||||
if body.Disabled {
|
||||
t.Error("disabled = true for a process that has a task-log reader; that is the report the page turns into \"logging was not enabled for this run\"")
|
||||
}
|
||||
if body.Found {
|
||||
t.Error("found = true for an attempt with no log file on disk")
|
||||
}
|
||||
if !strings.Contains(w.Body.String(), `"found"`) {
|
||||
t.Errorf("body = %s, want an explicit found marker so the page can say the attempt has no log rather than that logging is off", w.Body)
|
||||
}
|
||||
}
|
||||
|
||||
// TestHandleTaskLogsDownloadServesTheAttemptLog pins the deliverable: the
|
||||
// endpoint hands back the attempt's log as a file download. The route falling
|
||||
// through to the SPA asset handler would answer 200 with an HTML page, so this
|
||||
// asserts on the attachment headers and the body, not merely on the status.
|
||||
func TestHandleTaskLogsDownloadServesTheAttemptLog(t *testing.T) {
|
||||
srv := newTestServer(t)
|
||||
ctx := t.Context()
|
||||
logs := logging.NewTaskRegistry(t.TempDir(), logging.NewFeed(10), logging.TaskSinkOptions{})
|
||||
srv.TaskLogs = logs
|
||||
|
||||
if _, err := srv.Store.EnqueueIssue(ctx, "acme", "widget", 1, "task", "", "", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
task, err := srv.Store.TaskByIssue(ctx, "acme", "widget", 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := logs.Open(task.ID, task.Attempt); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
logs.Write(task.ID, logging.Entry{Level: "ERROR", Message: "gate failed"})
|
||||
if err := logs.Close(task.ID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
url := "/api/tasks/" + strconv.FormatInt(task.ID, 10) + "/logs/download"
|
||||
req := httptest.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
w := httptest.NewRecorder()
|
||||
srv.Handler().ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("GET %s = %d, body %s", url, w.Code, w.Body)
|
||||
}
|
||||
wantName := "task-" + strconv.FormatInt(task.ID, 10) + "-attempt-" + strconv.Itoa(task.Attempt) + ".log"
|
||||
if got := w.Header().Get("Content-Disposition"); got != `attachment; filename="`+wantName+`"` {
|
||||
t.Errorf("Content-Disposition = %q, want an attachment named %q", got, wantName)
|
||||
}
|
||||
if !strings.Contains(w.Body.String(), "gate failed") {
|
||||
t.Errorf("download body = %s, want the attempt's own log content", w.Body)
|
||||
}
|
||||
}
|
||||
|
||||
// TestHandleTaskLogsDownloadWithoutALogAnswersNotFound keeps the download
|
||||
// honest: there is nothing to attach, so it says so rather than handing back a
|
||||
// zero-byte file that looks like a successful download of nothing.
|
||||
func TestHandleTaskLogsDownloadWithoutALogAnswersNotFound(t *testing.T) {
|
||||
srv := newTestServer(t)
|
||||
ctx := t.Context()
|
||||
srv.TaskLogs = logging.NewTaskRegistry(t.TempDir(), logging.NewFeed(10), logging.TaskSinkOptions{})
|
||||
|
||||
if _, err := srv.Store.EnqueueIssue(ctx, "acme", "widget", 1, "task", "", "", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
task, err := srv.Store.TaskByIssue(ctx, "acme", "widget", 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
url := "/api/tasks/" + strconv.FormatInt(task.ID, 10) + "/logs/download"
|
||||
req := httptest.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
w := httptest.NewRecorder()
|
||||
srv.Handler().ServeHTTP(w, req)
|
||||
if w.Code != http.StatusNotFound {
|
||||
t.Fatalf("GET %s with no log = %d, want 404", url, w.Code)
|
||||
}
|
||||
}
|
||||
|
||||
// TestHandleTaskLogsDownloadWithoutAReaderAnswersServiceUnavailable is the
|
||||
// degradation the boundary permits: a process with no task-log contract answers
|
||||
// 503 rather than 404, because "I cannot read logs" and "there is no log" are
|
||||
// not the same claim.
|
||||
func TestHandleTaskLogsDownloadWithoutAReaderAnswersServiceUnavailable(t *testing.T) {
|
||||
srv := newTestServer(t)
|
||||
ctx := t.Context()
|
||||
if _, err := srv.Store.EnqueueIssue(ctx, "acme", "widget", 1, "task", "", "", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
task, err := srv.Store.TaskByIssue(ctx, "acme", "widget", 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
url := "/api/tasks/" + strconv.FormatInt(task.ID, 10) + "/logs/download"
|
||||
req := httptest.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
w := httptest.NewRecorder()
|
||||
srv.Handler().ServeHTTP(w, req)
|
||||
if w.Code != http.StatusServiceUnavailable {
|
||||
body, _ := io.ReadAll(w.Result().Body)
|
||||
t.Fatalf("GET %s without a reader = %d (%s), want 503", url, w.Code, body)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -16,84 +19,201 @@ import (
|
||||
// Attempt from the store, since that is what a human or Archie's own chat
|
||||
// tool means by "why did task N park?" almost every time: the most recent
|
||||
// run, not an arbitrary earlier retry.
|
||||
//
|
||||
// Two outcomes are kept apart on purpose, because only one of them is about
|
||||
// the operator's configuration. A process with no task-log reader cannot say
|
||||
// anything about an attempt, so it reports disabled and the page explains that
|
||||
// this process cannot read logs. A process WITH a reader and an attempt with
|
||||
// no log file reports found=false, which the page states as no log recorded
|
||||
// for the attempt. Collapsing the second into the first is what made the
|
||||
// dashboard claim "task logging is optional and was not enabled for this run"
|
||||
// for every attempt of every task in a deployment where logging is
|
||||
// unconditional.
|
||||
func (s *Server) handleTaskLogs(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.Error(w, "bad id", http.StatusBadRequest)
|
||||
id, attempt, ok := s.taskLogTarget(w, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
task, err := s.Store.TaskByID(r.Context(), id)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if task == nil {
|
||||
http.Error(w, "task not found", http.StatusNotFound)
|
||||
reader := s.taskLogReader()
|
||||
if reader == nil {
|
||||
writeDisabledTaskLogs(w, attempt)
|
||||
return
|
||||
}
|
||||
|
||||
q := r.URL.Query()
|
||||
attempt := task.Attempt
|
||||
if raw := strings.TrimSpace(q.Get("attempt")); raw != "" {
|
||||
attempt, err = strconv.Atoi(raw)
|
||||
if err != nil {
|
||||
http.Error(w, "bad attempt", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
path := s.TaskLogs.Path(id, attempt)
|
||||
if path == "" {
|
||||
// Not an error: task logging is optional, same convention as
|
||||
// handleLogs for the daemon-wide log.
|
||||
writeJSON(w, map[string]any{
|
||||
"entries": []logging.Entry{},
|
||||
"file": "",
|
||||
"disabled": true,
|
||||
"attempt": attempt,
|
||||
})
|
||||
limit, ok := taskLogLimit(w, q.Get("limit"))
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
limit := logging.DefaultTailLines
|
||||
if raw := strings.TrimSpace(q.Get("limit")); raw != "" {
|
||||
parsed, err := strconv.Atoi(raw)
|
||||
if err != nil {
|
||||
http.Error(w, "bad limit", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
switch {
|
||||
case parsed <= 0:
|
||||
limit = logging.DefaultTailLines
|
||||
case parsed > logging.MaxTailLines:
|
||||
limit = logging.MaxTailLines
|
||||
default:
|
||||
limit = parsed
|
||||
}
|
||||
}
|
||||
result, err := logging.Tail(path, logging.Query{
|
||||
page, err := reader.TaskLog(r.Context(), id, attempt, logging.Query{
|
||||
Levels: splitCSV(q.Get("level")),
|
||||
Component: strings.TrimSpace(q.Get("component")),
|
||||
Contains: strings.TrimSpace(q.Get("q")),
|
||||
Limit: limit,
|
||||
})
|
||||
if err != nil {
|
||||
// A reader that exists but cannot read here is still a statement about
|
||||
// this process rather than about the attempt, so it keeps the disabled
|
||||
// answer instead of claiming the attempt has no log.
|
||||
if errors.Is(err, logging.ErrTaskLogsUnavailable) {
|
||||
writeDisabledTaskLogs(w, attempt)
|
||||
return
|
||||
}
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
components, err := logging.Components(path)
|
||||
if err != nil {
|
||||
s.Log.Warn("task log components unavailable", "task_id", id, "err", err)
|
||||
components = []string{}
|
||||
}
|
||||
|
||||
writeJSON(w, map[string]any{
|
||||
"entries": result.Entries,
|
||||
"truncated": result.Truncated,
|
||||
"file": result.File,
|
||||
"components": components,
|
||||
"entries": page.Entries,
|
||||
"truncated": page.Truncated,
|
||||
"file": page.File,
|
||||
"components": page.Components,
|
||||
"attempt": attempt,
|
||||
// found is the distinction the page needs: a reader answering with no
|
||||
// entries because the file is absent is not a reader that is absent.
|
||||
"found": page.Found,
|
||||
})
|
||||
}
|
||||
|
||||
// handleTaskLogDownload serves one task attempt's log verbatim as a file
|
||||
// download -- the log itself rather than a decoded view of it, because an
|
||||
// operator who asks for a download wants to read it in their own tooling or
|
||||
// hand it to someone else.
|
||||
//
|
||||
// The conditions stay apart here too. A process with no reader answers 503,
|
||||
// not 404: "there is no log for this attempt" is a claim only a process that
|
||||
// can look is in a position to make.
|
||||
func (s *Server) handleTaskLogDownload(w http.ResponseWriter, r *http.Request) {
|
||||
id, attempt, ok := s.taskLogTarget(w, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
reader := s.taskLogReader()
|
||||
if reader == nil {
|
||||
http.Error(w, logging.ErrTaskLogsUnavailable.Error(), http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
|
||||
// Headers are set before the read because the body streams straight from
|
||||
// the reader into the response: a log file is unbounded input, so
|
||||
// buffering it to size the response would defeat the reason the reader
|
||||
// streams at all. The attempt's own name is known up front.
|
||||
w.Header().Set("Content-Type", "application/x-ndjson")
|
||||
w.Header().Set("Content-Disposition", `attachment; filename="`+taskLogFilename(id, attempt)+`"`)
|
||||
|
||||
found, err := reader.TaskLogContent(r.Context(), id, attempt, w)
|
||||
if err != nil {
|
||||
if errors.Is(err, logging.ErrTaskLogsUnavailable) {
|
||||
http.Error(w, err.Error(), http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
// Once a 200 and a body are on the wire there is no status left to
|
||||
// send, so a failure partway through is logged where an operator can
|
||||
// find it rather than silently truncating the file.
|
||||
s.logf("task log download failed", "task", id, "attempt", attempt, "err", err)
|
||||
return
|
||||
}
|
||||
if !found {
|
||||
http.Error(w, "no log recorded for this attempt", http.StatusNotFound)
|
||||
}
|
||||
}
|
||||
|
||||
// taskLogTarget resolves the {id} path value and the task it names, returning
|
||||
// the attempt to read: the "attempt" query parameter when the request names
|
||||
// one, otherwise the task's current Attempt. It answers the request itself and
|
||||
// reports false when either step fails.
|
||||
func (s *Server) taskLogTarget(w http.ResponseWriter, r *http.Request) (id int64, attempt int, ok bool) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.Error(w, "bad id", http.StatusBadRequest)
|
||||
return 0, 0, false
|
||||
}
|
||||
task, err := s.Store.TaskByID(r.Context(), id)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return 0, 0, false
|
||||
}
|
||||
if task == nil {
|
||||
http.Error(w, "task not found", http.StatusNotFound)
|
||||
return 0, 0, false
|
||||
}
|
||||
|
||||
attempt = task.Attempt
|
||||
if raw := strings.TrimSpace(r.URL.Query().Get("attempt")); raw != "" {
|
||||
parsed, err := strconv.Atoi(raw)
|
||||
if err != nil {
|
||||
http.Error(w, "bad attempt", http.StatusBadRequest)
|
||||
return 0, 0, false
|
||||
}
|
||||
attempt = parsed
|
||||
}
|
||||
return id, attempt, true
|
||||
}
|
||||
|
||||
// taskLogLimit bounds a page the way handleLogs bounds the daemon-wide read:
|
||||
// the limit is caller-supplied and a log file is unbounded, so a request must
|
||||
// not be able to pull an arbitrary amount of it into memory.
|
||||
func taskLogLimit(w http.ResponseWriter, raw string) (int, bool) {
|
||||
raw = strings.TrimSpace(raw)
|
||||
if raw == "" {
|
||||
return logging.DefaultTailLines, true
|
||||
}
|
||||
parsed, err := strconv.Atoi(raw)
|
||||
if err != nil {
|
||||
http.Error(w, "bad limit", http.StatusBadRequest)
|
||||
return 0, false
|
||||
}
|
||||
switch {
|
||||
case parsed <= 0:
|
||||
return logging.DefaultTailLines, true
|
||||
case parsed > logging.MaxTailLines:
|
||||
return logging.MaxTailLines, true
|
||||
default:
|
||||
return parsed, true
|
||||
}
|
||||
}
|
||||
|
||||
// writeDisabledTaskLogs is the "this process cannot read task logs" answer,
|
||||
// the same convention handleLogs uses for the daemon-wide log: an optional
|
||||
// capability that is absent here must not turn "why did this task park?" into
|
||||
// a 500 for every task.
|
||||
func writeDisabledTaskLogs(w http.ResponseWriter, attempt int) {
|
||||
writeJSON(w, map[string]any{
|
||||
"entries": []logging.Entry{},
|
||||
"file": "",
|
||||
"disabled": true,
|
||||
"attempt": attempt,
|
||||
})
|
||||
}
|
||||
|
||||
// taskLogFilename names a downloaded attempt's log. It carries the task and
|
||||
// the attempt because an operator downloading two attempts of the same task
|
||||
// must not end up with one file overwriting the other, and the attempt is the
|
||||
// one identifier the log's own path would have given them.
|
||||
func taskLogFilename(taskID int64, attempt int) string {
|
||||
return "task-" + strconv.FormatInt(taskID, 10) + "-attempt-" + strconv.Itoa(attempt) + ".log"
|
||||
}
|
||||
|
||||
// taskLogReader is the task-log read capability this process has, or nil when
|
||||
// it has none. The seam is a narrow interface rather than a concrete registry
|
||||
// so the same handlers serve both processes: the daemon holds a registry over
|
||||
// its own state directory, the dashboard holds the State Store client. A
|
||||
// consumer-owned seam is the difference between the dashboard degrading
|
||||
// honestly and the dashboard opening another process's files.
|
||||
func (s *Server) taskLogReader() TaskLogSource {
|
||||
if s == nil {
|
||||
return nil
|
||||
}
|
||||
return s.TaskLogs
|
||||
}
|
||||
|
||||
// TaskLogSource is the read seam the task-log handlers consume. It is the
|
||||
// logging package's own reader contract, so a registry and a remote client
|
||||
// satisfy it without either one restating the log format -- the package that
|
||||
// owns the format also owns the shape of a read of it.
|
||||
type TaskLogSource interface {
|
||||
// TaskLog returns a page of one attempt's decoded log.
|
||||
TaskLog(ctx context.Context, taskID int64, attempt int, q logging.Query) (logging.TaskLogPage, error)
|
||||
// TaskLogContent writes one attempt's log verbatim to w, for a download.
|
||||
TaskLogContent(ctx context.Context, taskID int64, attempt int, w io.Writer) (bool, error)
|
||||
}
|
||||
@@ -14,7 +14,8 @@ func TestHandleTaskLogsReturnsEntriesForLatestAttemptByDefault(t *testing.T) {
|
||||
srv := newTestServer(t)
|
||||
ctx := t.Context()
|
||||
baseDir := t.TempDir()
|
||||
srv.TaskLogs = logging.NewTaskRegistry(baseDir, logging.NewFeed(10), logging.TaskSinkOptions{})
|
||||
logs := logging.NewTaskRegistry(baseDir, logging.NewFeed(10), logging.TaskSinkOptions{})
|
||||
srv.TaskLogs = logs
|
||||
|
||||
if _, err := srv.Store.EnqueueIssue(ctx, "acme", "widget", 1, "task", "", "", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -24,13 +25,13 @@ func TestHandleTaskLogsReturnsEntriesForLatestAttemptByDefault(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := srv.TaskLogs.Open(task.ID, task.Attempt); err != nil {
|
||||
if err := logs.Open(task.ID, task.Attempt); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
srv.TaskLogs.Write(task.ID, logging.Entry{
|
||||
logs.Write(task.ID, logging.Entry{
|
||||
Level: "ERROR", Message: "gate failed", Fields: map[string]any{"component": "gate"},
|
||||
})
|
||||
if err := srv.TaskLogs.Close(task.ID); err != nil {
|
||||
if err := logs.Close(task.ID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -58,7 +59,8 @@ func TestHandleTaskLogsHonoursExplicitAttempt(t *testing.T) {
|
||||
srv := newTestServer(t)
|
||||
ctx := t.Context()
|
||||
baseDir := t.TempDir()
|
||||
srv.TaskLogs = logging.NewTaskRegistry(baseDir, logging.NewFeed(10), logging.TaskSinkOptions{})
|
||||
logs := logging.NewTaskRegistry(baseDir, logging.NewFeed(10), logging.TaskSinkOptions{})
|
||||
srv.TaskLogs = logs
|
||||
|
||||
if _, err := srv.Store.EnqueueIssue(ctx, "acme", "widget", 1, "task", "", "", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -43,10 +43,16 @@ type Server struct {
|
||||
// LogFeed is the daemon diagnostic stream. It is separate from Events,
|
||||
// which contains persisted task lifecycle activity only.
|
||||
LogFeed *logging.Feed
|
||||
// TaskLogs holds each task's persisted log output. Archiving a task
|
||||
// removes its log files here too, via TaskLogs.Remove -- nil (task
|
||||
// logging not configured) makes that a no-op.
|
||||
TaskLogs *logging.TaskRegistry
|
||||
// TaskLogs reads each task's persisted log output. Composition gives this
|
||||
// process whichever implementation it can use: the daemon (whose state
|
||||
// directory holds the files) its own *logging.TaskRegistry, and the
|
||||
// dashboard process, which owns no such directory, the State Store client
|
||||
// -- the read crosses a contract rather than opening a file
|
||||
// (docs/prds/ui-service-boundary.md). Nil means this process has no
|
||||
// task-log capability at all, which the handlers report as disabled rather
|
||||
// than as "the attempt has no log": those are different claims and only one
|
||||
// of them is about configuration.
|
||||
TaskLogs TaskLogSource
|
||||
|
||||
// UpdateConfig applies a set of dotted-path config updates through
|
||||
// the same validate-persist-publish path as reload (wired by the
|
||||
@@ -238,6 +244,7 @@ func (s *Server) registerTaskRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("POST /api/tasks/{id}/action", s.handleTaskAction)
|
||||
mux.HandleFunc("GET /api/tasks/{id}", s.handleTask)
|
||||
mux.HandleFunc("GET /api/tasks/{id}/logs", s.handleTaskLogs)
|
||||
mux.HandleFunc("GET /api/tasks/{id}/logs/download", s.handleTaskLogDownload)
|
||||
}
|
||||
|
||||
func (s *Server) registerMappingAndBindingRoutes(mux *http.ServeMux) {
|
||||
|
||||
Reference in new issue
Block a user