-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Added a way to override default consistency level per agent #3920
Added a way to override default consistency level per agent #3920
Conversation
Following conversation hashicorp#3911 This patch allow to change the default behavior of Consul regarding consistency
…lelism to avoid timing issues on their contended CPUs
…delay gathering packages until the makefile
This avoids a conflict with #datacenter later on the page. We're mixing histroic manually specified anchors with generated anchors (via redcarpet / middleman-hashicorp) so we have to manually override the automatic generation here. I was tempted to rewrite the old manual anchors to use the automatic generation, but there is no way to maintain backwards compatibility, so will leave that for a time when it is appropriate for us to break links (or redirect them, etc). Fixes hashicorp#3916
Hello @banks, What do you think about this kind of implementation, would it be mergeable on long term? Regards |
I'll discuss again with the team on our Friday call and see if there is consensus on this. Thanks for all you effort chasing down these optimisations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pierresouchay I just got a chance to review this and added some more comments. We are ready to take this after that though, so this will probably get merged this week after you address my latest feedback.
agent/config/runtime.go
Outdated
@@ -461,6 +461,14 @@ type RuntimeConfig struct { | |||
// flag: -datacenter string | |||
Datacenter string | |||
|
|||
// Defines the maximum stale value for discovery path. Defauls to "0s". | |||
// Discovery paths are /v1/catalog/* and /v1/heath/* paths |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v1/health
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
agent/http.go
Outdated
defaults = false | ||
} | ||
if maxStale := query.Get("max_stale"); maxStale != "" { | ||
fmt.Printf("**** max_stale=%s\n", maxStale) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops... sorry, fixed
agent/http_test.go
Outdated
@@ -632,13 +634,70 @@ func TestParseConsistency(t *testing.T) { | |||
} | |||
} | |||
|
|||
// ensureConsistency check if consistency modes are correclty applied |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo in correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
agent/http.go
Outdated
if defaults { | ||
path := req.URL.Path | ||
if strings.HasPrefix(path, "/v1/catalog") || strings.HasPrefix(path, "/v1/health") { | ||
b.MaxStaleDuration = s.agent.config.DiscoveryMaxStale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrite this part as follows to make it a bit cleaner
if s.agent.config.DiscoveryMaxState > 0 {
b.MaxStaleDuration = s.agent.config.DiscoveryMaxStale
b.AllowStale = true
}
agent/http.go
Outdated
if b.MaxStaleDuration.Nanoseconds() > 0 { | ||
b.AllowStale = true | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upon further discussion on this, we thought it would be nice to add a header when the default consistency mode is overridden, so one suggestion we have is to add a new response header. This method could add a header like resp.AddHeader("X-Consul-Effective-Consistency-Level","stale")
or resp.AddHeader("X-Consul-Effective-Consistency-Level","leader")
etc. That way if a client lib is making a default request to an agent that has DiscoveryMaxStale set and is being overridden by this block, the response should tell you what it used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, doing it as well
Also please mention the new discovery_max_stale property in the docs here - https://github.com/hashicorp/consul/blob/master/website/source/docs/agent/options.html.md#configuration-key-reference |
agent/http.go
Outdated
dur, err := time.ParseDuration(maxStale) | ||
if err != nil { | ||
resp.WriteHeader(http.StatusBadRequest) | ||
fmt.Fprint(resp, "Invalid max_stale time") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also include the bad value here, so something like fmt.Fprint(resp, "Invalid max_stale value %q", maxStale)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
Minor fixes (typos in comments) Removed fmt.Printf debug code Added documentation to new option
@preetapan Thank you very much for the review, I made the all the fixes. The X-Consul-Effective-Consistency-Level is a bit more intrusive than expected since I had to add a setMeta in prepared queries as well (was missing, was maybe a bug) I also updated the documentation |
@@ -917,6 +917,14 @@ Consul will not enable TLS for the HTTP API unless the `https` port has been ass | |||
leader, so this lets Consul continue serving requests in long outage scenarios where no leader can | |||
be elected. | |||
|
|||
* <a name="discovery_max_stale"></a><a href="discovery_max_stale">`discovery_max_stale`</a> - In a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrite as
`discovery_max_stale` This enables stale requests for all service discovery HTTP endpoints. This is similar to how `max_stale` works for DNS requests. If this value is zero (default) then all service discovery HTTP endpoints are forwarded to the leader. If this value is greater than zero, any Consul server can handle the service discovery request. If a Consul server is behind the leader by more than discovery_max_stale, the query will be re-evaluated on the leader to get more up-to-date results.
@@ -157,6 +173,8 @@ type QueryMeta struct { | |||
|
|||
// Used to indicate if there is a known leader node | |||
KnownLeader bool | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment
Did the few last changes in PR #4004 , closing this one out |
Following conversation #3911
This patch allow to change the default behavior of Consul regarding
consistency
It still requires discussion probably and futher test, just a start for discussion