Skip to content

Commit

Permalink
feat(performance): improve Log Processing performance (#5647)
Browse files Browse the repository at this point in the history
* feat(performance): buffer the logs sent from the container, to avoid sending message for each line
* feat(performance): batch Test Workflow's result updates
* fix(testworkflows): handle getting long container logs after the log rotation happens
   @see {@link https://stackoverflow.com/a/68673451}
* feat(testworkflows): optimize reading timestamp from Kubernetes logs
* feat(testworkflows): optimize buffering logs
* feat(testworkflows): use native channel instead of heavier Channels for WatchInstrumentedPod
* feat(testworkflows): increase buffer size for logs buffering
  • Loading branch information
rangoo94 authored Jul 10, 2024
1 parent b7f8118 commit 1443737
Show file tree
Hide file tree
Showing 8 changed files with 463 additions and 80 deletions.
5 changes: 5 additions & 0 deletions pkg/testworkflows/testworkflowcontroller/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Channel[T any] interface {
Channel() <-chan ChannelMessage[T]
Close()
Done() <-chan struct{}
CtxErr() error
}

type channel[T any] struct {
Expand Down Expand Up @@ -168,3 +169,7 @@ func (c *channel[T]) Close() {
func (c *channel[T]) Done() <-chan struct{} {
return c.ctx.Done()
}

func (c *channel[T]) CtxErr() error {
return c.ctx.Err()
}
8 changes: 4 additions & 4 deletions pkg/testworkflows/testworkflowcontroller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (c *controller) StopController() {
}

func (c *controller) Watch(parentCtx context.Context) <-chan ChannelMessage[Notification] {
w, err := WatchInstrumentedPod(parentCtx, c.clientSet, c.signature, c.scheduledAt, c.pod, c.podEvents, WatchInstrumentedPodOptions{
ch, err := WatchInstrumentedPod(parentCtx, c.clientSet, c.signature, c.scheduledAt, c.pod, c.podEvents, WatchInstrumentedPodOptions{
JobEvents: c.jobEvents,
Job: c.job,
})
Expand All @@ -222,7 +222,7 @@ func (c *controller) Watch(parentCtx context.Context) <-chan ChannelMessage[Noti
v.Close()
return v.Channel()
}
return w.Channel()
return ch
}

// TODO: Make it actually light
Expand Down Expand Up @@ -281,15 +281,15 @@ func (c *controller) Logs(parentCtx context.Context, follow bool) io.Reader {
case <-c.podEvents.Peek(parentCtx):
case <-alignTimeoutCh:
}
w, err := WatchInstrumentedPod(parentCtx, c.clientSet, c.signature, c.scheduledAt, c.pod, c.podEvents, WatchInstrumentedPodOptions{
ch, err := WatchInstrumentedPod(parentCtx, c.clientSet, c.signature, c.scheduledAt, c.pod, c.podEvents, WatchInstrumentedPodOptions{
JobEvents: c.jobEvents,
Job: c.job,
Follow: common.Ptr(follow),
})
if err != nil {
return
}
for v := range w.Channel() {
for v := range ch {
if v.Error == nil && v.Value.Log != "" && !v.Value.Temporary {
if ref != v.Value.Ref && v.Value.Ref != "" {
ref = v.Value.Ref
Expand Down
Loading

0 comments on commit 1443737

Please sign in to comment.