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

Re-create HTTP connection to Graylog 60 update iterations #483

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions changelog/issue-479.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type = "fixed"
message = "Re-create HTTP connection to Graylog every 60 request loops to detect DNS changes."

issues = ["479"]
pulls = [""]

19 changes: 12 additions & 7 deletions services/periodicals.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,30 @@ import (
"github.com/Graylog2/collector-sidecar/logger"
)

const reCreateHttpConnEvery = 60

var log = logger.Log()
var httpClient *http.Client

func StartPeriodicals(context *context.Ctx) {
if httpClient == nil {
httpClient = rest.NewHTTPClient(api.GetTlsConfig(context))
}

go func() {
var httpClient *http.Client

configChecksums := make(map[string]string)
var lastBackendResponse graylog.ResponseBackendList
var lastRegResponse graylog.ResponseCollectorRegistration
logOnce := true
firstRun := true
iteration := 0

for {
if !firstRun {
if iteration > 0 {
time.Sleep(time.Duration(context.UserConfig.UpdateInterval) * time.Second)
}
firstRun = false
// Re-create HTTP connection every X loops: https://github.com/Graylog2/collector-sidecar/issues/479
if iteration%reCreateHttpConnEvery == 0 {
httpClient = rest.NewHTTPClient(api.GetTlsConfig(context))
}
iteration++

serverVersion, err := api.GetServerVersion(httpClient, context)
if err != nil {
Expand Down