Skip to content

Commit

Permalink
Limit list_log_file response size (#265)
Browse files Browse the repository at this point in the history
* Stop sending list of active log files if max Monog doc size is reached

* Use JSON structure for size calculation

Fixes Graylog2/graylog2-server#4899
  • Loading branch information
Marius Sturm authored and bernd committed Aug 1, 2018
1 parent be4687e commit 1a6ca34
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion api/graylog.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
package api

import (
"bytes"
"crypto/tls"
"encoding/json"
"io"
"net/http"
"strconv"
Expand Down Expand Up @@ -151,7 +153,20 @@ 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)
buf := new(bytes.Buffer)
if fileList != nil {
json.NewEncoder(buf).Encode(fileList)
}
fileListSize := buf.Len()
// 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

0 comments on commit 1a6ca34

Please sign in to comment.