Skip to content
Merged
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
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand All @@ -24,6 +24,8 @@ namespace Frontend.Balancer
{
public class ConfigurableResolverFactory : ResolverFactory
{
private static readonly BalancerAttributesKey<string> HostOverrideKey = new BalancerAttributesKey<string>("HostOverride");
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a little curious why we don't work directly with "HostOverride", rather than wrapping and unwrapping it, but I'm assuming this is idiomatic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Its a pattern copied from the HttpRequestOptions collection. It's designed to make the collection feel a little more strongly typed.


private readonly ResolverFactory _innerResolverFactory;
private readonly BalancerConfiguration _balancerConfiguration;

Expand Down Expand Up @@ -101,6 +103,13 @@ private void RaiseResult(ResolverResult result)
// DNS results change order between refreshes.
// Explicitly order by host to keep result order consistent.
var orderedAddresses = result.Addresses.OrderBy(a => a.EndPoint.Host).ToList();
// Remove host override from addresses so the destination IP address is available.
// The sample does this because the server returns the IP address to the client.
// This makes it clear that gRPC calls are balanced between pods.
foreach (var address in orderedAddresses)
{
((IDictionary<string, object?>)address.Attributes).Remove(HostOverrideKey.Key);
}
_listener(ResolverResult.ForResult(orderedAddresses, serviceConfig, Status.DefaultSuccess));
}
else
Expand Down