From ff7611895ab5623b975c9e3d60c49b6065feb85c Mon Sep 17 00:00:00 2001 From: dehort Date: Fri, 4 Oct 2024 17:28:45 -0500 Subject: [PATCH] Make run output truncation limits configurable (#392) --- internal/common/config/config.go | 3 +++ internal/validator/handler.go | 13 +++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/internal/common/config/config.go b/internal/common/config/config.go index 960a8532..82cce534 100644 --- a/internal/common/config/config.go +++ b/internal/common/config/config.go @@ -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) diff --git a/internal/validator/handler.go b/internal/validator/handler.go index 8498defb..11a2a556 100644 --- a/internal/validator/handler.go +++ b/internal/validator/handler.go @@ -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.") @@ -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 = "" @@ -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 = "" }