From ead06d6108bb49a78d9f325c5b134008029079f3 Mon Sep 17 00:00:00 2001 From: Marius Sturm Date: Thu, 19 Jul 2018 15:21:22 +0200 Subject: [PATCH 1/2] Stop sending list of active log files if max Monog doc size is reached --- api/graylog.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/api/graylog.go b/api/graylog.go index 306ff46..9f93f57 100644 --- a/api/graylog.go +++ b/api/graylog.go @@ -21,6 +21,7 @@ import ( "net/http" "strconv" "strings" + "unsafe" "github.com/Graylog2/collector-sidecar/api/graylog" "github.com/Graylog2/collector-sidecar/api/rest" @@ -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) + // 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.") + } } } From 3eeb88f39624983438d4db4e766d4bb6e1122cae Mon Sep 17 00:00:00 2001 From: Marius Sturm Date: Thu, 26 Jul 2018 13:51:50 +0200 Subject: [PATCH 2/2] Use JSON structure for size calculation --- api/graylog.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/api/graylog.go b/api/graylog.go index 9f93f57..ed3010f 100644 --- a/api/graylog.go +++ b/api/graylog.go @@ -16,12 +16,13 @@ package api import ( + "bytes" "crypto/tls" + "encoding/json" "io" "net/http" "strconv" "strings" - "unsafe" "github.com/Graylog2/collector-sidecar/api/graylog" "github.com/Graylog2/collector-sidecar/api/rest" @@ -153,7 +154,11 @@ func UpdateRegistration(httpClient *http.Client, ctx *context.Ctx, status *grayl registration.NodeDetails.Metrics = metrics if len(ctx.UserConfig.ListLogFiles) > 0 { fileList := common.ListFiles(ctx.UserConfig.ListLogFiles) - fileListSize := (int)(unsafe.Sizeof(common.File{})) * len(fileList) + 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 {