-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
apigateway example #203
apigateway example #203
Conversation
@peterbourgon Could you take a look at the last commit and tell me if that is what you have in mind, please. |
Keeping my comments limited to the architecture for the time being...
|
The json files are consul definition files. The example services don't self-register with consul. I pass these files to consul on startup to let it know about the services which is I don't like but was the fastest way. I could add self-registration to the other example services or add a script which starts the service and does 3rd party registration. Yes, I need to clean up the code. The make{Concat,Sum}Handler can be merged together. I lean towards having the endpoint and handler factory functions in the client/service packages, to keep the code each service adds, to the apigateway, to a minimum. It would make swapping service in and out of the apigateway simpler and reducing the imports to just one package per services instead for example addsvc, being two imports at the moment. |
Ahh, I see. For the purposes of this example, let's leave those out, and just assume that the operator is already running the services and has them registered in Consul. (We should add self-registration in #167.)
It's not just about cleaning up the existing code, it's about domain of responsibility. If the API gateway needs to unmarshal and remarshal requests, then it seems like that code should be owned by the respective services and called, rather than duplicated here. That in turn implies the services need either have client packages, or export the MakeFoo{Handler, Endpoint} methods — not sure which right now. Right? What do you think? |
I agree, I removed the files.
Endpoint methods should be in a separate package, like netflix is handling it. |
OK. Where do we stand here? Is the PR in a state that you consider final? Or are you looking for more direction from me? |
I consider it final. It shows a basic apigateway, which could be used as a starting point. I like to keep the service endpoint factory code (eg. makeSumEndpoint) in the apigateway package because it is just relevant to the apigateway example. Should I squash the commits into one? |
"github.com/hashicorp/consul/api" | ||
"golang.org/x/net/context" | ||
"google.golang.org/grpc" | ||
) |
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.
Please separate these imports into 3 groups:
import (
// stdlib
// non go-kit
// github.com/go-kit/kit/*
)
and remove the commented-out statements.
Here's a patch: https://gist.github.com/peterbourgon/4385034065703985e2ef You can apply it with Changes:
Does it make sense? Did I overlook anything? Do you like it? :) If it's good, please commit and rebase on master, and we can get this merged! |
The patch looks great.
I don't see a problem with it being an unbuffered channel. You also didn't change it in the patch. |
@marshauf You're right. In some circumstances it's important for all goroutines to be able to push into the channel even if there's no receivers, to prevent goroutine leaks. But in this case we just teardown immediately, so no problem. |
…consul and forwards rpc calls to discovered endpoints
… variable to construct the apigateway mapping
* Reorder imports * Remove flagset * Add loadbalancer.Retry and parameters * Restructure service definitions * Make ServiceDef an anonymous inline type * Rename the factory functions for symmetry * Add a lot of comments * Pass method as parameter to httpFactory * Passing "fatal" to logger.Log doesn't terminate; fix some instances of that * Consistent logger.Log "err" key with error vals * Changes to makeHandler * Use Retry-wrapped loadbalancer instead of invoking loadbalancer.Endpoint directly * Write http.Error to client in case of error
7844d1e
to
5dc97b3
Compare
Nice! Thanks for the contribution! |
[WIP] apigateway example
This is a work-in-progress pull request as discussed in #202 .
Running consul with the provided service definition, stringsvc3 and apigateway, you can run
instead of directly calling the stringsvc3 service method.
The apigateway currently only handles http json encoded calls. To support different transports I could check the consul service definition tags for values like "HTTP/JSON", "gRPC" to determine the transport and codec.