From 32fc17becb81492b34ddf76c21f6c56ae6956afd Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Fri, 1 Sep 2023 08:45:57 +0200 Subject: [PATCH] ACA Cluster Provider Improvements (#2036) * Add Redis store and manage stale members * Fix ListAsync method of Redis store * Expire current member immediately if replica inactive * Use configured cluster host instead of always finding smallest IP This ensures that whatever the RemoteConfig is bound to, is used. --- .../Actors/AzureContainerAppsClusterMonitor.cs | 5 +++-- .../ClusterProviders/AzureContainerAppsProvider.cs | 9 ++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Proto.Cluster.AzureContainerApps/Actors/AzureContainerAppsClusterMonitor.cs b/src/Proto.Cluster.AzureContainerApps/Actors/AzureContainerAppsClusterMonitor.cs index b1fc29ce34..c005969fcc 100644 --- a/src/Proto.Cluster.AzureContainerApps/Actors/AzureContainerAppsClusterMonitor.cs +++ b/src/Proto.Cluster.AzureContainerApps/Actors/AzureContainerAppsClusterMonitor.cs @@ -150,7 +150,7 @@ private async Task UpdateMembersAsync() var expiredMembers = storedMembers.Where(m => m.UpdatedAt + ttl < now).ToList(); LogStoredMembers(storedMembers); - await UpdateCurrentMember(activeMembers, now); + await UpdateCurrentMember(activeMembers, expiredMembers, now); await RemoveExpiredMembers(expiredMembers); UpdateClusterTopology(activeMembers); @@ -174,7 +174,7 @@ private void LogStoredMembers(ICollection storedMembers) _logger.LogWarning("Did not get any members from {Store}", _clusterMemberStore.GetType().Name); } - private async Task UpdateCurrentMember(ICollection activeMembers, DateTimeOffset now) + private async Task UpdateCurrentMember(ICollection activeMembers, ICollection expiredMembers, DateTimeOffset now) { var currentMember = activeMembers.FirstOrDefault(m => m.Id == _memberId); @@ -187,6 +187,7 @@ private async Task UpdateCurrentMember(ICollection activeMembers, { _logger.LogInformation("Revision {RevisionName} is not active", revisionName); activeMembers.Remove(currentMember); + expiredMembers.Add(currentMember); } else { diff --git a/src/Proto.Cluster.AzureContainerApps/ClusterProviders/AzureContainerAppsProvider.cs b/src/Proto.Cluster.AzureContainerApps/ClusterProviders/AzureContainerAppsProvider.cs index 152477f3de..be9e24d029 100644 --- a/src/Proto.Cluster.AzureContainerApps/ClusterProviders/AzureContainerAppsProvider.cs +++ b/src/Proto.Cluster.AzureContainerApps/ClusterProviders/AzureContainerAppsProvider.cs @@ -3,7 +3,6 @@ using Microsoft.Extensions.Logging; using Proto.Cluster.AzureContainerApps.Actors; using Proto.Cluster.AzureContainerApps.Messages; -using Proto.Cluster.AzureContainerApps.Utils; using Proto.DependencyInjection; namespace Proto.Cluster.AzureContainerApps.ClusterProviders; @@ -15,12 +14,12 @@ namespace Proto.Cluster.AzureContainerApps.ClusterProviders; public class AzureContainerAppsProvider : IClusterProvider { private readonly ILogger _logger; - private readonly string _advertisedHost; private string _address = default!; private Cluster _cluster = default!; private string _clusterName = default!; private string[] _kinds = default!; + private string _host = default!; private int _port; private PID _clusterMonitor = default!; @@ -31,17 +30,17 @@ public class AzureContainerAppsProvider : IClusterProvider public AzureContainerAppsProvider(ILogger logger) { _logger = logger; - _advertisedHost = IPUtils.FindSmallestIpAddress().ToString(); } /// public Task StartMemberAsync(Cluster cluster) { var clusterName = cluster.Config.ClusterName; - var (_, port) = cluster.System.GetAddress(); + var (host, port) = cluster.System.GetAddress(); var kinds = cluster.GetClusterKinds(); _cluster = cluster; _clusterName = clusterName; + _host = host; _port = port; _kinds = kinds; @@ -86,7 +85,7 @@ private void StartClusterMonitor() private void RegisterMember() { // Send a message to register this member, which will also start the cluster monitor. - _cluster.System.Root.Send(_clusterMonitor, new RegisterMember(_clusterName, _advertisedHost, _port, _kinds, _cluster.System.Id)); + _cluster.System.Root.Send(_clusterMonitor, new RegisterMember(_clusterName, _host, _port, _kinds, _cluster.System.Id)); } private void UnregisterMember()