Skip to content

Commit

Permalink
fix: remove log retry (#945)
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Brecic <[email protected]>
  • Loading branch information
lbrecic authored Aug 23, 2024
1 parent a09b9c7 commit c1332a8
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 39 deletions.
1 change: 0 additions & 1 deletion docs/daytona_server_logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ daytona server logs [flags]
```
--file Read logs from local server log file
-f, --follow Follow logs
-r, --retry Retry connection
```

### Options inherited from parent commands
Expand Down
4 changes: 0 additions & 4 deletions hack/docs/daytona_server_logs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ options:
shorthand: f
default_value: "false"
usage: Follow logs
- name: retry
shorthand: r
default_value: "false"
usage: Retry connection
inherited_options:
- name: help
default_value: "false"
Expand Down
2 changes: 1 addition & 1 deletion internal/util/apiclient/websocket_log_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var workspaceLogsStarted bool

func ReadWorkspaceLogs(activeProfile config.Profile, workspaceId string, projectNames []string, stopLogs *bool) {
var wg sync.WaitGroup
query := "follow=true&retry=true"
query := "follow=true"

logs_view.CalculateLongestPrefixLength(projectNames)

Expand Down
32 changes: 9 additions & 23 deletions internal/util/log_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ func ReadLog(ctx context.Context, logReader io.Reader, follow bool, c chan []byt
}
}

func ReadJSONLog(ctx context.Context, logReader io.Reader, follow bool, retry bool, c chan interface{}, errChan chan error) {
func ReadJSONLog(ctx context.Context, logReader io.Reader, follow bool, c chan interface{}, errChan chan error) {
var buffer bytes.Buffer
var err error
reader := bufio.NewReader(logReader)
delimiter := []byte(logs.LogDelimiter)

Expand All @@ -50,29 +49,16 @@ func ReadJSONLog(ctx context.Context, logReader io.Reader, follow bool, retry bo
default:
byteChunk := make([]byte, 1024)

if retry {
for {
n, err := reader.Read(byteChunk)
if err == nil {
buffer.Write(byteChunk[:n])
break
} else if !follow && err == io.EOF {
errChan <- io.EOF
return
}
}
} else {
n, err := reader.Read(byteChunk)
if err != nil {
if err != io.EOF {
errChan <- err
} else if !follow {
errChan <- io.EOF
return
}
n, err := reader.Read(byteChunk)
if err != nil {
if err != io.EOF {
errChan <- err
} else if !follow {
errChan <- io.EOF
return
}
buffer.Write(byteChunk[:n])
}
buffer.Write(byteChunk[:n])

data := buffer.Bytes()

Expand Down
4 changes: 1 addition & 3 deletions pkg/api/controllers/log/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ func writeJSONToWs(ws *websocket.Conn, c chan interface{}, errChan chan error) {
func readJSONLog(ginCtx *gin.Context, logReader io.Reader) {
followQuery := ginCtx.Query("follow")
follow := followQuery == "true"
retryQuery := ginCtx.Query("retry")
retry := retryQuery == "true"

ws, err := upgrader.Upgrade(ginCtx.Writer, ginCtx.Request, nil)
if err != nil {
Expand All @@ -115,7 +113,7 @@ func readJSONLog(ginCtx *gin.Context, logReader io.Reader) {
ctx, cancel := context.WithCancel(context.Background())

defer cancel()
go util.ReadJSONLog(ctx, logReader, follow, retry, msgChannel, errChannel)
go util.ReadJSONLog(ctx, logReader, follow, msgChannel, errChannel)
go writeJSONToWs(ws, msgChannel, errChannel)

go func() {
Expand Down
8 changes: 1 addition & 7 deletions pkg/cmd/server/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
)

var followFlag bool
var retryFlag bool
var fileFlag bool

var logsCmd = &cobra.Command{
Expand All @@ -38,11 +37,7 @@ var logsCmd = &cobra.Command{
}

query := ""
if retryFlag && followFlag {
query += "follow=true&retry=true"
} else if retryFlag {
query += "retry=true"
} else if followFlag {
if followFlag {
query += "follow=true"
}

Expand Down Expand Up @@ -128,6 +123,5 @@ func readServerLogFile() {

func init() {
logsCmd.Flags().BoolVarP(&followFlag, "follow", "f", false, "Follow logs")
logsCmd.Flags().BoolVarP(&retryFlag, "retry", "r", false, "Retry connection")
logsCmd.Flags().BoolVar(&fileFlag, "file", false, "Read logs from local server log file")
}

0 comments on commit c1332a8

Please sign in to comment.