Skip to content

Commit

Permalink
Abort request on missing Graylog server version
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mpfz0r committed Oct 13, 2023
1 parent abe7994 commit 1054cfd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
8 changes: 3 additions & 5 deletions api/graylog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
11 changes: 11 additions & 0 deletions changelog/unreleased/issue-481.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# PLEASE REMOVE COMMENTS AND OPTIONAL FIELDS! THANKS!

# Entry type according to https://keepachangelog.com/en/1.0.0/
# One of: a(dded), c(hanged), d(eprecated), r(emoved), f(ixed), s(ecurity)
type = "fixed"
message = "Avoid stopping collectors if a Graylog cluster behind load balancers is partly shut down."

issues = ["481"]
pulls = ["482"]

contributors = [""]
5 changes: 4 additions & 1 deletion services/periodicals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1054cfd

Please sign in to comment.