foulkon icon indicating copy to clipboard operation
foulkon copied to clipboard

RFC: Adding a GRPC API

Open srenatus opened this issue 6 years ago • 5 comments

Hi there. We're transitioning our internal services to use GRPC (instead of HTTP/REST). Thus, I'd like to contribute a GRPC interface to Foulkon's worker.

What do you think? Would you appreciate the addition? Also, I don't just want to throw a huge junk of code over the fence, but rather incrementally add the functionality.

What does this look like?

  • a .proto definition for the service's methods
  • generated go code (using protoc-gen-go)
  • another wrapper package, grpc, around the methods defined in api, implementing the stubs generated from the .proto (this is akin to http)

Example: dex

This is how dex does it:

  • its proto, excerpt:
    // CreateClientReq is a request to make a client.
    message CreateClientReq {
      Client client = 1;
    }
    
    // CreateClientResp returns the response from creating a client.
    message CreateClientResp {
      bool already_exists = 1;
      Client client = 2; 
    }
    // ...
    
    service Dex {
      // CreateClient creates a client.
      rpc CreateClient(CreateClientReq) returns (CreateClientResp) {};
      // ...
    }
    
  • the generated code
  • the defined methods:
    func (d dexAPI) CreateClient(ctx context.Context, req *api.CreateClientReq) (*api.CreateClientResp, error) { /* ...  */ }
    

Notes

  • Generating the code also gives us a client library, which would fix #64.
  • Authenticating requests would, for GRPC, use the GRPC metadata -- containing a JWT token, or a special header (depending on the configured authenticators) -- in the same way it works for the HTTP API.

srenatus avatar Oct 23 '17 06:10 srenatus

@srenatus, we have to review this, it's a huge change as you said, we will tell you something soon. Thanks for your comments.

rsoletob avatar Oct 23 '17 07:10 rsoletob

@rsoletob Thanks! I'm looking forward to hear from you. Happy to clarify stuff, I've also just re-joined the gitter room for real-time comms.

srenatus avatar Oct 23 '17 07:10 srenatus

What I've forgotten to point out is that there's some potential here to eventually use grpc-gateway to generate the REST handlers, which would then reduce the overall amount of custom code again 😉

srenatus avatar Oct 23 '17 07:10 srenatus

The cool thing about GRPC is that it create a language-independent API. CoreOS etcd, Kubernetes and Docker migrate to use GRPC. I would love to see this as part of the project, too?

chris-rock avatar Oct 23 '17 10:10 chris-rock

@srenatus @chris-rock we agree with you, gRPC seems like a good feature. We dont have much experience working with gRPC, but we'll improve our knowledge about it. In short, we would love to add this function to foulkon. We let this issue open to track the progress of this feature.

sergiogarcia94 avatar Oct 24 '17 13:10 sergiogarcia94