From 03b8a00743115b2236a45a3f359ef0c86c9c2f6f Mon Sep 17 00:00:00 2001 From: Marco Pfatschbacher Date: Fri, 13 Oct 2023 12:43:12 +0100 Subject: [PATCH] Abort request on missing Graylog server version If we fail to read the server version from Graylog, stop using a fallback to 4.0.0 and retry the request instead. In scenarios with multiple Graylog nodes behind a load balancer, this can lead to the sidecar temporarly stopping all collectors. Fixes #481 --- api/graylog.go | 8 +++----- services/periodicals.go | 5 ++++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/api/graylog.go b/api/graylog.go index bb78baa..d3f7886 100644 --- a/api/graylog.go +++ b/api/graylog.go @@ -42,22 +42,20 @@ var ( ) func GetServerVersion(httpClient *http.Client, ctx *context.Ctx) (*GraylogVersion, error) { - // In case of an error just assume 4.0.0 - fallbackVersion, _ := NewGraylogVersion("4.0.0") - c := rest.NewClient(httpClient, ctx) c.BaseURL = ctx.ServerUrl r, err := c.NewRequest("GET", "/", nil, nil) if err != nil { log.Errorf("Cannot retrieve server version %v", err) - return fallbackVersion, err + return nil, err } versionResponse := graylog.ServerVersionResponse{} resp, err := c.Do(r, &versionResponse) if err != nil || resp == nil { log.Errorf("Error fetching server version %v", err) - return fallbackVersion, err + return nil, err } + log.Debugf("Graylog server version %v", versionResponse.Version) return NewGraylogVersion(versionResponse.Version) } diff --git a/services/periodicals.go b/services/periodicals.go index a630cf6..8efa7fb 100644 --- a/services/periodicals.go +++ b/services/periodicals.go @@ -49,7 +49,10 @@ func StartPeriodicals(context *context.Ctx) { } firstRun = false - serverVersion, _ := api.GetServerVersion(httpClient, context) + serverVersion, err := api.GetServerVersion(httpClient, context) + if err != nil { + continue + } // registration regResponse contains configuration assignments regResponse, err := updateCollectorRegistration(httpClient, lastRegResponse.Checksum, context, serverVersion)