Skip to content

Commit

Permalink
Make run output truncation limits configurable (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
dehort authored Oct 4, 2024
1 parent 22853a4 commit ff76118
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions internal/common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func Get() *viper.Viper {
options.SetDefault("storage.retries", 3)
options.SetDefault("storage.max.concurrency", 5)
options.SetDefault("artifact.max.size", 1024*1024)
options.SetDefault("artifact.truncate.stdout.field.after.lines", 500)
options.SetDefault("artifact.max.stdout.field.size", 1024)
options.SetDefault("artifact.max.kafka.message.size", 1024*1024)

options.SetDefault("satellite.response.full", true)

Expand Down
13 changes: 7 additions & 6 deletions internal/validator/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ func (this *handler) validateContent(ctx context.Context, requestType string, da

log := utils.GetLogFromContext(ctx)

maxMessageSize := 1 * 1024 * 1024
maxStdoutSize := 1024
maxMessageSize := cfg.GetInt("artifact.max.kafka.message.size")
maxStdoutSize := cfg.GetInt("artifact.max.stdout.field.size")
truncateAfterNumberOfLines := cfg.GetInt("artifact.truncate.stdout.field.after.lines")

// FIXME: make this configurable
truncateData := len(data) >= maxMessageSize
if truncateData {
log.Debug("Payload too big. Truncating payload.")
Expand Down Expand Up @@ -207,7 +207,7 @@ func (this *handler) validateContent(ctx context.Context, requestType string, da
}

// There could also be too many console strings
if i > 500 {
if i > truncateAfterNumberOfLines {
if validatedEvent.Console != nil || *validatedEvent.Console != "" {
validatedEvent.Console = &truncated
truncated = ""
Expand All @@ -229,8 +229,9 @@ func (this *handler) validateContent(ctx context.Context, requestType string, da
*validatedEvent.Stdout = (*validatedEvent.Stdout)[0:maxStdoutSize] + "..."
}

// There could also be too many stdouts
if i > 500 && i < len(lines)-2 {
// There could also be too many stdouts, but try to preserve the last lines of
// the output as it contains a summary
if i > truncateAfterNumberOfLines && i < len(lines)-2 {
validatedEvent.Stdout = &truncated
truncated = ""
}
Expand Down

0 comments on commit ff76118

Please sign in to comment.