Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the cluster model on destination changes #1568

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/ReverseProxy/Management/ProxyConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,13 @@ private void UpdateRuntimeClusters(IEnumerable<ClusterConfig> incomingClusters)
{
currentCluster.Revision++;
Log.ClusterChanged(_logger, incomingCluster.ClusterId);

// Config changed, so update runtime cluster
currentCluster.Model = newClusterModel;
}

if (destinationsChanged || configChanged)
{
// Config changed, so update runtime cluster
currentCluster.Model = newClusterModel;

_clusterDestinationsUpdater.UpdateAllDestinations(currentCluster);

foreach (var listener in _clusterChangeListeners)
Expand Down
2 changes: 1 addition & 1 deletion src/ReverseProxy/Model/ClusterState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public ClusterDestinationsState DestinationsState
internal AtomicCounter ConcurrencyCounter { get; } = new AtomicCounter();

/// <summary>
/// Tracks changes to the cluster configuration for use with rebuilding dependent endpoints.
/// Tracks changes to the cluster configuration for use with rebuilding dependent endpoints. Destination changes do not affect this property.
/// </summary>
internal int Revision { get; set; }
}
2 changes: 1 addition & 1 deletion src/ReverseProxy/Model/RouteModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public RouteModel(

// May not be populated if the cluster config is missing. https://github.com/microsoft/reverse-proxy/issues/797
/// <summary>
/// The ClusterInfo instance associated with this route.
/// The <see cref="ClusterState"/> instance associated with this route.
/// </summary>
public ClusterState? Cluster { get; }

Expand Down
49 changes: 49 additions & 0 deletions test/ReverseProxy.Tests/Management/ProxyConfigManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,55 @@ public async Task ChangeConfig_ActiveHealthCheckIsEnabled_RunInitialCheck()
Assert.True(activeMonitor.Scheduler.IsScheduled(clusterState));
}

[Fact]
public async Task ChangeConfig_DestinationChange_IsReflectedOnRouteConfiguration()
{
var endpoints = new List<RouteConfig>() { new RouteConfig() { RouteId = "r1", ClusterId = "c1", Match = new RouteMatch { Path = "/" } } };
var clusters = new List<ClusterConfig>()
{
new ClusterConfig
{
ClusterId = "c1",
Destinations = new Dictionary<string, DestinationConfig>(StringComparer.OrdinalIgnoreCase)
{
{ "d1", new DestinationConfig() { Address = "http://d1" } }
}
}
};
var services = CreateServices(endpoints, clusters);
var inMemoryConfig = (InMemoryConfigProvider)services.GetRequiredService<IProxyConfigProvider>();
var configManager = services.GetRequiredService<ProxyConfigManager>();
var dataSource = await configManager.InitialLoadAsync();

var endpoint = Assert.Single(dataSource.Endpoints);
var routeConfig = endpoint.Metadata.GetMetadata<RouteModel>();
Assert.Equal("http://d1", Assert.Single(routeConfig.Cluster.Destinations).Value.Model.Config.Address);
Assert.Equal(1, routeConfig.Cluster.Revision);

inMemoryConfig.Update(
endpoints,
new List<ClusterConfig>()
{
new ClusterConfig
{
ClusterId = "c1",
Destinations = new Dictionary<string, DestinationConfig>(StringComparer.OrdinalIgnoreCase)
{
{ "d1", new DestinationConfig() { Address = "http://d1-v2" } }
}
}
});

var destinationConfig = Assert.Single(routeConfig.Cluster.Destinations).Value.Model.Config;
Assert.Equal("http://d1-v2", destinationConfig.Address);

Assert.Same(destinationConfig, Assert.Single(routeConfig.Cluster.DestinationsState.AllDestinations).Model.Config);
Assert.Same(destinationConfig, Assert.Single(routeConfig.Cluster.Model.Config.Destinations).Value);

// Destination changes do not affect this property
Assert.Equal(1, routeConfig.Cluster.Revision);
}

[Fact]
public async Task LoadAsync_RequestVersionValidationError_Throws()
{
Expand Down