Skip to content

Commit 7174c0e

Browse files
committed
fix test
1 parent c031c41 commit 7174c0e

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

internal/watcher/health/health_watcher_service.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,28 @@ func NewHealthWatcherService(agentConfig *config.Config) *HealthWatcherService {
5151
}
5252
}
5353

54-
func (hw *HealthWatcherService) UpdateHealthWatcher(instances []*mpi.Instance) {
54+
func (hw *HealthWatcherService) UpdateHealthWatcher(ctx context.Context, instances []*mpi.Instance) {
5555
hw.healthWatcherMutex.Lock()
5656
defer hw.healthWatcherMutex.Unlock()
5757

5858
clear(hw.instances)
5959

6060
for _, instance := range instances {
61-
hw.instances[instance.GetInstanceMeta().GetInstanceId()] = instance
61+
switch instance.GetInstanceMeta().GetInstanceType() {
62+
case mpi.InstanceMeta_INSTANCE_TYPE_NGINX, mpi.InstanceMeta_INSTANCE_TYPE_NGINX_PLUS:
63+
hw.instances[instance.GetInstanceMeta().GetInstanceId()] = instance
64+
case mpi.InstanceMeta_INSTANCE_TYPE_AGENT:
65+
case mpi.InstanceMeta_INSTANCE_TYPE_UNSPECIFIED,
66+
mpi.InstanceMeta_INSTANCE_TYPE_UNIT,
67+
mpi.InstanceMeta_INSTANCE_TYPE_NGINX_APP_PROTECT:
68+
fallthrough
69+
default:
70+
slog.DebugContext(
71+
ctx,
72+
"Health watcher not implemented",
73+
"instance_type", instance.GetInstanceMeta().GetInstanceType(),
74+
)
75+
}
6276
}
6377
}
6478

internal/watcher/health/health_watcher_service_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestHealthWatcherService_UpdateHealthWatcher(t *testing.T) {
5555

5656
assert.Equal(t, instance, healthWatcher.instances[instance.GetInstanceMeta().GetInstanceId()])
5757

58-
healthWatcher.UpdateHealthWatcher([]*mpi.Instance{updatedInstance})
58+
healthWatcher.UpdateHealthWatcher(t.Context(), []*mpi.Instance{updatedInstance})
5959
assert.Equal(t, updatedInstance, healthWatcher.instances[instance.GetInstanceMeta().GetInstanceId()])
6060
}
6161

internal/watcher/watcher_plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ func (w *Watcher) handleCredentialUpdate(ctx context.Context, message credential
303303
func (w *Watcher) handleInstanceUpdates(newCtx context.Context, message instance.ResourceUpdatesMessage) {
304304
if message.Resource != nil {
305305
slog.DebugContext(newCtx, "Resource updated", "resource", message.Resource)
306-
w.healthWatcherService.UpdateHealthWatcher(message.Resource.GetInstances())
306+
w.healthWatcherService.UpdateHealthWatcher(newCtx, message.Resource.GetInstances())
307307

308308
w.messagePipe.Process(newCtx, &bus.Message{Topic: bus.ResourceUpdateTopic, Data: message.Resource})
309309
}

0 commit comments

Comments
 (0)