Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xds: generate routes directly from API gateway snapshot #17392

Merged
merged 17 commits into from
May 25, 2023

Conversation

sarahalsmiller
Copy link
Member

@sarahalsmiller sarahalsmiller commented May 17, 2023

Description

In order to move the gateway off of using an underlying ingress gateway, add functionality to generate API Gateway natively. Previously this code was all in a single branch, but for ease of tracking and reviewing, breaking this code into 4 separate PRs.

NOTE- this code relies on a helper function introduced in this PR #17390 and tests will not pass until that code is merged.

Testing & Reproduction steps

  • No user facing changes are present, current CI/CD process passing ensures no behavior changes.

Links

PR Checklist

  • updated test coverage
  • external facing docs updated
  • appropriate backport labels added
  • not a security concern

@sarahalsmiller sarahalsmiller requested review from nathancoleman and a team May 17, 2023 17:29
@sarahalsmiller sarahalsmiller changed the base branch from main to NET-3673-endpointsFromSnapshotAPIGateway May 17, 2023 17:30
@github-actions github-actions bot added the theme/envoy/xds Related to Envoy support label May 17, 2023
@sarahalsmiller sarahalsmiller added pr/no-changelog PR does not need a corresponding .changelog entry backport/1.15 This release series is no longer active on CE. Use backport/ent/1.15. labels May 17, 2023
@sarahalsmiller sarahalsmiller added pr/no-backport and removed backport/1.15 This release series is no longer active on CE. Use backport/ent/1.15. labels May 18, 2023
@nathancoleman nathancoleman changed the title xds generation for routes api gateway xds: generate routes directly from API gateway snapshot May 18, 2023
Comment on lines -39 to +40
// TODO Find a cleaner solution, can't currently pass unexported property types
var err error
cfgSnap.IngressGateway, err = cfgSnap.APIGateway.ToIngress(cfgSnap.Datacenter)
if err != nil {
return nil, err
}
return s.routesForIngressGateway(cfgSnap)
return s.routesForAPIGateway(cfgSnap)
Copy link
Member

Choose a reason for hiding this comment

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

This is the crux of the whole change that we're making: instead of converting to an ingress gateway snapshot and generating xDS resources from that, we generate xDS resources directly from our API gateway snapshot 🎉

Copy link
Contributor

@andrewstucki andrewstucki left a comment

Choose a reason for hiding this comment

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

Some questions/changes here.

agent/consul/discoverychain/gateway.go Outdated Show resolved Hide resolved
}

// FlattenHTTPRoute takes in a route and its parent config entries and returns a list of flattened routes
func FlattenHTTPRoute(route *structs.HTTPRouteConfigEntry, listener *structs.APIGatewayListener, gateway *structs.APIGatewayConfigEntry) []structs.HTTPRouteConfigEntry {
Copy link
Contributor

Choose a reason for hiding this comment

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

So, I'm slightly confused as to what this is being used for. the route consolidation/flatenning that was happening in the discoverychain compilation previously was to merge all compatible routes on a listener so that we can have some "uber routes" that combine disparate parts of multiple routes configuration. This was due to the way that we otherwise couldn't take into account things like two routes with the same hostname values that have different path routing rules. In order for our synthesized discoverychain primitives to generate proper xDS in that case, we pretty much had to have one "uber route" per-hostname.

Guess I'm confused because this looks like it's trying to take in a single route and generate multiple routes from it? Additionally why would we be trying to flatten/merge routes if all we have at this point is a single route we're operating on?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is a bit confusing, and this was something I wrote out by directly tracing what the ToIngress function was previously doing to the route. It could be set up wrong here, but we do get test failures if we don't run this function since we appear to be relying on some of the transformation that happens in the consolidateHTTPRoute function. Would it make more sense if matches persisted outside of this function?

Copy link
Contributor

Choose a reason for hiding this comment

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

Talked with @nathancoleman and @sarahalsmiller about how this function would probably make more sense if it was returning a lower-level construct closer to the xDS, but the logic of splitting matches per hostname seems to make sense - this feels like a reasonable candidate to consider refactoring later.

Copy link
Member

@nathancoleman nathancoleman May 22, 2023

Choose a reason for hiding this comment

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

The route consolidation logic uses a specific format for the route name here. The pre-existing logic for synthesizing discovery chains uses the list of consolidated routes, so the disco chains are indexed using this specific name format.

The code that we're discussing here needs to look up disco chains using the index built earlier. If it doesn't use the same name format that the route consolidation logic used in the indexing step, then we aren't able to find any disco chains and end up producing no xDS resources because of this.

We could potentially rework the discovery chain synthesizing code in the future to use a different naming strategy when indexing discovery chains, but that's outside the scope of this PR.

Copy link
Member

@nathancoleman nathancoleman May 22, 2023

Choose a reason for hiding this comment

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

I added a comment in the code explaining this - see 072aa45

Copy link
Contributor

Choose a reason for hiding this comment

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

that's fine if we end up doing this mostly in a refactor, but there are few things I think we should make sure of when doing this here, and probably additionally add comments about:

  1. we can only use the name/hostname of the route that is returned from this function here, any other used fields will be wrong due to the fact that we're not actually consolidating this route with any other routes
  2. I think even in this PR, given point 1 above, that we should likely just do something like make a function called something to the effect of "SynthesizedRouteNames" to do the CRC32 rename + hostname splitting for route iteration, because as it stands, the helper introduced as part of the discoverychain just isn't doing any of the route merging/flattening that its name indicates it's doing due to the fact that it's only taking in a single route.
  3. down the line, in a follow-up, it probably makes the most sense to just do something like set the compiled routes on another field in proxycfg at synthesize time -- something like SynthesizedRoutes so that we're not leaking abstractions even more than we currently are into the xDS code

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed flattenHTTPRoutes into a function called ReformatHTTPRoute and reverted the gateway discoverychain logic back to how it was before.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok I ended up needed to revert that because it caused the integration tests to blow up, but hopefully the changes I made to the naming/comment make whats happening clearer.

agent/xds/routes.go Show resolved Hide resolved
Base automatically changed from NET-3673-endpointsFromSnapshotAPIGateway to main May 19, 2023 18:51
agent/consul/discoverychain/gateway.go Outdated Show resolved Hide resolved
agent/consul/discoverychain/gateway.go Outdated Show resolved Hide resolved
}

// FlattenHTTPRoute takes in a route and its parent config entries and returns a list of flattened routes
func FlattenHTTPRoute(route *structs.HTTPRouteConfigEntry, listener *structs.APIGatewayListener, gateway *structs.APIGatewayConfigEntry) []structs.HTTPRouteConfigEntry {
Copy link
Contributor

Choose a reason for hiding this comment

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

Talked with @nathancoleman and @sarahalsmiller about how this function would probably make more sense if it was returning a lower-level construct closer to the xDS, but the logic of splitting matches per hostname seems to make sense - this feels like a reasonable candidate to consider refactoring later.

agent/xds/routes.go Outdated Show resolved Hide resolved
agent/xds/routes.go Outdated Show resolved Hide resolved
agent/xds/routes.go Outdated Show resolved Hide resolved
@sarahalsmiller sarahalsmiller merged commit 6d35edc into main May 25, 2023
@sarahalsmiller sarahalsmiller deleted the NET-3672-routesForAPIGateway branch May 25, 2023 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/no-backport pr/no-changelog PR does not need a corresponding .changelog entry theme/envoy/xds Related to Envoy support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants