Skip to content

Commit 09e30f3

Browse files
mpfz0rMarius Sturm
authored and
Marius Sturm
committed
Wipe configchecksums also on assignment changes (backport) (#357)
* Wipe configchecksums also on assignment changes (#353) If an assignemnt is changed to switch a backend from one configuration to another, we would still send configuration requests using the old checksum. The server will respond with `NotModified` and we don't try to restart the backend. Instead of also resetting the checksum when we update the assignment store, simply wipe the entire checksum map if either the assignment or the backends have changed. Fixes #352 (cherry picked from commit dca0b17) * Bump version to 1.0.1
1 parent 39a311c commit 09e30f3

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

assignments/assignment.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package assignments
1717

1818
import (
1919
"github.com/Graylog2/collector-sidecar/common"
20+
"reflect"
2021
)
2122

2223
var (
@@ -59,7 +60,11 @@ func (as *assignmentStore) AssignedBackendIds() []string {
5960
return result
6061
}
6162

62-
func (as *assignmentStore) Update(assignments []ConfigurationAssignment) {
63+
func (as *assignmentStore) Update(assignments []ConfigurationAssignment) bool {
64+
beforeUpdate := make(map[string]string)
65+
for k, v := range as.assignments {
66+
beforeUpdate[k] = v
67+
}
6368
if len(assignments) != 0 {
6469
var activeIds []string
6570
for _, assignment := range assignments {
@@ -70,6 +75,7 @@ func (as *assignmentStore) Update(assignments []ConfigurationAssignment) {
7075
} else {
7176
Store.cleanup([]string{})
7277
}
78+
return !reflect.DeepEqual(beforeUpdate, as.assignments)
7379
}
7480

7581
func (as *assignmentStore) cleanup(validBackendIds []string) {

daemon/daemon.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (dc *DaemonConfig) GetRunnerByBackendId(id string) Runner {
111111
return nil
112112
}
113113

114-
func (dc *DaemonConfig) SyncWithAssignments(configChecksums map[string]string, context *context.Ctx) {
114+
func (dc *DaemonConfig) SyncWithAssignments(context *context.Ctx) {
115115
if dc.Runner == nil {
116116
return
117117
}
@@ -125,7 +125,6 @@ func (dc *DaemonConfig) SyncWithAssignments(configChecksums map[string]string, c
125125
log.Infof("[%s] Updating process configuration", runner.Name())
126126
runnerServiceType := runnerBackend.ServiceType
127127
runner.SetBackend(*backend)
128-
configChecksums[backend.Id] = ""
129128
if backend.ServiceType != runnerServiceType {
130129
log.Infof("Changing process runner (%s -> %s) for: %s",
131130
runnerServiceType, backend.ServiceType, backend.Name)
@@ -146,7 +145,6 @@ func (dc *DaemonConfig) SyncWithAssignments(configChecksums map[string]string, c
146145
if backend == nil || assignments.Store.GetAll()[backend.Id] == "" {
147146
log.Info("Removing process runner: " + backend.Name)
148147
dc.DeleteRunner(id)
149-
configChecksums[backend.Id] = ""
150148
}
151149
}
152150
assignedBackends := []*backends.Backend{}

services/periodicals.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,28 @@ func StartPeriodicals(context *context.Ctx) {
4545
for {
4646
time.Sleep(time.Duration(context.UserConfig.UpdateInterval) * time.Second)
4747

48-
// registration response contains configuration assignments
49-
response, err := updateCollectorRegistration(httpClient, assignmentChecksum, context)
48+
// registration regResponse contains configuration assignments
49+
regResponse, err := updateCollectorRegistration(httpClient, assignmentChecksum, context)
5050
if err != nil {
5151
continue
5252
}
53-
assignmentChecksum = response.Checksum
53+
assignmentChecksum = regResponse.Checksum
5454
// backend list is needed before configuration assignments are updated
5555
backendResponse, err := fetchBackendList(httpClient, backendChecksum, context)
5656
if err != nil {
5757
continue
5858
}
5959
backendChecksum = backendResponse.Checksum
6060

61-
if !response.NotModified || !backendResponse.NotModified {
62-
assignments.Store.Update(response.Assignments)
61+
if !regResponse.NotModified || !backendResponse.NotModified {
62+
modified := assignments.Store.Update(regResponse.Assignments)
63+
// regResponse.NotModified is always false, because graylog does not implement caching yet.
64+
// Thus we need to double check.
65+
if modified || !backendResponse.NotModified {
66+
configChecksums = make(map[string]string)
67+
}
6368
// create process instances
64-
daemon.Daemon.SyncWithAssignments(configChecksums, context)
69+
daemon.Daemon.SyncWithAssignments(context)
6570
// test for new or updated configurations and start the corresponding collector
6671
if assignments.Store.Len() == 0 {
6772
if logOnce {

version.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
COLLECTOR_VERSION = 1.0.0
1+
COLLECTOR_VERSION = 1.0.1
22
COLLECTOR_VERSION_SUFFIX =
33
COLLECTOR_REVISION = 1

0 commit comments

Comments
 (0)