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

Allow specifying GRPC load balancer #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

d4l3k
Copy link

@d4l3k d4l3k commented May 23, 2018

This is the easiest way I can see of adding in load balancing. I don't think there should be an unexpected side effects but please let me know if you can think of anything.

This adds in a round robin DNSResolver for load balancing purposes. The GRPC DNSResolver first checks if SRV records are present on the specified host and if so, uses them. If they don't exist it just resolves the DNS hostname as normal. If there's an IP specified it just uses that.

@d4l3k
Copy link
Author

d4l3k commented Jun 3, 2018

@pieterlouw Any thoughts on this?

@pieterlouw
Copy link
Owner

Ho @d4l3k ,
Thanks for this, it looks great. I need to find a moment to test this myself before I merge it in.

Few things:

How does this affect the Caddyfile setup? Can you perhaps post an example?

The only thing that bothers me is the gRPC Naming package is still experimental according to the documentation. I'm sure it's stable, it's just I'm reluctant to add an API that might change and break future Caddy builds.

@d4l3k
Copy link
Author

d4l3k commented Jun 4, 2018

Hey,

This shouldn't change the Caddyfile setup at all. It just checks for a GRPC SRV record first. and falls back to just normal DNS resolution.

And yeah, I totally missed the fact that that package was experimental and deprecated. I'll investigate a bit more and update the PR.

@d4l3k
Copy link
Author

d4l3k commented Jun 4, 2018

Okay, I just took a deeper look into this. Looks like load balancing is actually supported out of the box, but the default resolver is "passthrough" and load balancer is "pick_first".

For SRV resolving you can just do dns://service.examples.com.

@d4l3k
Copy link
Author

d4l3k commented Jun 4, 2018

I updated this PR to add a balancer config option which lets you specify which load balancer mode you want to do. Resolvers can just be specified by the scheme :// in the backend_addr field.

As for the balancing stuff being experimental, this code no longer depends on any package other than the main grpc one which should prevent most issues and it seems unlikely that they'd remove the grpc.WithBalancerName method without notice considering the old deprecated load balancing mechanism still works.

This in use would look like

grpc dns://service.foo {
  balancer round_robin
}

@d4l3k d4l3k changed the title Use DNSResolver for load balancing purposes Allow specifying GRPC load balancer Jun 4, 2018
case "balancer":
if !c.Args(&s.balancerName) {
return c.Errf("balancer missing argument")
}
Copy link
Owner

Choose a reason for hiding this comment

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

Does this make "balancer" a required field in the Caddyfile?

"balancer" should be optional, especially important for backward compatibility.

Copy link
Author

Choose a reason for hiding this comment

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

I don't believe this makes it required. It just means if you specify balancer you need to provide an argument.

@pieterlouw
Copy link
Owner

pieterlouw commented Jun 6, 2018

Thanks @d4l3k

I added a comment on the changes you made in setup.go (https://github.com/pieterlouw/caddy-grpc/pull/5/files#diff-4d86aab957c347ca87f7021d57b17205)

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.

2 participants