Skip to content

Commit

Permalink
fix: misc bugs related to new logref support
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Sep 5, 2024
1 parent cceda4f commit 97e3f03
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
10 changes: 6 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
"NODE_VERSION": "lts/*"
}
},
"runArgs": ["--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"],
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],
"customizations": {
"vscode": {
// Set *default* container specific settings.json values on container create.
Expand All @@ -38,10 +42,8 @@
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "go version",

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
}
19 changes: 6 additions & 13 deletions internal/api/backresthandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ func (s *BackrestHandler) GetLogs(ctx context.Context, req *connect.Request[v1.L
}
return fmt.Errorf("get log data %v: %w", req.Msg.GetRef(), err)
}
defer s.logStore.Unsubscribe(req.Msg.Ref, ch)

doneCh := make(chan struct{})

Expand All @@ -550,20 +551,12 @@ func (s *BackrestHandler) GetLogs(ctx context.Context, req *connect.Request[v1.L
defer interval.Stop()

go func() {
for {
select {
case data, ok := <-ch:
if !ok {
close(doneCh)
return
}
mu.Lock()
buf.Write(data)
mu.Unlock()
case <-ctx.Done():
return
}
for data := range ch {
mu.Lock()
buf.Write(data)
mu.Unlock()
}
close(doneCh)
}()

flushHelper := func() error {
Expand Down
8 changes: 7 additions & 1 deletion internal/logwriter/livelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,14 @@ func (t *LiveLog) Unsubscribe(id string, ch chan []byte) {
if w, ok := t.writers[id]; ok {
w.mu.Lock()
defer w.mu.Unlock()
w.subscribers = slices.DeleteFunc(w.subscribers, func(c chan []byte) bool {

idx := slices.IndexFunc(w.subscribers, func(c chan []byte) bool {
return c == ch
})
if idx >= 0 {
close(ch)
w.subscribers = append(w.subscribers[:idx], w.subscribers[idx+1:]...)
}
}
}

Expand Down Expand Up @@ -194,6 +199,7 @@ func (t *LiveLogWriter) Close() error {
for _, ch := range t.subscribers {
close(ch)
}
t.subscribers = nil

return t.fh.Close()
}
5 changes: 4 additions & 1 deletion webui/src/components/LogView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export const LogView = ({ logref }: { logref: string }) => {
}}
>
{lines.map((line, i) => (
<pre style={{ margin: "0px" }} key={i}>
<pre
style={{ margin: "0px", whiteSpace: "pre", overflow: "visible" }}
key={i}
>
{line}
</pre>
))}
Expand Down
5 changes: 5 additions & 0 deletions webui/src/components/OperationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export const OperationRow = ({
});
} else if (operation.op.case === "operationPrune") {
const prune = operation.op.value;
expandedBodyItems.push("prune");
bodyItems.push({
key: "prune",
label: "Prune Output",
Expand All @@ -223,6 +224,7 @@ export const OperationRow = ({
});
} else if (operation.op.case === "operationCheck") {
const check = operation.op.value;
expandedBodyItems.push("check");
bodyItems.push({
key: "check",
label: "Check Output",
Expand All @@ -242,6 +244,9 @@ export const OperationRow = ({
} else if (operation.op.case === "operationRunHook") {
const hook = operation.op.value;
if (operation.logref) {
if (operation.status === OperationStatus.STATUS_INPROGRESS) {
expandedBodyItems.push("logref");
}
bodyItems.push({
key: "logref",
label: "Hook Output",
Expand Down

0 comments on commit 97e3f03

Please sign in to comment.