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

ping endpoint can now wait for leader #4600

Merged
merged 3 commits into from
Oct 28, 2015
Merged

ping endpoint can now wait for leader #4600

merged 3 commits into from
Oct 28, 2015

Conversation

otoolep
Copy link
Contributor

@otoolep otoolep commented Oct 28, 2015

With this change the ping endpoint now accepts an optional parameter wait_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

@otoolep
Copy link
Contributor Author

otoolep commented Oct 28, 2015

@corylanou @beckettsean

func TestHandler_PingWaitForLeader(t *testing.T) {
h := NewHandler(false)
w := httptest.NewRecorder()
h.ServeHTTP(w, MustNewRequest("GET", "/ping?wait_for_leader=1s", nil))
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@corylanou
Copy link
Contributor

Very nice! one minor nit. +1.

@otoolep
Copy link
Contributor Author

otoolep commented Oct 28, 2015

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.

otoolep added a commit that referenced this pull request Oct 28, 2015
ping endpoint can now wait for leader
@otoolep otoolep merged commit ef190b4 into master Oct 28, 2015
@otoolep otoolep deleted the wait_for_leader branch October 28, 2015 19:04
@gunnaraasen
Copy link
Member

I'm a little late to this, but just want to pitch some alternatives to wait_for_leader.

  • The ping endpoint could check for a leader and return http.StatusServiceUnavailable if none exists and http.StatusNoContent if a leader exists.
  • The ping endpoint could include another header like X-Influxdb-Status or X-Influxdb-Cluster with a value like available or unavailable.

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.

@otoolep
Copy link
Contributor Author

otoolep commented Oct 28, 2015

Clients can still poll. Simply set the timeout to, say, 1ms and keep requesting until the client gets 204.

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.

3 participants