From 8e5b42e54e57d6921b6bc5c0d8e9ab79a52e90e3 Mon Sep 17 00:00:00 2001 From: Niclas Pehrsson Date: Wed, 24 Jan 2024 14:07:41 +0100 Subject: [PATCH] Make it possible to disable verification of RevisionHasTrafficEnabled for the ACA provider (#2080) --- .../AzureContainerAppsClusterMonitor.cs | 42 +++++++++++-------- .../AzureContainerAppsProviderOptions.cs | 5 +++ 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/Proto.Cluster.AzureContainerApps/Actors/AzureContainerAppsClusterMonitor.cs b/src/Proto.Cluster.AzureContainerApps/Actors/AzureContainerAppsClusterMonitor.cs index c005969fcc..94d90ee55d 100644 --- a/src/Proto.Cluster.AzureContainerApps/Actors/AzureContainerAppsClusterMonitor.cs +++ b/src/Proto.Cluster.AzureContainerApps/Actors/AzureContainerAppsClusterMonitor.cs @@ -180,21 +180,24 @@ private async Task UpdateCurrentMember(ICollection activeMembers, if (currentMember is not null) { - var canReceiveTraffic = await CanReceiveTrafficAsync().ConfigureAwait(false); - var revisionName = _containerAppMetadata.RevisionName; - - if (!canReceiveTraffic) - { - _logger.LogInformation("Revision {RevisionName} is not active", revisionName); - activeMembers.Remove(currentMember); - expiredMembers.Add(currentMember); - } - else + if (_options.Value.IsVerifyRevisionHasTrafficEnabled) { - _logger.LogInformation("Updating current member {MemberId} on {MemberAddress}", currentMember.Id, currentMember.Address); - currentMember = currentMember with { UpdatedAt = now }; - await _clusterMemberStore.UpdateAsync(currentMember).ConfigureAwait(false); + var canReceiveTraffic = await CanReceiveTrafficAsync().ConfigureAwait(false); + + if (!canReceiveTraffic) + { + var revisionName = _containerAppMetadata.RevisionName; + + _logger.LogInformation("Revision {RevisionName} is not active", revisionName); + activeMembers.Remove(currentMember); + expiredMembers.Add(currentMember); + return; + } } + + _logger.LogInformation("Updating current member {MemberId} on {MemberAddress}", currentMember.Id, currentMember.Address); + currentMember = currentMember with { UpdatedAt = now }; + await _clusterMemberStore.UpdateAsync(currentMember).ConfigureAwait(false); } } @@ -228,12 +231,15 @@ private async Task AddMember() private async Task AddMemberInternal() { - var canReceiveTraffic = await CanReceiveTrafficAsync().ConfigureAwait(false); - - if (!canReceiveTraffic) + if (_options.Value.IsVerifyRevisionHasTrafficEnabled) { - _logger.LogInformation("Revision {RevisionName} is not active", _containerAppMetadata.RevisionName); - return; + var canReceiveTraffic = await CanReceiveTrafficAsync().ConfigureAwait(false); + + if (!canReceiveTraffic) + { + _logger.LogInformation("Revision {RevisionName} is not active", _containerAppMetadata.RevisionName); + return; + } } var member = new Member diff --git a/src/Proto.Cluster.AzureContainerApps/Options/AzureContainerAppsProviderOptions.cs b/src/Proto.Cluster.AzureContainerApps/Options/AzureContainerAppsProviderOptions.cs index 05afd64834..4c6f8175f5 100644 --- a/src/Proto.Cluster.AzureContainerApps/Options/AzureContainerAppsProviderOptions.cs +++ b/src/Proto.Cluster.AzureContainerApps/Options/AzureContainerAppsProviderOptions.cs @@ -32,4 +32,9 @@ public class AzureContainerAppsProviderOptions /// The actual TTL is determined by the and the by adding them together. /// public TimeSpan MemberTimeToLive { get; set; } = TimeSpan.FromMinutes(1); + /// + /// If set to true, the provider will verify that the revision that this replica is part of has 1 or more percent of the traffic. + /// If not it won't be added to the cluster, and if already added it will be removed. + /// + public bool IsVerifyRevisionHasTrafficEnabled { get; set; } = true; } \ No newline at end of file