Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal sealed class RoundRobinLoadBalancingPolicy : ILoadBalancingPolicy
return null;
}

var counter = _counters.GetOrCreateValue(context.GetClusterState());
Copy link
Member

@Tratcher Tratcher Jul 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this was the last call to GetClusterState. Can you remove that API as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

var counter = _counters.GetOrCreateValue(cluster);

// Increment returns the new value and we want the first return value to be 0.
var offset = counter.Increment() - 1;
Expand Down
10 changes: 0 additions & 10 deletions src/ReverseProxy/Model/HttpContextFeaturesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ namespace Microsoft.AspNetCore.Http
/// </summary>
public static class HttpContextFeaturesExtensions
{
/// <summary>
/// Retrieves the <see cref="ClusterState"/> instance associated with the current request.
/// </summary>
public static ClusterState GetClusterState(this HttpContext context)
{
var route = context.GetRouteModel();
var cluster = route.Cluster ?? throw new InvalidOperationException($"The {typeof(RouteModel).FullName} is missing the {typeof(ClusterState).FullName}.");
return cluster;
}

/// <summary>
/// Retrieves the <see cref="RouteModel"/> instance associated with the current request.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ public void PickDestination_RoundRobin_Works()

var context = new DefaultHttpContext();

var routeConfig = new RouteModel(new RouteConfig(), new ClusterState("cluster1"), HttpTransformer.Default);
var cluster = new ClusterState("cluster1");
var routeConfig = new RouteModel(new RouteConfig(), cluster, HttpTransformer.Default);
var feature = new ReverseProxyFeature()
{
Route = routeConfig,
Expand All @@ -146,7 +147,7 @@ public void PickDestination_RoundRobin_Works()

for (var i = 0; i < 10; i++)
{
var result = loadBalancer.PickDestination(context, cluster: null, availableDestinations: destinations);
var result = loadBalancer.PickDestination(context, cluster, availableDestinations: destinations);
Assert.Same(destinations[i % destinations.Length], result);
result.ConcurrentRequestCount++;
}
Expand Down