Skip to content

Commit 486e673

Browse files
authored
Update health watcher if there is an instance update (#1204)
1 parent de1e010 commit 486e673

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

internal/watcher/health/health_watcher_service.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func NewHealthWatcherService(agentConfig *config.Config) *HealthWatcherService {
5454
func (hw *HealthWatcherService) AddHealthWatcher(instances []*mpi.Instance) {
5555
hw.healthWatcherMutex.Lock()
5656
defer hw.healthWatcherMutex.Unlock()
57+
5758
for _, instance := range instances {
5859
switch instance.GetInstanceMeta().GetInstanceType() {
5960
case mpi.InstanceMeta_INSTANCE_TYPE_NGINX, mpi.InstanceMeta_INSTANCE_TYPE_NGINX_PLUS:
@@ -73,12 +74,18 @@ func (hw *HealthWatcherService) AddHealthWatcher(instances []*mpi.Instance) {
7374
}
7475

7576
func (hw *HealthWatcherService) UpdateHealthWatcher(instances []*mpi.Instance) {
77+
hw.healthWatcherMutex.Lock()
78+
defer hw.healthWatcherMutex.Unlock()
79+
7680
for _, instance := range instances {
7781
hw.instances[instance.GetInstanceMeta().GetInstanceId()] = instance
7882
}
7983
}
8084

8185
func (hw *HealthWatcherService) DeleteHealthWatcher(instances []*mpi.Instance) {
86+
hw.healthWatcherMutex.Lock()
87+
defer hw.healthWatcherMutex.Unlock()
88+
8289
for _, instance := range instances {
8390
delete(hw.watchers, instance.GetInstanceMeta().GetInstanceId())
8491
delete(hw.instances, instance.GetInstanceMeta().GetInstanceId())

internal/watcher/watcher_plugin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ func (w *Watcher) handleInstanceUpdates(newCtx context.Context, message instance
328328
}
329329
if len(message.InstanceUpdates.UpdatedInstances) > 0 {
330330
slog.DebugContext(newCtx, "Instances updated", "instances", message.InstanceUpdates.UpdatedInstances)
331+
w.healthWatcherService.UpdateHealthWatcher(message.InstanceUpdates.UpdatedInstances)
331332
w.messagePipe.Process(
332333
newCtx,
333334
&bus.Message{Topic: bus.UpdatedInstancesTopic, Data: message.InstanceUpdates.UpdatedInstances},

0 commit comments

Comments
 (0)