Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make payload truncation limits configurable #392

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading