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

Truncate single stdout instances that are too long #390

Merged
merged 2 commits into from
Sep 10, 2024
Merged
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
31 changes: 24 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,17 @@ 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] + "..."
}

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

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