Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions packages/orchestrator/internal/template/cache/build_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cache
import (
"context"
"fmt"
"slices"
"time"

"github.com/jellydator/ttlcache/v3"
Expand Down Expand Up @@ -75,13 +74,8 @@ func (b *BuildInfo) SetFail(reason *template_manager.TemplateBuildStatusReason)
})
}

func (b *BuildInfo) GetLogs(direction template_manager.LogsDirection) []*template_manager.TemplateBuildLogEntry {
lines := b.logs.Lines()
if direction == template_manager.LogsDirection_Backward {
slices.Reverse(lines)
}

return lines
func (b *BuildInfo) GetLogs() []*template_manager.TemplateBuildLogEntry {
return b.logs.Lines()
}

type BuildCache struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"context"
"slices"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -43,9 +44,15 @@ func (s *ServerStore) TemplateBuildStatus(ctx context.Context, in *template_mana
end = e.AsTime()
}

logLines := buildInfo.GetLogs()
// If the direction is backward, we need to reverse the log entries to have them in the descending order
if direction == template_manager.LogsDirection_Backward {
slices.Reverse(logLines)
}

logEntries := make([]*template_manager.TemplateBuildLogEntry, 0)
logsCrawled := int32(0)
for _, entry := range buildInfo.GetLogs(direction) {
for _, entry := range logLines {
// Skip entries that are below the specified level
if entry.GetLevel().Number() < in.GetLevel().Number() {
continue
Expand All @@ -64,11 +71,16 @@ func (s *ServerStore) TemplateBuildStatus(ctx context.Context, in *template_mana
continue
}

logEntries = append(logEntries, entry)

if uint32(len(logEntries)) >= limit {
break
}
}

logEntries = append(logEntries, entry)
// If the direction is backward, we need to reverse the log entries again to have them back in the ascending order
if direction == template_manager.LogsDirection_Backward {
slices.Reverse(logEntries)
}

result := buildInfo.GetResult()
Expand Down
Loading