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

Limit list_log_file response size #265

Merged
merged 2 commits into from
Aug 1, 2018
Merged
Changes from 1 commit
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
12 changes: 11 additions & 1 deletion api/graylog.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net/http"
"strconv"
"strings"
"unsafe"

"github.com/Graylog2/collector-sidecar/api/graylog"
"github.com/Graylog2/collector-sidecar/api/rest"
Expand Down Expand Up @@ -151,7 +152,16 @@ func UpdateRegistration(httpClient *http.Client, ctx *context.Ctx, status *grayl
registration.NodeDetails.Status = status
registration.NodeDetails.Metrics = metrics
if len(ctx.UserConfig.ListLogFiles) > 0 {
registration.NodeDetails.LogFileList = common.ListFiles(ctx.UserConfig.ListLogFiles)
fileList := common.ListFiles(ctx.UserConfig.ListLogFiles)
fileListSize := (int)(unsafe.Sizeof(common.File{})) * len(fileList)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually correct? As far as I understand, this measures the size of an empty common.File struct. But a filled struct might be much larger because we don't know the length of the strings beforehand.

How about measuring the serialized request by marshaling it into JSON?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was thinking about that too, my concern was that we would do the same operation two times. Marshal to JSON to get the list size... marshal again to actually send the request. It's not too expensive but anyway. Guess the result will be better because we also get the JSON overhead.

// Maximum MongoDB document size is 16793600 bytes so we leave some extra space for the rest of the request
// before we skip to send the file list.
if fileListSize < 10000000 {
registration.NodeDetails.LogFileList = fileList
} else {
log.Warn("[UpdateRegistration] Maximum file list size exceeded, skip sending list of active log files!" +
" Adjust list_log_file setting.")
}
}
}

Expand Down