Skip to content

Commit 757715d

Browse files
[Feature] Strip ANSI codes from run logs and store them as plain text instead of bytes #2841
Extracted `ansistrip` timeouts as constants
1 parent 1b37038 commit 757715d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

runner/internal/executor/executor.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ import (
2828
"github.com/prometheus/procfs"
2929
)
3030

31+
// TODO: Tune these parameters for optimal experience/performance
32+
const (
33+
// Output is flushed when the cursor doesn't move for this duration
34+
AnsiStripFlushInterval = 500 * time.Millisecond
35+
36+
// Output is flushed regardless of cursor activity after this maximum delay
37+
AnsiStripMaxDelay = 3 * time.Second
38+
)
39+
3140
type RunExecutor struct {
3241
tempDir string
3342
homeDir string
@@ -132,7 +141,7 @@ func (ex *RunExecutor) Run(ctx context.Context) (err error) {
132141
}
133142
}()
134143

135-
stripper := ansistrip.NewWriter(ex.runnerLogs, 500*time.Millisecond, 3*time.Second)
144+
stripper := ansistrip.NewWriter(ex.runnerLogs, AnsiStripFlushInterval, AnsiStripMaxDelay)
136145
logger := io.MultiWriter(runnerLogFile, os.Stdout, stripper)
137146
ctx = log.WithLogger(ctx, log.NewEntry(logger, int(log.DefaultEntry.Logger.Level))) // todo loglevel
138147
log.Info(ctx, "Run job", "log_level", log.GetLogger(ctx).Logger.Level.String())
@@ -439,7 +448,7 @@ func (ex *RunExecutor) execJob(ctx context.Context, jobLogFile io.Writer) error
439448
defer func() { _ = ptm.Close() }()
440449
defer func() { _ = cmd.Wait() }() // release resources if copy fails
441450

442-
stripper := ansistrip.NewWriter(ex.jobLogs, 500*time.Millisecond, 3*time.Second)
451+
stripper := ansistrip.NewWriter(ex.jobLogs, AnsiStripFlushInterval, AnsiStripMaxDelay)
443452
logger := io.MultiWriter(jobLogFile, ex.jobWsLogs, stripper)
444453
_, err = io.Copy(logger, ptm)
445454
if err != nil && !isPtyError(err) {

0 commit comments

Comments
 (0)