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

connect: fix failover through a mesh gateway to a remote datacenter #6259

Merged
merged 11 commits into from
Aug 5, 2019

Conversation

rboyer
Copy link
Member

@rboyer rboyer commented Aug 1, 2019

(NOTE: This is a simpler variation of a solution to #6161 than was proposed in PR #6254)

Failover is pushed entirely down to the data plane by creating envoy
clusters and putting each successive destination in a different load
assignment priority band. For example this shows that normally requests
go to 1.2.3.4:8080 but when that fails they go to 6.7.8.9:8080:

- name: foo
  load_assignment:
    cluster_name: foo
    policy:
      overprovisioning_factor: 100000
    endpoints:
    - priority: 0
      lb_endpoints:
      - endpoint:
          address:
            socket_address:
              address: 1.2.3.4
              port_value: 8080
    - priority: 1
      lb_endpoints:
      - endpoint:
          address:
            socket_address:
              address: 6.7.8.9
              port_value: 8080

Mesh gateways route requests based solely on the SNI header tacked onto
the TLS layer. Envoy currently only lets you configure the outbound SNI
header at the cluster layer.

If you try to failover through a mesh gateway you ideally would
configure the SNI value per endpoint, but that's not possible in envoy
today.

This PR introduces a simpler way around the problem for now:

  1. We identify any target of failover that will use mesh gateway mode local or
    remote and then further isolate any resolver node in the compiled discovery
    chain that has a failover destination set to one of those targets.

  2. For each of these resolvers we will perform a small measurement of
    comparative healths of the endpoints that come back from the health API for the
    set of primary target and serial failover targets. We walk the list of targets
    in order and if any endpoint is healthy we return that target, otherwise we
    move on to the next target.

  3. The CDS and EDS endpoints both perform the measurements in (2) for the
    affected resolver nodes.

  4. For CDS this measurement selects which TLS SNI field to use for the cluster
    (note the cluster is always going to be named for the primary target)

  5. For EDS this measurement selects which set of endpoints will populate the
    cluster. Priority tiered failover is ignored.

One of the big downsides to this approach to failover is that the failover
detection and correction is going to be controlled by consul rather than
deferring that entirely to the data plane as with the prior version. This also
means that we are bound to only failover using official health signals and
cannot make use of data plane signals like outlier detection to affect
failover.

In this specific scenario the lack of data plane signals is ok because the
effectiveness is already muted by the fact that the ultimate destination
endpoints will have their data plane signals scrambled when they pass through
the mesh gateway wrapper anyway so we're not losing much.

Fixes #6161

@rboyer rboyer requested a review from a team August 1, 2019 13:51
@rboyer rboyer self-assigned this Aug 1, 2019
@rboyer rboyer added the theme/connect Anything related to Consul Connect, Service Mesh, Side Car Proxies label Aug 1, 2019
@rboyer rboyer added this to the 1.6.0-rc1 milestone Aug 1, 2019
Copy link
Member

@banks banks left a comment

Choose a reason for hiding this comment

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

This looks great. One big question about the config/flexibility but the code otherwise looks good to me.

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

return primary // if everything is broken just use the primary for now
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about making the healthy threshold configurable? That was what we talked about in the original domain model RFC (i.e. failover if some percentage of nodes is unhealthy).

It seems simple to built here, I think the big downside is that Envoy doesn't exactly support that model so if it does fix weighted clusters to be able to set separate SNI per leg or similar we won't be able to use it as it won't exactly provide "healthy threshold" semantics.

Given that no other proxies work exactly like Envoy in this sliding failover case, what do you think about introducing a healthy_threshold_percent now which is the percentage of services that must be healthy to keep traffic flowing to them and not failover. Then if we want to re-introduce more complex "sliding" mechanism for Envoy later we could be explicit and add it as a separate mutually exclusive option like sliding_failover_overprovision_factor.

I think that's OK UX esp. given that this mode is one we can always implement for any proxy as we are in control and most other proxies are more likely to be able to do something like this than they are to do something with same semantics as Envoy over provisioning/weighting?

If the answer is that we'd rather ship like this I think that's OK but I feel like "wait til every single instance is dead" although that's what prepared queries do is not really an ideal strategy in a modern Service Mesh. It basically only works with extremely low numbers of replicas and low request volume. Everything else is just a prolonged cascading failure until at last the remaining nodes are overwhelmed and fail health checks and traffic shifts but then the overwhelmed nodes catch up and get "healthy" and traffic flaps back etc...

Copy link
Member Author

Choose a reason for hiding this comment

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

Moving this to a new issue as it's purely additive: #6276

@rboyer rboyer force-pushed the compiled-discovery-chain-api branch from 7bddbec to 247756e Compare August 1, 2019 19:18
@rboyer rboyer force-pushed the simpler-failover-through-mesh-gateway branch from 7955d77 to cf62afd Compare August 1, 2019 19:19
@rboyer rboyer force-pushed the compiled-discovery-chain-api branch from 72a55eb to 534a9f5 Compare August 2, 2019 16:04
@rboyer rboyer changed the base branch from compiled-discovery-chain-api to release/1-6 August 2, 2019 20:37
@rboyer rboyer force-pushed the simpler-failover-through-mesh-gateway branch from cf62afd to 4d263ea Compare August 2, 2019 22:01
Failover is pushed entirely down to the data plane by creating envoy
clusters and putting each successive destination in a different load
assignment priority band. For example this shows that normally requests
go to 1.2.3.4:8080 but when that fails they go to 6.7.8.9:8080:

- name: foo
  load_assignment:
    cluster_name: foo
    policy:
      overprovisioning_factor: 100000
    endpoints:
    - priority: 0
      lb_endpoints:
      - endpoint:
          address:
            socket_address:
              address: 1.2.3.4
              port_value: 8080
    - priority: 1
      lb_endpoints:
      - endpoint:
          address:
            socket_address:
              address: 6.7.8.9
              port_value: 8080

Mesh gateways route requests based solely on the SNI header tacked onto
the TLS layer. Envoy currently only lets you configure the outbound SNI
header at the cluster layer.

If you try to failover through a mesh gateway you ideally would
configure the SNI value per endpoint, but that's not possible in envoy
today.

This PR introduces a simpler way around the problem for now:

1. We identify any target of failover that will use mesh gateway mode local or
   remote and then further isolate any resolver node in the compiled discovery
   chain that has a failover destination set to one of those targets.

2. For each of these resolvers we will perform a small measurement of
   comparative healths of the endpoints that come back from the health API for the
   set of primary target and serial failover targets. We walk the list of targets
   in order and if any endpoint is healthy we return that target, otherwise we
   move on to the next target.

3. The CDS and EDS endpoints both perform the measurements in (2) for the
   affected resolver nodes.

4. For CDS this measurement selects which TLS SNI field to use for the cluster
   (note the cluster is always going to be named for the primary target)

5. For EDS this measurement selects which set of endpoints will populate the
   cluster. Priority tiered failover is ignored.

One of the big downsides to this approach to failover is that the failover
detection and correction is going to be controlled by consul rather than
deferring that entirely to the data plane as with the prior version. This also
means that we are bound to only failover using official health signals and
cannot make use of data plane signals like outlier detection to affect
failover.

In this specific scenario the lack of data plane signals is ok because the
effectiveness is already muted by the fact that the ultimate destination
endpoints will have their data plane signals scrambled when they pass through
the mesh gateway wrapper anyway so we're not losing much.

Another related fix is that we now use the endpoint health from the
underlying service, not the health of the gateway (regardless of
failover mode).
@rboyer rboyer force-pushed the simpler-failover-through-mesh-gateway branch from 4d263ea to 08406fa Compare August 2, 2019 22:05
@@ -188,6 +189,11 @@ func TestDiscoveryChainRead(t *testing.T) {
Kind: structs.ServiceResolver,
Name: "web",
ConnectTimeout: 33 * time.Second,
Failover: map[string]structs.ServiceResolverFailover{
Copy link
Member Author

Choose a reason for hiding this comment

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

After the compiler patch above the gateway customization is now correctly ignored so this test wasn't testing one of the customizations. Adding a dc2 failover causes it to continue being customized by gateway mode.

Copy link
Member

@mkeeler mkeeler left a comment

Choose a reason for hiding this comment

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

This looks good to me. Just a few questions.

agent/consul/discoverychain/compile.go Outdated Show resolved Hide resolved
agent/xds/clusters_test.go Show resolved Hide resolved
agent/xds/endpoints_test.go Show resolved Hide resolved
agent/xds/listeners_test.go Show resolved Hide resolved
Copy link
Member

@mkeeler mkeeler left a comment

Choose a reason for hiding this comment

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

:shipit:

@rboyer rboyer merged commit 8e22d80 into release/1-6 Aug 5, 2019
@rboyer rboyer deleted the simpler-failover-through-mesh-gateway branch August 5, 2019 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/connect Anything related to Consul Connect, Service Mesh, Side Car Proxies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants