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
4 changes: 2 additions & 2 deletions agent/proxycfg/api_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func (h *handlerAPIGateway) handleRouteConfigUpdate(ctx context.Context, u Updat
},
}

listenerKey := APIGatewayListenerKey{Protocol: string(listener.Protocol), Port: listener.Port}
listenerKey := APIGatewayListenerKeyFromListener(listener)
upstreams[listenerKey] = append(upstreams[listenerKey], upstream)
}

Expand Down Expand Up @@ -371,7 +371,7 @@ func (h *handlerAPIGateway) handleRouteConfigUpdate(ctx context.Context, u Updat
},
}

listenerKey := APIGatewayListenerKey{Protocol: string(listener.Protocol), Port: listener.Port}
listenerKey := APIGatewayListenerKeyFromListener(listener)
upstreams[listenerKey] = append(upstreams[listenerKey], upstream)
}

Expand Down
4 changes: 4 additions & 0 deletions agent/proxycfg/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,10 @@ func (c *configSnapshotIngressGateway) isEmpty() bool {

type APIGatewayListenerKey = IngressListenerKey

func APIGatewayListenerKeyFromListener(l structs.APIGatewayListener) APIGatewayListenerKey {
Copy link
Member Author

@nathancoleman nathancoleman May 18, 2023

Choose a reason for hiding this comment

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

This change is just for ease of use, no functional impact

return APIGatewayListenerKey{Protocol: string(l.Protocol), Port: l.Port}
}

type IngressListenerKey struct {
Protocol string
Port int
Expand Down
42 changes: 23 additions & 19 deletions agent/xds/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,36 +530,40 @@ type readyUpstreams struct {
upstreams []structs.Upstream
}

// getReadyUpstreams returns a map containing the list of upstreams for each listener that is ready
func getReadyUpstreams(cfgSnap *proxycfg.ConfigSnapshot) map[string]readyUpstreams {

ready := map[string]readyUpstreams{}
for _, l := range cfgSnap.APIGateway.Listeners {
//need to account for the state of the Listener when building the upstreams list
// Only include upstreams for listeners that are ready
if !cfgSnap.APIGateway.GatewayConfig.ListenerIsReady(l.Name) {
continue
}

// For each route bound to the listener
boundListener := cfgSnap.APIGateway.BoundListeners[l.Name]
//get route ref
for _, routeRef := range boundListener.Routes {
//get upstreams
upstreamMap := cfgSnap.APIGateway.Upstreams[routeRef]
for _, upstreams := range upstreamMap {
Copy link
Member Author

Choose a reason for hiding this comment

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

The big change is removing this for loop - instead of picking the upstreams specific to the listener, we were looping through all upstreams for all listeners and adding them

for _, u := range upstreams {
r, ok := ready[l.Name]
if !ok {
r = readyUpstreams{
listenerKey: proxycfg.APIGatewayListenerKey{
Protocol: string(l.Protocol),
Port: l.Port,
},
listenerCfg: l,
boundListenerCfg: boundListener,
routeReference: routeRef,
}
// Get all upstreams for the route
routeUpstreams := cfgSnap.APIGateway.Upstreams[routeRef]

// Filter to upstreams that attach to this specific listener since
// a route can bind to + have upstreams for multiple listeners
listenerKey := proxycfg.APIGatewayListenerKeyFromListener(l)
routeUpstreamsForListener := routeUpstreams[listenerKey]

for _, upstream := range routeUpstreamsForListener {
// Insert or update readyUpstreams for the listener to include this upstream
r, ok := ready[l.Name]
if !ok {
r = readyUpstreams{
listenerKey: listenerKey,
listenerCfg: l,
boundListenerCfg: boundListener,
routeReference: routeRef,
}
r.upstreams = append(r.upstreams, u)
ready[l.Name] = r
}
r.upstreams = append(r.upstreams, upstream)
ready[l.Name] = r
}
}
}
Expand Down