Skip to content

Commit

Permalink
Truncate single stdout instances that are too long
Browse files Browse the repository at this point in the history
  • Loading branch information
dehort committed Sep 9, 2024
1 parent 754a7ba commit e00427f
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions internal/validator/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func (this *handler) validateContent(ctx context.Context, requestType string, da
log := utils.GetLogFromContext(ctx)

maxMessageSize := 1 * 1024 * 1024
maxStdoutSize := 1024

// FIXME: make this configurable
truncateData := len(data) >= maxMessageSize
Expand Down Expand Up @@ -193,10 +194,18 @@ func (this *handler) validateContent(ctx context.Context, requestType string, da
return nil, err
}

if i > 500 && truncateData {
if validatedEvent.Console != nil || *validatedEvent.Console != "" {
validatedEvent.Console = &truncated
truncated = ""
if truncateData {
// There could be one big console string
if validatedEvent.Console != nil && len(*validatedEvent.Console) > maxStdoutSize {
*validatedEvent.Console = (*validatedEvent.Console)[0:maxStdoutSize] + "..."
}

// There could also be too many console strings
if i > 500 {
if validatedEvent.Console != nil || *validatedEvent.Console != "" {
validatedEvent.Console = &truncated
truncated = ""
}
}
}

Expand All @@ -208,9 +217,19 @@ func (this *handler) validateContent(ctx context.Context, requestType string, da
return nil, err
}

if i > 500 && i < len(lines)-2 && truncateData {
validatedEvent.Stdout = &truncated
truncated = ""
if truncateData {
// There could be one big stdout
if validatedEvent.Stdout != nil && len(*validatedEvent.Stdout) > maxStdoutSize {
*validatedEvent.Stdout = (*validatedEvent.Stdout)[0:maxStdoutSize] + "..."
fmt.Println("TRUNCATED sliced")
}

// There could also be too many stdouts
if i > 500 && i < len(lines)-2 {
validatedEvent.Stdout = &truncated
truncated = ""
fmt.Println("TRUNCATED")
}
}

events.Playbook = append(events.Playbook, *validatedEvent)
Expand Down

0 comments on commit e00427f

Please sign in to comment.