Skip to content

Commit

Permalink
Merge conflicts, cleanup, naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Tratcher committed Dec 15, 2020
1 parent f27e9f1 commit f4c21d0
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 23 deletions.
2 changes: 1 addition & 1 deletion samples/ReverseProxy.Config.Sample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void Configure(IApplicationBuilder app)
proxyPipeline.UseRequestAffinitizer();
proxyPipeline.UsePassiveHealthChecks();
})
.Configure((builder, route) => builder.WithDisplayName($"ReverseProxy {route.RouteId}-{route.ClusterId}"));
.ConfigureEndpoints((builder, route) => builder.WithDisplayName($"ReverseProxy {route.RouteId}-{route.ClusterId}"));
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -32,7 +35,7 @@ public void Add(Action<EndpointBuilder> convention)
/// </summary>
/// <param name="convention">The convention to add to the builder.</param>
/// <returns></returns>
public ReverseProxyConventionBuilder Configure(Action<IEndpointConventionBuilder> convention)
public ReverseProxyConventionBuilder ConfigureEndpoints(Action<IEndpointConventionBuilder> convention)
{
_ = convention ?? throw new ArgumentNullException(nameof(convention));

Expand All @@ -52,7 +55,7 @@ void Action(EndpointBuilder endpointBuilder)
/// </summary>
/// <param name="convention">The convention to add to the builder.</param>
/// <returns></returns>
public ReverseProxyConventionBuilder Configure(Action<IEndpointConventionBuilder, ProxyRoute> convention)
public ReverseProxyConventionBuilder ConfigureEndpoints(Action<IEndpointConventionBuilder, ProxyRoute> convention)
{
_ = convention ?? throw new ArgumentNullException(nameof(convention));

Expand All @@ -73,7 +76,7 @@ void Action(EndpointBuilder endpointBuilder)
/// </summary>
/// <param name="convention">The convention to add to the builder.</param>
/// <returns></returns>
public ReverseProxyConventionBuilder Configure(Action<IEndpointConventionBuilder, ProxyRoute, Cluster> convention)
public ReverseProxyConventionBuilder ConfigureEndpoints(Action<IEndpointConventionBuilder, ProxyRoute, Cluster> convention)
{
_ = convention ?? throw new ArgumentNullException(nameof(convention));

Expand All @@ -92,7 +95,7 @@ void Action(EndpointBuilder endpointBuilder)
return this;
}

internal class EndpointBuilderConventionBuilder : IEndpointConventionBuilder
private class EndpointBuilderConventionBuilder : IEndpointConventionBuilder
{
private readonly EndpointBuilder _endpointBuilder;

Expand Down
20 changes: 7 additions & 13 deletions src/ReverseProxy/Service/Management/ProxyConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ private void Initialize()

private void CreateEndpoints()
{
var endpoints = new List<Endpoint>();
foreach (var existingRoute in _routeManager.GetItems())
var routes = _routeManager.GetItems();
var endpoints = new List<Endpoint>(routes.Count);
foreach (var existingRoute in routes)
{
var runtimeConfig = existingRoute.Config;
// Only rebuild the endpoint for modified routes or clusters.
var endpoint = existingRoute.CachedEndpoint;
if (endpoint == null)
{
endpoint = _proxyEndpointFactory.CreateEndpoint(runtimeConfig, _conventions);
endpoint = _proxyEndpointFactory.CreateEndpoint(existingRoute.Config, _conventions);
existingRoute.CachedEndpoint = endpoint;
}
endpoints.Add(endpoint);
Expand Down Expand Up @@ -214,9 +214,9 @@ private async Task<bool> ApplyConfigAsync(IProxyConfig config)
}

// Update clusters first because routes need to reference them.
var clustersChanged = UpdateRuntimeClusters(configuredClusters);
UpdateRuntimeClusters(configuredClusters);
var routesChanged = UpdateRuntimeRoutes(configuredRoutes);
return routesChanged || clustersChanged;
return routesChanged;
}

private async Task<(IList<ProxyRoute>, IList<Exception>)> VerifyRoutesAsync(IReadOnlyList<ProxyRoute> routes, CancellationToken cancellation)
Expand Down Expand Up @@ -326,10 +326,9 @@ private async Task<bool> ApplyConfigAsync(IProxyConfig config)
return (configuredClusters, errors);
}

private bool UpdateRuntimeClusters(IList<Cluster> newClusters)
private void UpdateRuntimeClusters(IList<Cluster> newClusters)
{
var desiredClusters = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
var changed = false;

foreach (var newCluster in newClusters)
{
Expand Down Expand Up @@ -408,15 +407,12 @@ private bool UpdateRuntimeClusters(IList<Cluster> newClusters)

currentCluster.ForceUpdateDynamicState();
});

changed |= clusterChanged;
}

foreach (var existingCluster in _clusterManager.GetItems())
{
if (!desiredClusters.Contains(existingCluster.ClusterId))
{
changed = true;
// NOTE 1: This is safe to do within the `foreach` loop
// because `IClusterManager.GetItems` returns a copy of the list of clusters.
//
Expand All @@ -427,8 +423,6 @@ private bool UpdateRuntimeClusters(IList<Cluster> newClusters)
_clusterManager.TryRemoveItem(existingCluster.ClusterId);
}
}

return changed;
}

private bool UpdateRuntimeDestinations(IDictionary<string, Destination> newDestinations, IDestinationManager destinationManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void ReverseProxyConventionBuilder_Configure_Works()
var conventions = new List<Action<EndpointBuilder>>();
var builder = new ReverseProxyConventionBuilder(conventions);

builder.Configure(builder =>
builder.ConfigureEndpoints(builder =>
{
configured = true;
});
Expand All @@ -47,7 +47,7 @@ public void ReverseProxyConventionBuilder_ConfigureWithProxy_Works()
var conventions = new List<Action<EndpointBuilder>>();
var builder = new ReverseProxyConventionBuilder(conventions);

builder.Configure((builder, proxy) =>
builder.ConfigureEndpoints((builder, proxy) =>
{
configured = true;
});
Expand All @@ -70,7 +70,7 @@ public void ReverseProxyConventionBuilder_ConfigureWithProxyAndCluster_Works()
var conventions = new List<Action<EndpointBuilder>>();
var builder = new ReverseProxyConventionBuilder(conventions);

builder.Configure((builder, proxy, cluster) =>
builder.ConfigureEndpoints((builder, proxy, cluster) =>
{
configured = true;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private static HttpContext CreateContext(string loadBalancingPolicy, IReadOnlyLi
});
context.Features.Set(cluster);

var routeConfig = new RouteConfig(new RouteInfo("route-1"), new ProxyRoute(), cluster, Array.Empty<Endpoint>(), transforms: null);
var routeConfig = new RouteConfig(new RouteInfo("route-1"), new ProxyRoute(), cluster, transforms: null);
var endpoint = new Endpoint(default, new EndpointMetadataCollection(routeConfig), string.Empty);
context.SetEndpoint(endpoint);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void PickDestination_RoundRobin_Works()

var context = new DefaultHttpContext();

var routeConfig = new RouteConfig(new RouteInfo("route-1"), new ProxyRoute(), new ClusterInfo("cluster1", new DestinationManager()), Array.Empty<Endpoint>(), transforms: null);
var routeConfig = new RouteConfig(new RouteInfo("route-1"), new ProxyRoute(), new ClusterInfo("cluster1", new DestinationManager()), transforms: null);
var endpoint = new Endpoint(default, new EndpointMetadataCollection(routeConfig), string.Empty);
context.SetEndpoint(endpoint);

Expand Down

0 comments on commit f4c21d0

Please sign in to comment.