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

Request based on the SRV record of the service #51

Merged
merged 1 commit into from
Jan 17, 2017

Conversation

DennyLoko
Copy link
Contributor

I've made this changes to be possible to do a request based on the SRV record of the service. It is useful when you have a service discovery mechanism, like Consul, so you can pass the information and the system will query the SRV record and to the request based on it.

I do not expect this PR to be merged right away, but to start a discussion on the following topic.

Please, review it and suggest the needed changes.

@codecov-io
Copy link

codecov-io commented Jan 5, 2017

Current coverage is 96.93% (diff: 100%)

No coverage report found for master at 2e0c231.

Powered by Codecov. Last update 2e0c231...5213400

@DennyLoko
Copy link
Contributor Author

One of the things that I did not implement is the round robin based on the weight of the record.

The net.LookupSRV function already returns the records sorted by priority and randomize the ones with the same weight. So, upon the retry, it will try another service based on this criteria.

@jeevatkm
Copy link
Member

jeevatkm commented Jan 6, 2017

@DennyLoko Thanks for the PR, I appreciate it.

I know SRV records lookup is widely used in XMPP/Jabber, SIP, LDAP, etc.; not sure about HTTP(s) world.

Can you please help me to understand, this use case is benefits widely?

@DennyLoko
Copy link
Contributor Author

DennyLoko commented Jan 6, 2017

Hello @jeevatkm!

We use an extensive number of Docker containers on our microservices infrastructure, and we use Consul as service discovery mechanism to help us reach each container without the need to have a list of IP addresses of each container of each service.

Consul provides a DNS interface for querying the SRV record of the services, so this change could help other users which have the same infrastructure as me.

@jeevatkm
Copy link
Member

jeevatkm commented Jan 7, 2017

Thanks for providing real usage scenario. I hope and believe it will be useful for resty users. I will go through PR code changes and share my suggestions.

Thanks again for your time and effort.

Copy link
Member

@jeevatkm jeevatkm left a comment

Choose a reason for hiding this comment

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

@DennyLoko I have added my recommendations, please have a look and take care.

domain := strings.TrimRight(addrs[idx].Target, ".")
path = strings.TrimLeft(path, "/")

return fmt.Sprintf("%s://%s:%d/%s", DefaultClient.scheme, domain, addrs[idx].Port, path)
Copy link
Member

Choose a reason for hiding this comment

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

Please use r.client.scheme instead of DefaultClient.scheme.

@@ -465,3 +489,15 @@ func (r *Request) fmtBodyString() (body string) {

return
}

func (r *Request) selectAddr(addrs []*net.SRV, path string, attempt int) string {
if addrs == nil {
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add test case for when addrs is nil and SRV is record is set. So we can ensure request goes through or gives error info to caller.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I didn't understand, but I think this test case already cover this situation.

@jeevatkm
Copy link
Member

@DennyLoko whenever you push your changes, I will merge it. Thanks.

Copy link
Contributor Author

@DennyLoko DennyLoko left a comment

Choose a reason for hiding this comment

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

Sorry for taking so long to reply, it was a rush week.

I've replaced DefaultClient.scheme with r.client.scheme and added some documentation for the SetSRV function.

@@ -465,3 +489,15 @@ func (r *Request) fmtBodyString() (body string) {

return
}

func (r *Request) selectAddr(addrs []*net.SRV, path string, attempt int) string {
if addrs == nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I didn't understand, but I think this test case already cover this situation.

@jeevatkm jeevatkm self-assigned this Jan 16, 2017
@jeevatkm jeevatkm added this to the v0.11 Milestone milestone Jan 16, 2017
@jeevatkm
Copy link
Member

@DennyLoko no worries, thanks for your response.

Changes looks good, can you please squash these commits?

@DennyLoko
Copy link
Contributor Author

Done 👍

@jeevatkm jeevatkm merged commit bbe60b3 into go-resty:master Jan 17, 2017
@DennyLoko DennyLoko deleted the query-srv branch January 17, 2017 17:42
@jeevatkm
Copy link
Member

@DennyLoko Thanks, PR is merged.

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

Successfully merging this pull request may close these issues.

3 participants