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

Add command line flag to toggle required consistency on consul reads #811

Merged
merged 3 commits into from
May 6, 2022

Conversation

jeremycw
Copy link
Contributor

@jeremycw jeremycw commented Jan 8, 2021

It seems like there are some Consul query options that would be nice to expose to the user for configuration. Specifically I need default consistency mode for Consul reads (https://www.consul.io/api-docs/features/consistency) so I kind of just crammed a toggle for the RequireConsistent query param onto the command line.

This is probably not mergable as-is but I'd like to open this up for discussion since there are probably more query options that should be configurable by the user. For example if someone wants stale consistency mode it's still not possible but i figured I'd start getting input before writing too much code.

@scalp42

@evandam
Copy link

evandam commented Jan 27, 2021

Hey folks, we rolled this out and it works great for Fabio being able to continue handling requests during a Consul leader election with the following:

registry.consul.requireConsistent = false
registry.consul.allowStale = true

What do we need to do get this merged?

@ketzacoatl
Copy link

@nathanejohnson / @leprechau / @pschultz, is it expected behavior for fabio to go dark during a consul leader election? It seems protecting against that would be very useful.

@scalp42
Copy link

scalp42 commented Feb 3, 2021

I can confirm, fork works perfectly. Fabio won't drop routes when there's a leadership election as expected with the stale reads.

@pschultz
Copy link
Member

pschultz commented Feb 3, 2021

My expectation is for fabio to fail static by default, i.e. routes should not change if Consul goes away.

@jeremycw jeremycw force-pushed the require-consistent-flag branch from 8e03437 to 734367e Compare February 3, 2021 21:48
@scalp42
Copy link

scalp42 commented Feb 5, 2021

@pschultz unfortunately, that's not the behavior we're seeing. 500s start being returned from local Consul when leadership election happens.

@ketzacoatl
Copy link

@pschultz unfortunately, that's not the behavior we're seeing. 500s start being returned from local Consul when leadership election happens.

@scalp42 do you also see change in fabio's routes as a result of the 500 from consul?

@evandam
Copy link

evandam commented Feb 6, 2021

Hi @ketzacoatl

I can confirm that Fabio does drop routes during a new Consul leader election. This isn't the case when enabling allowStale in this PR.

Here are logs hitting a service in Fabio every second while restarting Consul on the leader in a cluster of 3 servers: https://gist.github.com/evandam/b8f27c76bebf58634f6c5d412f61c0bc

You can see the 500 errors from Consul, followed by removing the route from Fabio, and 404s until a new leader is elected (18 seconds of downtime in this example).

If this isn't expected, is this new behavior introduced in a recent release?

@ketzacoatl
Copy link

@evandam thank you for taking the time to run that isolated test and extracting the logs for this PR! That's a great way to confirm the behavior.

@scalp42 / @pschultz, how should we proceed? Is there a regression to investigate that makes this feature/option not matter, or is this the proper way to handle the upstream outage with consul? I believe it's the latter, but maybe there's a reason for the former?

@scalp42
Copy link

scalp42 commented Feb 8, 2021

@ketzacoatl I can confirm all the routes get removed in Fabio logs.

@evandam
Copy link

evandam commented Feb 8, 2021

For what it's worth, I did the same tests on previous versions of Fabio back to 1.5.9 (May 2018) and see the same, so this doesn't seem to be new behavior unless it goes back farther than that.

@pschultz
Copy link
Member

pschultz commented Feb 9, 2021

Is there a regression to investigate that makes this feature/option not matter, or is this the proper way to handle the upstream outage with consul? I believe it's the latter.

I agree. I suggest to do what @evandam proposed and let the defaults be

registry.consul.requireConsistent = false
registry.consul.allowStale = true

This is a big enough change to warrant a minor version bump, I think.

@evandam
Copy link

evandam commented Feb 10, 2021

@pschultz I think there may need to be some extra validation added to the config. requireConsistent and allowStale can both be set to true, but requests to Consul will fail since it's not valid.

fabio[21514]: 2021/02/10 23:09:11 [WARN] consul: Error fetching health state. Unexpected response code: 400 (Cannot specify ?stale with ?consistent, conflicting semantics.)

@ketzacoatl
Copy link

Extra safety there sounds great 👍

@aaronhurt
Copy link
Member

After reading through all the comments and testing I'm comfortable merging this once the additional validation is added and the defaults reflect the current operating state.

Do not allow registry.consul.allowStale and
registry.consul.requireConsistent to be true at the same time. This
would cause errors when communicating with consul.
@jeremycw
Copy link
Contributor Author

jeremycw commented May 7, 2021

@leprechau I've added a validation to return an error if allowStale and requireConsistent are both true. The defaults should already match the existing configuration:

allowStale: false
requireConsistent: true

@scalp42

@aaronhurt
Copy link
Member

Thank you, I'll give this one more look and get it merged when I get back to a real browser.

@jeremycw
Copy link
Contributor Author

@leprechau Any update on this?

@daande
Copy link

daande commented Mar 3, 2022

Any update on this? @leprechau

@nathanejohnson nathanejohnson force-pushed the master branch 2 times, most recently from a55de9d to 04f958c Compare April 11, 2022 18:45
@jeremycw
Copy link
Contributor Author

@nathanejohnson Hey, it looks like this was about to be merged but then things went silent. Could we get another pair of eyes on this?

@nathanejohnson
Copy link
Member

@jeremycw thank you for bringing this to my attention. I will review this ASAP!

@jeremycw
Copy link
Contributor Author

jeremycw commented May 5, 2022

@nathanejohnson Any thoughts or updates?

@scalp42
Copy link

scalp42 commented May 6, 2022

@nathanejohnson nathanejohnson merged commit 3677770 into fabiolb:master May 6, 2022
@nathanejohnson
Copy link
Member

Sorry this took so long!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants