]> git.feebdaed.xyz Git - 0xmirror/grpc-go.git/commitdiff
xds: refactor xdsresource.Endpoint to add resolver.Endpoint (gRFC A81) (#8750)
authorPranjali-2501 <87357388+Pranjali-2501@users.noreply.github.com>
Tue, 16 Dec 2025 02:47:44 +0000 (08:17 +0530)
committerGitHub <noreply@github.com>
Tue, 16 Dec 2025 02:47:44 +0000 (08:17 +0530)
This PR updates the internal `xdsresource.Endpoint` struct to contain a
`resolver.Endpoint` instead of a `[]string` to store the list of
addresses associated with the endpoint [gRFC
A81](https://github.com/grpc/proposal/blob/master/A81-xds-authority-rewriting.md).
This change standardizes how backend information is stored and ensures
that attributes (such as Hostname) are correctly associated with the
endpoint hierarchy.

### Key Changes:

 **Struct Update:**
* `xdsresource.Endpoint` now includes a `ResolverEndpoint` field (of
type `resolver.Endpoint`) to store addresses and attributes. Remove the
existing `Address` field (of type `[]string`) and store address as a
`resolver.Endpoint` field.

**Attribute Handling:**
* Added `SetHostname` and `GetHostname` helpers to manage hostname
metadata within `resolver.Endpoint.Attributes`.

 **Parsing Logic:**
* Updated `parseEndpoints` in `unmarshal_eds.go` to correctly populate
the `resolver.Endpoint` object.

RELEASE NOTES: N/A

internal/xds/balancer/clusterresolver/configbuilder.go
internal/xds/balancer/clusterresolver/configbuilder_test.go
internal/xds/xdsclient/tests/eds_watchers_test.go
internal/xds/xdsclient/tests/federation_watchers_test.go
internal/xds/xdsclient/tests/resource_update_test.go
internal/xds/xdsclient/xdsresource/type_eds.go
internal/xds/xdsclient/xdsresource/unmarshal_eds.go
internal/xds/xdsclient/xdsresource/unmarshal_eds_test.go
resolver/resolver.go

index 3d8e08972c1dfed0bc9dc930bed942b45ef95b8b..6aabc935bc7811276746c5d2f7d3a5a86615c5ed 100644 (file)
@@ -21,6 +21,7 @@ package clusterresolver
 import (
        "encoding/json"
        "fmt"
+       "slices"
        "sort"
 
        "google.golang.org/grpc/internal/balancer/weight"
@@ -265,10 +266,13 @@ func priorityLocalitiesToClusterImpl(localities []xdsresource.Locality, priority
                        if endpoint.HealthStatus != xdsresource.EndpointHealthStatusHealthy && endpoint.HealthStatus != xdsresource.EndpointHealthStatusUnknown {
                                continue
                        }
-                       resolverEndpoint := resolver.Endpoint{}
-                       for _, as := range endpoint.Addresses {
-                               resolverEndpoint.Addresses = append(resolverEndpoint.Addresses, resolver.Address{Addr: as})
-                       }
+
+                       // Create a copy of endpoint.ResolverEndpoint to avoid race between
+                       // the xDS Client (which owns this shared object in its cache) and
+                       // the Cluster Resolver (which is trying to modify attributes).
+                       resolverEndpoint := endpoint.ResolverEndpoint
+                       resolverEndpoint.Addresses = slices.Clone(endpoint.ResolverEndpoint.Addresses)
+
                        resolverEndpoint = hierarchy.SetInEndpoint(resolverEndpoint, []string{priorityName, localityStr})
                        resolverEndpoint = xdsinternal.SetLocalityIDInEndpoint(resolverEndpoint, locality.ID)
                        // "To provide the xds_wrr_locality load balancer information about
index 571b756484e2714b6d807cad128af75e8f38c591..af6f8d5bd85db966c62fcc7a1b662c20e22ebe84 100644 (file)
@@ -95,10 +95,12 @@ func init() {
                        endpoints = append(endpoints, resolver.Endpoint{Addresses: []resolver.Address{{Addr: addr}}})
                        ends = append(ends, xdsresource.Endpoint{
                                HealthStatus: xdsresource.EndpointHealthStatusHealthy,
-                               Addresses: []string{
-                                       addr,
-                                       fmt.Sprintf("addr-%d-%d-additional-1", i, j),
-                                       fmt.Sprintf("addr-%d-%d-additional-2", i, j),
+                               ResolverEndpoint: resolver.Endpoint{
+                                       Addresses: []resolver.Address{
+                                               {Addr: addr},
+                                               {Addr: fmt.Sprintf("addr-%d-%d-additional-1", i, j)},
+                                               {Addr: fmt.Sprintf("addr-%d-%d-additional-2", i, j)},
+                                       },
                                },
                        })
                }
@@ -315,8 +317,8 @@ func TestBuildClusterImplConfigForDNS(t *testing.T) {
                        Name: "pick_first",
                },
        }
-       e1 := resolver.Endpoint{Addresses: []resolver.Address{{Addr: testEndpoints[0][0].Addresses[0]}}}
-       e2 := resolver.Endpoint{Addresses: []resolver.Address{{Addr: testEndpoints[0][1].Addresses[0]}}}
+       e1 := resolver.Endpoint{Addresses: []resolver.Address{{Addr: testEndpoints[0][0].ResolverEndpoint.Addresses[0].Addr}}}
+       e2 := resolver.Endpoint{Addresses: []resolver.Address{{Addr: testEndpoints[0][1].ResolverEndpoint.Addresses[0].Addr}}}
        wantEndpoints := []resolver.Endpoint{
                hierarchy.SetInEndpoint(e1, []string{"priority-3"}),
                hierarchy.SetInEndpoint(e2, []string{"priority-3"}),
@@ -417,14 +419,14 @@ func TestBuildClusterImplConfigForEDS(t *testing.T) {
                },
        }
        wantEndpoints := []resolver.Endpoint{
-               testEndpointWithAttrs(testEndpoints[0][0].Addresses, 20, 1, "priority-2-0", &testLocalityIDs[0]),
-               testEndpointWithAttrs(testEndpoints[0][1].Addresses, 20, 1, "priority-2-0", &testLocalityIDs[0]),
-               testEndpointWithAttrs(testEndpoints[1][0].Addresses, 80, 1, "priority-2-0", &testLocalityIDs[1]),
-               testEndpointWithAttrs(testEndpoints[1][1].Addresses, 80, 1, "priority-2-0", &testLocalityIDs[1]),
-               testEndpointWithAttrs(testEndpoints[2][0].Addresses, 20, 1, "priority-2-1", &testLocalityIDs[2]),
-               testEndpointWithAttrs(testEndpoints[2][1].Addresses, 20, 1, "priority-2-1", &testLocalityIDs[2]),
-               testEndpointWithAttrs(testEndpoints[3][0].Addresses, 80, 1, "priority-2-1", &testLocalityIDs[3]),
-               testEndpointWithAttrs(testEndpoints[3][1].Addresses, 80, 1, "priority-2-1", &testLocalityIDs[3]),
+               testEndpointWithAttrs(testEndpoints[0][0].ResolverEndpoint, 20, 1, "priority-2-0", &testLocalityIDs[0]),
+               testEndpointWithAttrs(testEndpoints[0][1].ResolverEndpoint, 20, 1, "priority-2-0", &testLocalityIDs[0]),
+               testEndpointWithAttrs(testEndpoints[1][0].ResolverEndpoint, 80, 1, "priority-2-0", &testLocalityIDs[1]),
+               testEndpointWithAttrs(testEndpoints[1][1].ResolverEndpoint, 80, 1, "priority-2-0", &testLocalityIDs[1]),
+               testEndpointWithAttrs(testEndpoints[2][0].ResolverEndpoint, 20, 1, "priority-2-1", &testLocalityIDs[2]),
+               testEndpointWithAttrs(testEndpoints[2][1].ResolverEndpoint, 20, 1, "priority-2-1", &testLocalityIDs[2]),
+               testEndpointWithAttrs(testEndpoints[3][0].ResolverEndpoint, 80, 1, "priority-2-1", &testLocalityIDs[3]),
+               testEndpointWithAttrs(testEndpoints[3][1].ResolverEndpoint, 80, 1, "priority-2-1", &testLocalityIDs[3]),
        }
 
        if diff := cmp.Diff(gotNames, wantNames); diff != "" {
@@ -547,16 +549,32 @@ func TestPriorityLocalitiesToClusterImpl(t *testing.T) {
                localities: []xdsresource.Locality{
                        {
                                Endpoints: []xdsresource.Endpoint{
-                                       {Addresses: []string{"addr-1-1"}, HealthStatus: xdsresource.EndpointHealthStatusHealthy, Weight: 90},
-                                       {Addresses: []string{"addr-1-2"}, HealthStatus: xdsresource.EndpointHealthStatusHealthy, Weight: 10},
+                                       {
+                                               ResolverEndpoint: resolver.Endpoint{Addresses: []resolver.Address{{Addr: "addr-1-1"}}},
+                                               Weight:           90,
+                                               HealthStatus:     xdsresource.EndpointHealthStatusHealthy,
+                                       },
+                                       {
+                                               ResolverEndpoint: resolver.Endpoint{Addresses: []resolver.Address{{Addr: "addr-1-2"}}},
+                                               Weight:           10,
+                                               HealthStatus:     xdsresource.EndpointHealthStatusHealthy,
+                                       },
                                },
                                ID:     clients.Locality{Zone: "test-zone-1"},
                                Weight: 20,
                        },
                        {
                                Endpoints: []xdsresource.Endpoint{
-                                       {Addresses: []string{"addr-2-1"}, HealthStatus: xdsresource.EndpointHealthStatusHealthy, Weight: 90},
-                                       {Addresses: []string{"addr-2-2"}, HealthStatus: xdsresource.EndpointHealthStatusHealthy, Weight: 10},
+                                       {
+                                               ResolverEndpoint: resolver.Endpoint{Addresses: []resolver.Address{{Addr: "addr-2-1"}}},
+                                               Weight:           90,
+                                               HealthStatus:     xdsresource.EndpointHealthStatusHealthy,
+                                       },
+                                       {
+                                               ResolverEndpoint: resolver.Endpoint{Addresses: []resolver.Address{{Addr: "addr-2-2"}}},
+                                               Weight:           10,
+                                               HealthStatus:     xdsresource.EndpointHealthStatusHealthy,
+                                       },
                                },
                                ID:     clients.Locality{Zone: "test-zone-2"},
                                Weight: 80,
@@ -576,10 +594,10 @@ func TestPriorityLocalitiesToClusterImpl(t *testing.T) {
                        ChildPolicy:    &iserviceconfig.BalancerConfig{Name: roundrobin.Name},
                },
                wantEndpoints: []resolver.Endpoint{
-                       testEndpointWithAttrs([]string{"addr-1-1"}, 20, 90, "test-priority", &clients.Locality{Zone: "test-zone-1"}),
-                       testEndpointWithAttrs([]string{"addr-1-2"}, 20, 10, "test-priority", &clients.Locality{Zone: "test-zone-1"}),
-                       testEndpointWithAttrs([]string{"addr-2-1"}, 80, 90, "test-priority", &clients.Locality{Zone: "test-zone-2"}),
-                       testEndpointWithAttrs([]string{"addr-2-2"}, 80, 10, "test-priority", &clients.Locality{Zone: "test-zone-2"}),
+                       testEndpointWithAttrs(resolver.Endpoint{Addresses: []resolver.Address{{Addr: "addr-1-1"}}}, 20, 90, "test-priority", &clients.Locality{Zone: "test-zone-1"}),
+                       testEndpointWithAttrs(resolver.Endpoint{Addresses: []resolver.Address{{Addr: "addr-1-2"}}}, 20, 10, "test-priority", &clients.Locality{Zone: "test-zone-1"}),
+                       testEndpointWithAttrs(resolver.Endpoint{Addresses: []resolver.Address{{Addr: "addr-2-1"}}}, 80, 90, "test-priority", &clients.Locality{Zone: "test-zone-2"}),
+                       testEndpointWithAttrs(resolver.Endpoint{Addresses: []resolver.Address{{Addr: "addr-2-2"}}}, 80, 10, "test-priority", &clients.Locality{Zone: "test-zone-2"}),
                },
        },
                {
@@ -587,16 +605,32 @@ func TestPriorityLocalitiesToClusterImpl(t *testing.T) {
                        localities: []xdsresource.Locality{
                                {
                                        Endpoints: []xdsresource.Endpoint{
-                                               {Addresses: []string{"addr-1-1"}, HealthStatus: xdsresource.EndpointHealthStatusHealthy, Weight: 90},
-                                               {Addresses: []string{"addr-1-2"}, HealthStatus: xdsresource.EndpointHealthStatusHealthy, Weight: 10},
+                                               {
+                                                       ResolverEndpoint: resolver.Endpoint{Addresses: []resolver.Address{{Addr: "addr-1-1"}}},
+                                                       Weight:           90,
+                                                       HealthStatus:     xdsresource.EndpointHealthStatusHealthy,
+                                               },
+                                               {
+                                                       ResolverEndpoint: resolver.Endpoint{Addresses: []resolver.Address{{Addr: "addr-1-2"}}},
+                                                       Weight:           10,
+                                                       HealthStatus:     xdsresource.EndpointHealthStatusHealthy,
+                                               },
                                        },
                                        ID:     clients.Locality{Zone: "test-zone-1"},
                                        Weight: 20,
                                },
                                {
                                        Endpoints: []xdsresource.Endpoint{
-                                               {Addresses: []string{"addr-2-1"}, HealthStatus: xdsresource.EndpointHealthStatusHealthy, Weight: 90},
-                                               {Addresses: []string{"addr-2-2"}, HealthStatus: xdsresource.EndpointHealthStatusHealthy, Weight: 10},
+                                               {
+                                                       ResolverEndpoint: resolver.Endpoint{Addresses: []resolver.Address{{Addr: "addr-2-1"}}},
+                                                       Weight:           90,
+                                                       HealthStatus:     xdsresource.EndpointHealthStatusHealthy,
+                                               },
+                                               {
+                                                       ResolverEndpoint: resolver.Endpoint{Addresses: []resolver.Address{{Addr: "addr-2-2"}}},
+                                                       Weight:           10,
+                                                       HealthStatus:     xdsresource.EndpointHealthStatusHealthy,
+                                               },
                                        },
                                        ID:     clients.Locality{Zone: "test-zone-2"},
                                        Weight: 80,
@@ -612,10 +646,10 @@ func TestPriorityLocalitiesToClusterImpl(t *testing.T) {
                                },
                        },
                        wantEndpoints: []resolver.Endpoint{
-                               testEndpointWithAttrs([]string{"addr-1-1"}, 20, 90, "test-priority", &clients.Locality{Zone: "test-zone-1"}),
-                               testEndpointWithAttrs([]string{"addr-1-2"}, 20, 10, "test-priority", &clients.Locality{Zone: "test-zone-1"}),
-                               testEndpointWithAttrs([]string{"addr-2-1"}, 80, 90, "test-priority", &clients.Locality{Zone: "test-zone-2"}),
-                               testEndpointWithAttrs([]string{"addr-2-2"}, 80, 10, "test-priority", &clients.Locality{Zone: "test-zone-2"}),
+                               testEndpointWithAttrs(resolver.Endpoint{Addresses: []resolver.Address{{Addr: "addr-1-1"}}}, 20, 90, "test-priority", &clients.Locality{Zone: "test-zone-1"}),
+                               testEndpointWithAttrs(resolver.Endpoint{Addresses: []resolver.Address{{Addr: "addr-1-2"}}}, 20, 10, "test-priority", &clients.Locality{Zone: "test-zone-1"}),
+                               testEndpointWithAttrs(resolver.Endpoint{Addresses: []resolver.Address{{Addr: "addr-2-1"}}}, 80, 90, "test-priority", &clients.Locality{Zone: "test-zone-2"}),
+                               testEndpointWithAttrs(resolver.Endpoint{Addresses: []resolver.Address{{Addr: "addr-2-2"}}}, 80, 10, "test-priority", &clients.Locality{Zone: "test-zone-2"}),
                        },
                },
        }
@@ -635,11 +669,7 @@ func TestPriorityLocalitiesToClusterImpl(t *testing.T) {
        }
 }
 
-func testEndpointWithAttrs(addrStrs []string, localityWeight, endpointWeight uint32, priority string, lID *clients.Locality) resolver.Endpoint {
-       endpoint := resolver.Endpoint{}
-       for _, a := range addrStrs {
-               endpoint.Addresses = append(endpoint.Addresses, resolver.Address{Addr: a})
-       }
+func testEndpointWithAttrs(endpoint resolver.Endpoint, localityWeight, endpointWeight uint32, priority string, lID *clients.Locality) resolver.Endpoint {
        path := []string{priority}
        if lID != nil {
                path = append(path, xdsinternal.LocalityString(*lID))
index d367e12d7a51566aec01a41f75e0bed9ede41d72..1192c20a7ee2ddcd738ba1e7aca9f3b8ac504cbb 100644 (file)
@@ -36,6 +36,7 @@ import (
        "google.golang.org/grpc/internal/xds/clients"
        "google.golang.org/grpc/internal/xds/xdsclient"
        "google.golang.org/grpc/internal/xds/xdsclient/xdsresource"
+       "google.golang.org/grpc/resolver"
        "google.golang.org/protobuf/types/known/wrapperspb"
 
        v3endpointpb "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
@@ -176,7 +177,12 @@ func (s) TestEDSWatch(t *testing.T) {
                                update: xdsresource.EndpointsUpdate{
                                        Localities: []xdsresource.Locality{
                                                {
-                                                       Endpoints: []xdsresource.Endpoint{{Addresses: []string{fmt.Sprintf("%s:%d", edsHost1, edsPort1)}, Weight: 1}},
+                                                       Endpoints: []xdsresource.Endpoint{{
+                                                               ResolverEndpoint: resolver.Endpoint{
+                                                                       Addresses: []resolver.Address{{Addr: fmt.Sprintf("%s:%d", edsHost1, edsPort1)}},
+                                                               },
+                                                               Weight: 1,
+                                                       }},
                                                        ID: clients.Locality{
                                                                Region:  "region-1",
                                                                Zone:    "zone-1",
@@ -199,7 +205,12 @@ func (s) TestEDSWatch(t *testing.T) {
                                update: xdsresource.EndpointsUpdate{
                                        Localities: []xdsresource.Locality{
                                                {
-                                                       Endpoints: []xdsresource.Endpoint{{Addresses: []string{fmt.Sprintf("%s:%d", edsHost1, edsPort1)}, Weight: 1}},
+                                                       Endpoints: []xdsresource.Endpoint{{
+                                                               ResolverEndpoint: resolver.Endpoint{
+                                                                       Addresses: []resolver.Address{{Addr: fmt.Sprintf("%s:%d", edsHost1, edsPort1)}},
+                                                               },
+                                                               Weight: 1,
+                                                       }},
                                                        ID: clients.Locality{
                                                                Region:  "region-1",
                                                                Zone:    "zone-1",
@@ -338,7 +349,12 @@ func (s) TestEDSWatch_TwoWatchesForSameResourceName(t *testing.T) {
                                update: xdsresource.EndpointsUpdate{
                                        Localities: []xdsresource.Locality{
                                                {
-                                                       Endpoints: []xdsresource.Endpoint{{Addresses: []string{fmt.Sprintf("%s:%d", edsHost1, edsPort1)}, Weight: 1}},
+                                                       Endpoints: []xdsresource.Endpoint{{
+                                                               ResolverEndpoint: resolver.Endpoint{
+                                                                       Addresses: []resolver.Address{{Addr: fmt.Sprintf("%s:%d", edsHost1, edsPort1)}},
+                                                               },
+                                                               Weight: 1,
+                                                       }},
                                                        ID: clients.Locality{
                                                                Region:  "region-1",
                                                                Zone:    "zone-1",
@@ -354,7 +370,12 @@ func (s) TestEDSWatch_TwoWatchesForSameResourceName(t *testing.T) {
                                update: xdsresource.EndpointsUpdate{
                                        Localities: []xdsresource.Locality{
                                                {
-                                                       Endpoints: []xdsresource.Endpoint{{Addresses: []string{fmt.Sprintf("%s:%d", edsHost2, edsPort2)}, Weight: 1}},
+                                                       Endpoints: []xdsresource.Endpoint{{
+                                                               ResolverEndpoint: resolver.Endpoint{
+                                                                       Addresses: []resolver.Address{{Addr: fmt.Sprintf("%s:%d", edsHost2, edsPort2)}},
+                                                               },
+                                                               Weight: 1,
+                                                       }},
                                                        ID: clients.Locality{
                                                                Region:  "region-1",
                                                                Zone:    "zone-1",
@@ -376,7 +397,12 @@ func (s) TestEDSWatch_TwoWatchesForSameResourceName(t *testing.T) {
                                update: xdsresource.EndpointsUpdate{
                                        Localities: []xdsresource.Locality{
                                                {
-                                                       Endpoints: []xdsresource.Endpoint{{Addresses: []string{fmt.Sprintf("%s:%d", edsHost1, edsPort1)}, Weight: 1}},
+                                                       Endpoints: []xdsresource.Endpoint{{
+                                                               ResolverEndpoint: resolver.Endpoint{
+                                                                       Addresses: []resolver.Address{{Addr: fmt.Sprintf("%s:%d", edsHost1, edsPort1)}},
+                                                               },
+                                                               Weight: 1,
+                                                       }},
                                                        ID: clients.Locality{
                                                                Region:  "region-1",
                                                                Zone:    "zone-1",
@@ -392,7 +418,12 @@ func (s) TestEDSWatch_TwoWatchesForSameResourceName(t *testing.T) {
                                update: xdsresource.EndpointsUpdate{
                                        Localities: []xdsresource.Locality{
                                                {
-                                                       Endpoints: []xdsresource.Endpoint{{Addresses: []string{fmt.Sprintf("%s:%d", edsHost2, edsPort2)}, Weight: 1}},
+                                                       Endpoints: []xdsresource.Endpoint{{
+                                                               ResolverEndpoint: resolver.Endpoint{
+                                                                       Addresses: []resolver.Address{{Addr: fmt.Sprintf("%s:%d", edsHost2, edsPort2)}},
+                                                               },
+                                                               Weight: 1,
+                                                       }},
                                                        ID: clients.Locality{
                                                                Region:  "region-1",
                                                                Zone:    "zone-1",
@@ -590,7 +621,12 @@ func (s) TestEDSWatch_ThreeWatchesForDifferentResourceNames(t *testing.T) {
                update: xdsresource.EndpointsUpdate{
                        Localities: []xdsresource.Locality{
                                {
-                                       Endpoints: []xdsresource.Endpoint{{Addresses: []string{fmt.Sprintf("%s:%d", edsHost1, edsPort1)}, Weight: 1}},
+                                       Endpoints: []xdsresource.Endpoint{{
+                                               ResolverEndpoint: resolver.Endpoint{
+                                                       Addresses: []resolver.Address{{Addr: fmt.Sprintf("%s:%d", edsHost1, edsPort1)}},
+                                               },
+                                               Weight: 1,
+                                       }},
                                        ID: clients.Locality{
                                                Region:  "region-1",
                                                Zone:    "zone-1",
@@ -681,7 +717,12 @@ func (s) TestEDSWatch_ResourceCaching(t *testing.T) {
                update: xdsresource.EndpointsUpdate{
                        Localities: []xdsresource.Locality{
                                {
-                                       Endpoints: []xdsresource.Endpoint{{Addresses: []string{fmt.Sprintf("%s:%d", edsHost1, edsPort1)}, Weight: 1}},
+                                       Endpoints: []xdsresource.Endpoint{{
+                                               ResolverEndpoint: resolver.Endpoint{
+                                                       Addresses: []resolver.Address{{Addr: fmt.Sprintf("%s:%d", edsHost1, edsPort1)}},
+                                               },
+                                               Weight: 1,
+                                       }},
                                        ID: clients.Locality{
                                                Region:  "region-1",
                                                Zone:    "zone-1",
@@ -813,7 +854,12 @@ func (s) TestEDSWatch_ValidResponseCancelsExpiryTimerBehavior(t *testing.T) {
                update: xdsresource.EndpointsUpdate{
                        Localities: []xdsresource.Locality{
                                {
-                                       Endpoints: []xdsresource.Endpoint{{Addresses: []string{fmt.Sprintf("%s:%d", edsHost1, edsPort1)}, Weight: 1}},
+                                       Endpoints: []xdsresource.Endpoint{{
+                                               ResolverEndpoint: resolver.Endpoint{
+                                                       Addresses: []resolver.Address{{Addr: fmt.Sprintf("%s:%d", edsHost1, edsPort1)}},
+                                               },
+                                               Weight: 1,
+                                       }},
                                        ID: clients.Locality{
                                                Region:  "region-1",
                                                Zone:    "zone-1",
@@ -976,7 +1022,12 @@ func (s) TestEDSWatch_PartialValid(t *testing.T) {
                update: xdsresource.EndpointsUpdate{
                        Localities: []xdsresource.Locality{
                                {
-                                       Endpoints: []xdsresource.Endpoint{{Addresses: []string{fmt.Sprintf("%s:%d", edsHost1, edsPort1)}, Weight: 1}},
+                                       Endpoints: []xdsresource.Endpoint{{
+                                               ResolverEndpoint: resolver.Endpoint{
+                                                       Addresses: []resolver.Address{{Addr: fmt.Sprintf("%s:%d", edsHost1, edsPort1)}},
+                                               },
+                                               Weight: 1,
+                                       }},
                                        ID: clients.Locality{
                                                Region:  "region-1",
                                                Zone:    "zone-1",
index 436235bfdbfd94ca3659aff27ca3e2ca4f586cec..aedf117be0e4d6842c1c2fbf3fafe2832587ed60 100644 (file)
@@ -29,6 +29,7 @@ import (
        "google.golang.org/grpc/internal/xds/clients"
        "google.golang.org/grpc/internal/xds/xdsclient"
        "google.golang.org/grpc/internal/xds/xdsclient/xdsresource"
+       "google.golang.org/grpc/resolver"
 
        v3clusterpb "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
        v3endpointpb "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
@@ -291,8 +292,13 @@ func (s) TestFederation_EndpointsResourceContextParamOrder(t *testing.T) {
                update: xdsresource.EndpointsUpdate{
                        Localities: []xdsresource.Locality{
                                {
-                                       Endpoints: []xdsresource.Endpoint{{Addresses: []string{"localhost:666"}, Weight: 1}},
-                                       Weight:    1,
+                                       Endpoints: []xdsresource.Endpoint{{
+                                               ResolverEndpoint: resolver.Endpoint{
+                                                       Addresses: []resolver.Address{{Addr: "localhost:666"}},
+                                               },
+                                               Weight: 1,
+                                       }},
+                                       Weight: 1,
                                        ID: clients.Locality{
                                                Region:  "region-1",
                                                Zone:    "zone-1",
index 2a7f146f983d2425ae809f626ed1acd6110dc046..87d5653fa00636896f059eda74e10b66659513e3 100644 (file)
@@ -36,6 +36,7 @@ import (
        "google.golang.org/grpc/internal/xds/clients"
        "google.golang.org/grpc/internal/xds/xdsclient"
        "google.golang.org/grpc/internal/xds/xdsclient/xdsresource"
+       "google.golang.org/grpc/resolver"
        "google.golang.org/protobuf/proto"
        "google.golang.org/protobuf/testing/protocmp"
        "google.golang.org/protobuf/types/known/anypb"
@@ -1089,16 +1090,26 @@ func (s) TestHandleEndpointsResponseFromManagementServer(t *testing.T) {
                        wantUpdate: xdsresource.EndpointsUpdate{
                                Localities: []xdsresource.Locality{
                                        {
-                                               Endpoints: []xdsresource.Endpoint{{Addresses: []string{"addr1:314"}, Weight: 1}},
-                                               ID:        clients.Locality{SubZone: "locality-1"},
-                                               Priority:  1,
-                                               Weight:    1,
+                                               Endpoints: []xdsresource.Endpoint{{
+                                                       ResolverEndpoint: resolver.Endpoint{
+                                                               Addresses: []resolver.Address{{Addr: "addr1:314"}},
+                                                       },
+                                                       Weight: 1,
+                                               }},
+                                               ID:       clients.Locality{SubZone: "locality-1"},
+                                               Priority: 1,
+                                               Weight:   1,
                                        },
                                        {
-                                               Endpoints: []xdsresource.Endpoint{{Addresses: []string{"addr2:159"}, Weight: 1}},
-                                               ID:        clients.Locality{SubZone: "locality-2"},
-                                               Priority:  0,
-                                               Weight:    1,
+                                               Endpoints: []xdsresource.Endpoint{{
+                                                       ResolverEndpoint: resolver.Endpoint{
+                                                               Addresses: []resolver.Address{{Addr: "addr2:159"}},
+                                                       },
+                                                       Weight: 1,
+                                               }},
+                                               ID:       clients.Locality{SubZone: "locality-2"},
+                                               Priority: 0,
+                                               Weight:   1,
                                        },
                                },
                        },
@@ -1123,16 +1134,26 @@ func (s) TestHandleEndpointsResponseFromManagementServer(t *testing.T) {
                        wantUpdate: xdsresource.EndpointsUpdate{
                                Localities: []xdsresource.Locality{
                                        {
-                                               Endpoints: []xdsresource.Endpoint{{Addresses: []string{"addr1:314"}, Weight: 1}},
-                                               ID:        clients.Locality{SubZone: "locality-1"},
-                                               Priority:  1,
-                                               Weight:    1,
+                                               Endpoints: []xdsresource.Endpoint{{
+                                                       ResolverEndpoint: resolver.Endpoint{
+                                                               Addresses: []resolver.Address{{Addr: "addr1:314"}},
+                                                       },
+                                                       Weight: 1,
+                                               }},
+                                               ID:       clients.Locality{SubZone: "locality-1"},
+                                               Priority: 1,
+                                               Weight:   1,
                                        },
                                        {
-                                               Endpoints: []xdsresource.Endpoint{{Addresses: []string{"addr2:159"}, Weight: 1}},
-                                               ID:        clients.Locality{SubZone: "locality-2"},
-                                               Priority:  0,
-                                               Weight:    1,
+                                               Endpoints: []xdsresource.Endpoint{{
+                                                       ResolverEndpoint: resolver.Endpoint{
+                                                               Addresses: []resolver.Address{{Addr: "addr2:159"}},
+                                                       },
+                                                       Weight: 1,
+                                               }},
+                                               ID:       clients.Locality{SubZone: "locality-2"},
+                                               Priority: 0,
+                                               Weight:   1,
                                        },
                                },
                        },
index 39b2ba74ddcb5adcfb78129d5ba41c1e371519fa..c6dc0c096c1996cdd5496d28d2697578b5fdf967 100644 (file)
@@ -19,6 +19,7 @@ package xdsresource
 
 import (
        "google.golang.org/grpc/internal/xds/clients"
+       "google.golang.org/grpc/resolver"
        "google.golang.org/protobuf/types/known/anypb"
 )
 
@@ -48,13 +49,13 @@ const (
 )
 
 // Endpoint contains information of an endpoint.
+// TODO(i/8757) : Replace Endpoint with resolver.Endpoint struct.
 type Endpoint struct {
-       Addresses    []string
-       HealthStatus EndpointHealthStatus
-       Weight       uint32
-       HashKey      string
-       Metadata     map[string]any
-       Hostname     string
+       ResolverEndpoint resolver.Endpoint
+       HealthStatus     EndpointHealthStatus
+       Weight           uint32
+       HashKey          string
+       Metadata         map[string]any
 }
 
 // Locality contains information of a locality.
index ebf47961c45d0a68ffa0adb5f15b37b7694e22ae..4ec133249bbec00c5482d45b47fe5321a2df878f 100644 (file)
@@ -30,10 +30,34 @@ import (
        "google.golang.org/grpc/internal/pretty"
        xdsinternal "google.golang.org/grpc/internal/xds"
        "google.golang.org/grpc/internal/xds/clients"
+       "google.golang.org/grpc/resolver"
        "google.golang.org/protobuf/proto"
        "google.golang.org/protobuf/types/known/anypb"
 )
 
+// hostnameKeyType is the key to store the hostname attribute in
+// a resolver.Endpoint.
+type hostnameKeyType struct{}
+
+// setHostname returns a copy of the given endpoint with hostname added
+// as an attribute.
+func setHostname(endpoint resolver.Endpoint, hostname string) resolver.Endpoint {
+       // Only set if non-empty; xds_cluster_impl uses this to trigger :authority
+       // rewriting.
+       if hostname == "" {
+               return endpoint
+       }
+       endpoint.Attributes = endpoint.Attributes.WithValue(hostnameKeyType{}, hostname)
+       return endpoint
+}
+
+// HostnameFromEndpoint returns the hostname attribute of endpoint. If this
+// attribute is not set, it returns the empty string.
+func HostnameFromEndpoint(endpoint resolver.Endpoint) string {
+       hostname, _ := endpoint.Attributes.Value(hostnameKeyType{}).(string)
+       return hostname
+}
+
 func unmarshalEndpointsResource(r *anypb.Any) (string, EndpointsUpdate, error) {
        r, err := UnwrapResource(r)
        if err != nil {
@@ -102,7 +126,9 @@ func parseEndpoints(lbEndpoints []*v3endpointpb.LbEndpoint, uniqueEndpointAddrs
                        }
                }
 
+               address := []resolver.Address{}
                for _, a := range addrs {
+                       address = append(address, resolver.Address{Addr: a})
                        if uniqueEndpointAddrs[a] {
                                return nil, fmt.Errorf("duplicate endpoint with the same address %s", a)
                        }
@@ -126,13 +152,14 @@ func parseEndpoints(lbEndpoints []*v3endpointpb.LbEndpoint, uniqueEndpointAddrs
                                hashKey = hashKeyFromMetadata(endpointMetadata)
                        }
                }
+               endpoint := resolver.Endpoint{Addresses: address}
+               endpoint = setHostname(endpoint, lbEndpoint.GetEndpoint().GetHostname())
                endpoints = append(endpoints, Endpoint{
-                       HealthStatus: EndpointHealthStatus(lbEndpoint.GetHealthStatus()),
-                       Addresses:    addrs,
-                       Weight:       weight,
-                       HashKey:      hashKey,
-                       Metadata:     endpointMetadata,
-                       Hostname:     lbEndpoint.GetEndpoint().GetHostname(),
+                       ResolverEndpoint: endpoint,
+                       HealthStatus:     EndpointHealthStatus(lbEndpoint.GetHealthStatus()),
+                       Weight:           weight,
+                       HashKey:          hashKey,
+                       Metadata:         endpointMetadata,
                })
        }
        return endpoints, nil
index 905cf8a20f26702bc87b9b52b68f497ae9657bdb..2a8db8a7aa3396adfcf1ab950a2fce50dce2b025 100644 (file)
@@ -34,12 +34,23 @@ import (
        "google.golang.org/grpc/internal/testutils"
        "google.golang.org/grpc/internal/xds/clients"
        "google.golang.org/grpc/internal/xds/xdsclient/xdsresource/version"
+       "google.golang.org/grpc/resolver"
        "google.golang.org/protobuf/proto"
        "google.golang.org/protobuf/types/known/anypb"
        "google.golang.org/protobuf/types/known/structpb"
        "google.golang.org/protobuf/types/known/wrapperspb"
 )
 
+func buildResolverEndpoint(addr []string, hostname string) resolver.Endpoint {
+       address := []resolver.Address{}
+       for _, a := range addr {
+               address = append(address, resolver.Address{Addr: a})
+       }
+       resolverEndpoint := resolver.Endpoint{Addresses: address}
+       resolverEndpoint = setHostname(resolverEndpoint, hostname)
+       return resolverEndpoint
+}
+
 func (s) TestEDSParseRespProto(t *testing.T) {
        tests := []struct {
                name    string
@@ -94,14 +105,10 @@ func (s) TestEDSParseRespProto(t *testing.T) {
                        m: func() *v3endpointpb.ClusterLoadAssignment {
                                clab0 := newClaBuilder("test", nil)
                                endpoints1 := []endpointOpts{{addrWithPort: "addr1:314"}}
-                               locOption1 := &addLocalityOptions{
-                                       Health: []v3corepb.HealthStatus{v3corepb.HealthStatus_HEALTHY},
-                               }
+                               locOption1 := &addLocalityOptions{Health: []v3corepb.HealthStatus{v3corepb.HealthStatus_HEALTHY}}
                                clab0.addLocality("locality-1", 0, 1, endpoints1, locOption1)
                                endpoints2 := []endpointOpts{{addrWithPort: "addr2:159"}}
-                               locOption2 := &addLocalityOptions{
-                                       Health: []v3corepb.HealthStatus{v3corepb.HealthStatus_HEALTHY},
-                               }
+                               locOption2 := &addLocalityOptions{Health: []v3corepb.HealthStatus{v3corepb.HealthStatus_HEALTHY}}
                                clab0.addLocality("locality-2", 0, 0, endpoints2, locOption2)
                                return clab0.Build()
                        }(),
@@ -153,10 +160,9 @@ func (s) TestEDSParseRespProto(t *testing.T) {
                                Localities: []Locality{
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr1:314"},
-                                                       HealthStatus: EndpointHealthStatusUnhealthy,
-                                                       Weight:       271,
-                                                       Hostname:     "addr1",
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr1:314"}, "addr1"),
+                                                       HealthStatus:     EndpointHealthStatusUnhealthy,
+                                                       Weight:           271,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-1"},
                                                Priority: 1,
@@ -164,10 +170,9 @@ func (s) TestEDSParseRespProto(t *testing.T) {
                                        },
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr2:159"},
-                                                       HealthStatus: EndpointHealthStatusDraining,
-                                                       Weight:       828,
-                                                       Hostname:     "addr2",
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr2:159"}, "addr2"),
+                                                       HealthStatus:     EndpointHealthStatusDraining,
+                                                       Weight:           828,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-2"},
                                                Priority: 0,
@@ -201,10 +206,9 @@ func (s) TestEDSParseRespProto(t *testing.T) {
                                Localities: []Locality{
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr1:314"},
-                                                       HealthStatus: EndpointHealthStatusUnhealthy,
-                                                       Weight:       271,
-                                                       Hostname:     "addr1",
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr1:314"}, "addr1"),
+                                                       HealthStatus:     EndpointHealthStatusUnhealthy,
+                                                       Weight:           271,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-1"},
                                                Priority: 1,
@@ -212,10 +216,9 @@ func (s) TestEDSParseRespProto(t *testing.T) {
                                        },
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr2:159"},
-                                                       HealthStatus: EndpointHealthStatusDraining,
-                                                       Weight:       828,
-                                                       Hostname:     "addr2",
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr2:159"}, "addr2"),
+                                                       HealthStatus:     EndpointHealthStatusDraining,
+                                                       Weight:           828,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-1"},
                                                Priority: 0,
@@ -298,13 +301,13 @@ func (s) TestEDSParseRespProtoAdditionalAddrs(t *testing.T) {
                        name: "multiple localities",
                        m: func() *v3endpointpb.ClusterLoadAssignment {
                                clab0 := newClaBuilder("test", nil)
-                               endpoints1 := []endpointOpts{{addrWithPort: "addr1:997", additionalAddrWithPorts: []string{"addr1:1000"}}}
+                               endpoints1 := []endpointOpts{{addrWithPort: "addr1:997", additionalAddrWithPorts: []string{"addr1:1000"}, hostname: "addr1"}}
                                locOption1 := &addLocalityOptions{
                                        Health: []v3corepb.HealthStatus{v3corepb.HealthStatus_UNHEALTHY},
                                        Weight: []uint32{271},
                                }
                                clab0.addLocality("locality-1", 1, 1, endpoints1, locOption1)
-                               endpoints2 := []endpointOpts{{addrWithPort: "addr2:998", additionalAddrWithPorts: []string{"addr2:1000"}}}
+                               endpoints2 := []endpointOpts{{addrWithPort: "addr2:998", additionalAddrWithPorts: []string{"addr2:1000"}, hostname: "addr2"}}
                                locOption2 := &addLocalityOptions{
                                        Health: []v3corepb.HealthStatus{v3corepb.HealthStatus_HEALTHY},
                                        Weight: []uint32{828},
@@ -317,9 +320,9 @@ func (s) TestEDSParseRespProtoAdditionalAddrs(t *testing.T) {
                                Localities: []Locality{
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr1:997", "addr1:1000"},
-                                                       HealthStatus: EndpointHealthStatusUnhealthy,
-                                                       Weight:       271,
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr1:997", "addr1:1000"}, "addr1"),
+                                                       HealthStatus:     EndpointHealthStatusUnhealthy,
+                                                       Weight:           271,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-1"},
                                                Priority: 1,
@@ -327,9 +330,9 @@ func (s) TestEDSParseRespProtoAdditionalAddrs(t *testing.T) {
                                        },
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr2:998", "addr2:1000"},
-                                                       HealthStatus: EndpointHealthStatusHealthy,
-                                                       Weight:       828,
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr2:998", "addr2:1000"}, "addr2"),
+                                                       HealthStatus:     EndpointHealthStatusHealthy,
+                                                       Weight:           828,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-2"},
                                                Priority: 0,
@@ -541,10 +544,9 @@ func (s) TestUnmarshalEndpoints(t *testing.T) {
                                Localities: []Locality{
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr1:314"},
-                                                       HealthStatus: EndpointHealthStatusUnhealthy,
-                                                       Weight:       271,
-                                                       Hostname:     "addr1",
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr1:314"}, "addr1"),
+                                                       HealthStatus:     EndpointHealthStatusUnhealthy,
+                                                       Weight:           271,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-1"},
                                                Priority: 1,
@@ -552,10 +554,9 @@ func (s) TestUnmarshalEndpoints(t *testing.T) {
                                        },
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr2:159"},
-                                                       HealthStatus: EndpointHealthStatusDraining,
-                                                       Weight:       828,
-                                                       Hostname:     "addr2",
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr2:159"}, "addr2"),
+                                                       HealthStatus:     EndpointHealthStatusDraining,
+                                                       Weight:           828,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-2"},
                                                Priority: 0,
@@ -574,10 +575,9 @@ func (s) TestUnmarshalEndpoints(t *testing.T) {
                                Localities: []Locality{
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr1:314"},
-                                                       HealthStatus: EndpointHealthStatusUnhealthy,
-                                                       Weight:       271,
-                                                       Hostname:     "addr1",
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr1:314"}, "addr1"),
+                                                       HealthStatus:     EndpointHealthStatusUnhealthy,
+                                                       Weight:           271,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-1"},
                                                Priority: 1,
@@ -585,10 +585,9 @@ func (s) TestUnmarshalEndpoints(t *testing.T) {
                                        },
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr2:159"},
-                                                       HealthStatus: EndpointHealthStatusDraining,
-                                                       Weight:       828,
-                                                       Hostname:     "addr2",
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr2:159"}, "addr2"),
+                                                       HealthStatus:     EndpointHealthStatusDraining,
+                                                       Weight:           828,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-2"},
                                                Priority: 0,
@@ -643,6 +642,7 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOn(t *testing.T
                                                        }),
                                                },
                                        },
+                                       hostname: "addr1",
                                }}
                                clab0.addLocality("locality-1", 1, 0, endpoints, nil)
                                return clab0.Build()
@@ -651,9 +651,9 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOn(t *testing.T
                                Localities: []Locality{
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr1:314"},
-                                                       HealthStatus: EndpointHealthStatusUnknown,
-                                                       Weight:       1,
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr1:314"}, "addr1"),
+                                                       HealthStatus:     EndpointHealthStatusUnknown,
+                                                       Weight:           1,
                                                        Metadata: map[string]any{
                                                                "test-key": ProxyAddressMetadataValue{
                                                                        Address: "1.2.3.4:1111",
@@ -684,6 +684,7 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOn(t *testing.T
                                                        },
                                                },
                                        },
+                                       hostname: "addr1",
                                }}
                                clab0.addLocality("locality-1", 1, 0, endpoints, nil)
                                return clab0.Build()
@@ -692,9 +693,9 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOn(t *testing.T
                                Localities: []Locality{
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr1:314"},
-                                                       HealthStatus: EndpointHealthStatusUnknown,
-                                                       Weight:       1,
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr1:314"}, "addr1"),
+                                                       HealthStatus:     EndpointHealthStatusUnknown,
+                                                       Weight:           1,
                                                        Metadata: map[string]any{
                                                                "test-key": StructMetadataValue{Data: map[string]any{
                                                                        "key": float64(123),
@@ -712,7 +713,7 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOn(t *testing.T
                        name: "typed_filter_metadata_in_locality",
                        endpointProto: func() *v3endpointpb.ClusterLoadAssignment {
                                clab0 := newClaBuilder("test", nil)
-                               endpoints := []endpointOpts{{addrWithPort: "addr1:314"}}
+                               endpoints := []endpointOpts{{addrWithPort: "addr1:314", hostname: "addr1"}}
                                locOption := &addLocalityOptions{
                                        Metadata: &v3corepb.Metadata{
                                                TypedFilterMetadata: map[string]*anypb.Any{
@@ -735,9 +736,9 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOn(t *testing.T
                                Localities: []Locality{
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr1:314"},
-                                                       HealthStatus: EndpointHealthStatusUnknown,
-                                                       Weight:       1,
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr1:314"}, "addr1"),
+                                                       HealthStatus:     EndpointHealthStatusUnknown,
+                                                       Weight:           1,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-1"},
                                                Priority: 0,
@@ -755,7 +756,7 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOn(t *testing.T
                        name: "filter_metadata_in_locality",
                        endpointProto: func() *v3endpointpb.ClusterLoadAssignment {
                                clab0 := newClaBuilder("test", nil)
-                               endpoints := []endpointOpts{{addrWithPort: "addr1:314"}}
+                               endpoints := []endpointOpts{{addrWithPort: "addr1:314", hostname: "addr1"}}
                                locOption := &addLocalityOptions{
                                        Metadata: &v3corepb.Metadata{
                                                FilterMetadata: map[string]*structpb.Struct{
@@ -776,9 +777,9 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOn(t *testing.T
                                Localities: []Locality{
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr1:314"},
-                                                       HealthStatus: EndpointHealthStatusUnknown,
-                                                       Weight:       1,
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr1:314"}, "addr1"),
+                                                       HealthStatus:     EndpointHealthStatusUnknown,
+                                                       Weight:           1,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-1"},
                                                Priority: 0,
@@ -820,6 +821,7 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOn(t *testing.T
                                                        },
                                                },
                                        },
+                                       hostname: "addr1",
                                }}
                                clab0.addLocality("locality-1", 1, 0, endpoints, nil)
                                return clab0.Build()
@@ -828,9 +830,9 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOn(t *testing.T
                                Localities: []Locality{
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr1:314"},
-                                                       HealthStatus: EndpointHealthStatusUnknown,
-                                                       Weight:       1,
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr1:314"}, "addr1"),
+                                                       HealthStatus:     EndpointHealthStatusUnknown,
+                                                       Weight:           1,
                                                        Metadata: map[string]any{
                                                                "test-key": ProxyAddressMetadataValue{
                                                                        Address: "1.2.3.4:1111",
@@ -848,7 +850,7 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOn(t *testing.T
                        name: "typed_filter_metadata_over_filter_metadata_in_locality",
                        endpointProto: func() *v3endpointpb.ClusterLoadAssignment {
                                clab0 := newClaBuilder("test", nil)
-                               endpoints := []endpointOpts{{addrWithPort: "addr1:314"}}
+                               endpoints := []endpointOpts{{addrWithPort: "addr1:314", hostname: "addr1"}}
                                locOption := &addLocalityOptions{
                                        Metadata: &v3corepb.Metadata{
                                                TypedFilterMetadata: map[string]*anypb.Any{
@@ -880,9 +882,9 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOn(t *testing.T
                                Localities: []Locality{
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr1:314"},
-                                                       HealthStatus: EndpointHealthStatusUnknown,
-                                                       Weight:       1,
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr1:314"}, "addr1"),
+                                                       HealthStatus:     EndpointHealthStatusUnknown,
+                                                       Weight:           1,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-1"},
                                                Priority: 0,
@@ -924,6 +926,7 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOn(t *testing.T
                                                        },
                                                },
                                        },
+                                       hostname: "addr1",
                                }}
                                clab0.addLocality("locality-1", 1, 0, endpoints, nil)
                                return clab0.Build()
@@ -932,9 +935,9 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOn(t *testing.T
                                Localities: []Locality{
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr1:314"},
-                                                       HealthStatus: EndpointHealthStatusUnknown,
-                                                       Weight:       1,
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr1:314"}, "addr1"),
+                                                       HealthStatus:     EndpointHealthStatusUnknown,
+                                                       Weight:           1,
                                                        Metadata: map[string]any{
                                                                "test-key": ProxyAddressMetadataValue{
                                                                        Address: "1.2.3.4:1111",
@@ -955,7 +958,7 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOn(t *testing.T
                        name: "both_filter_and_typed_filter_metadata_in_locality",
                        endpointProto: func() *v3endpointpb.ClusterLoadAssignment {
                                clab0 := newClaBuilder("test", nil)
-                               endpoints := []endpointOpts{{addrWithPort: "addr1:314"}}
+                               endpoints := []endpointOpts{{addrWithPort: "addr1:314", hostname: "addr1"}}
                                locOption := &addLocalityOptions{
                                        Metadata: &v3corepb.Metadata{
                                                TypedFilterMetadata: map[string]*anypb.Any{
@@ -987,9 +990,9 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOn(t *testing.T
                                Localities: []Locality{
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr1:314"},
-                                                       HealthStatus: EndpointHealthStatusUnknown,
-                                                       Weight:       1,
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr1:314"}, "addr1"),
+                                                       HealthStatus:     EndpointHealthStatusUnknown,
+                                                       Weight:           1,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-1"},
                                                Priority: 0,
@@ -1048,6 +1051,7 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOff(t *testing.
                                                        }),
                                                },
                                        },
+                                       hostname: "addr1",
                                }}
                                clab0.addLocality("locality-1", 1, 0, endpoints, nil)
                                return clab0.Build()
@@ -1056,9 +1060,9 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOff(t *testing.
                                Localities: []Locality{
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr1:314"},
-                                                       HealthStatus: EndpointHealthStatusUnknown,
-                                                       Weight:       1,
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr1:314"}, "addr1"),
+                                                       HealthStatus:     EndpointHealthStatusUnknown,
+                                                       Weight:           1,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-1"},
                                                Priority: 0,
@@ -1084,6 +1088,7 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOff(t *testing.
                                                        },
                                                },
                                        },
+                                       hostname: "addr1",
                                }}
                                clab0.addLocality("locality-1", 1, 0, endpoints, nil)
                                return clab0.Build()
@@ -1092,9 +1097,9 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOff(t *testing.
                                Localities: []Locality{
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr1:314"},
-                                                       HealthStatus: EndpointHealthStatusUnknown,
-                                                       Weight:       1,
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr1:314"}, "addr1"),
+                                                       HealthStatus:     EndpointHealthStatusUnknown,
+                                                       Weight:           1,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-1"},
                                                Priority: 0,
@@ -1107,7 +1112,7 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOff(t *testing.
                        name: "typed_filter_metadata_in_locality",
                        endpointProto: func() *v3endpointpb.ClusterLoadAssignment {
                                clab0 := newClaBuilder("test", nil)
-                               endpoints := []endpointOpts{{addrWithPort: "addr1:314"}}
+                               endpoints := []endpointOpts{{addrWithPort: "addr1:314", hostname: "addr1"}}
                                locOption := &addLocalityOptions{
                                        Metadata: &v3corepb.Metadata{
                                                TypedFilterMetadata: map[string]*anypb.Any{
@@ -1130,9 +1135,9 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOff(t *testing.
                                Localities: []Locality{
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr1:314"},
-                                                       HealthStatus: EndpointHealthStatusUnknown,
-                                                       Weight:       1,
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr1:314"}, "addr1"),
+                                                       HealthStatus:     EndpointHealthStatusUnknown,
+                                                       Weight:           1,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-1"},
                                                Priority: 0,
@@ -1145,7 +1150,7 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOff(t *testing.
                        name: "filter_metadata_in_locality",
                        endpointProto: func() *v3endpointpb.ClusterLoadAssignment {
                                clab0 := newClaBuilder("test", nil)
-                               endpoints := []endpointOpts{{addrWithPort: "addr1:314"}}
+                               endpoints := []endpointOpts{{addrWithPort: "addr1:314", hostname: "addr1"}}
                                locOption := &addLocalityOptions{
                                        Metadata: &v3corepb.Metadata{
                                                FilterMetadata: map[string]*structpb.Struct{
@@ -1166,9 +1171,9 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOff(t *testing.
                                Localities: []Locality{
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr1:314"},
-                                                       HealthStatus: EndpointHealthStatusUnknown,
-                                                       Weight:       1,
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr1:314"}, "addr1"),
+                                                       HealthStatus:     EndpointHealthStatusUnknown,
+                                                       Weight:           1,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-1"},
                                                Priority: 0,
@@ -1205,6 +1210,7 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOff(t *testing.
                                                        },
                                                },
                                        },
+                                       hostname: "addr1",
                                }}
                                clab0.addLocality("locality-1", 1, 0, endpoints, nil)
                                return clab0.Build()
@@ -1213,9 +1219,9 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOff(t *testing.
                                Localities: []Locality{
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr1:314"},
-                                                       HealthStatus: EndpointHealthStatusUnknown,
-                                                       Weight:       1,
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr1:314"}, "addr1"),
+                                                       HealthStatus:     EndpointHealthStatusUnknown,
+                                                       Weight:           1,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-1"},
                                                Priority: 0,
@@ -1228,7 +1234,7 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOff(t *testing.
                        name: "both_filter_and_typed_filter_metadata_in_locality",
                        endpointProto: func() *v3endpointpb.ClusterLoadAssignment {
                                clab0 := newClaBuilder("test", nil)
-                               endpoints := []endpointOpts{{addrWithPort: "addr1:314"}}
+                               endpoints := []endpointOpts{{addrWithPort: "addr1:314", hostname: "addr1"}}
                                locOption := &addLocalityOptions{
                                        Metadata: &v3corepb.Metadata{
                                                TypedFilterMetadata: map[string]*anypb.Any{
@@ -1260,9 +1266,9 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOff(t *testing.
                                Localities: []Locality{
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr1:314"},
-                                                       HealthStatus: EndpointHealthStatusUnknown,
-                                                       Weight:       1,
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr1:314"}, "addr1"),
+                                                       HealthStatus:     EndpointHealthStatusUnknown,
+                                                       Weight:           1,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-1"},
                                                Priority: 0,
@@ -1288,6 +1294,7 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOff(t *testing.
                                                        }),
                                                },
                                        },
+                                       hostname: "addr1",
                                }}
                                locOption := &addLocalityOptions{
                                        Metadata: &v3corepb.Metadata{
@@ -1309,9 +1316,9 @@ func (s) TestEDSParseRespProto_HTTP_Connect_CustomMetadata_EnvVarOff(t *testing.
                                Localities: []Locality{
                                        {
                                                Endpoints: []Endpoint{{
-                                                       Addresses:    []string{"addr1:314"},
-                                                       HealthStatus: EndpointHealthStatusUnknown,
-                                                       Weight:       1,
+                                                       ResolverEndpoint: buildResolverEndpoint([]string{"addr1:314"}, "addr1"),
+                                                       HealthStatus:     EndpointHealthStatusUnknown,
+                                                       Weight:           1,
                                                }},
                                                ID:       clients.Locality{SubZone: "locality-1"},
                                                Priority: 0,
index 8e6af9514b6d351b79470efcf46de41cb79bdba8..598ed21a29cfd13e509faed80b53a44463da61b9 100644 (file)
@@ -182,6 +182,7 @@ type BuildOptions struct {
 
 // An Endpoint is one network endpoint, or server, which may have multiple
 // addresses with which it can be accessed.
+// TODO(i/8773) : make resolver.Endpoint and resolver.Address immutable
 type Endpoint struct {
        // Addresses contains a list of addresses used to access this endpoint.
        Addresses []Address