-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
ping endpoint can now wait for leader #4600
Conversation
func TestHandler_PingWaitForLeader(t *testing.T) { | ||
h := NewHandler(false) | ||
w := httptest.NewRecorder() | ||
h.ServeHTTP(w, MustNewRequest("GET", "/ping?wait_for_leader=1s", nil)) |
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.
nit: this should be /ping?wait-for-leader=1s
. Underscores technically need to be encoded in a parameter name.
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.
So you're suggesting we change the API? I didn't know this. Can you provide a reference?
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.
ah, it appears I'm wrong. An underscore
doesn't need to be encoded, but I've seen code that encodes urls encode them to %5f
in the past, so I assumed (incorrectly) it was part of the spec. Personally, I don't like underscores in urls as they are hard to read, but that's a preference thing. As long as we are consistent in our API that is probably what matters.
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.
Well, at the risk of bike-shedding, I think we should differentiate between the path i.e. ping and a query param. I also prefer hyphens in the paths, but query params seem different to me. For example, Twitter uses underscores in its query params.
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.
yup, all good by me. If there was a spec it would be different, but because there is not, consistency is the only thing that really matters.
Very nice! one minor nit. +1. |
Since @corylanou seems to have left it at my discretion, I am going with underscores for our first multi-word query param. We can still change before 0.9.5 releases if necessary. |
ping endpoint can now wait for leader
I'm a little late to this, but just want to pitch some alternatives to
Both of these would then allow a client to poll for the status of a node instead sending a request and waiting potentially several seconds for a response. Most clients would need to have some kind of polling in place anyway since the HTTP timeout would be tripped for any serious cluster problems. |
Clients can still poll. Simply set the timeout to, say, 1ms and keep requesting until the client gets 204. |
With this change the
ping
endpoint now accepts an optional parameterwait_for_leader
, which should be supplied with a timeout. If set then the endpoint will not return until the system has a Raft leader, or the timeout passes. If the timeout passes 503 is returned.If the timeout is 0, then the endpoint waits forever.
https://github.com/influxdb/influxdb.com/issues/438