dkron
dkron copied to clipboard
gRPC client for jobs
Is your feature request related to a problem? Please describe. The only official (documented) API is the HTTP - REST one. The code is using protobuf and gRPC and actually if you work with a single node it just works. When working with multiple nodes we might receive "node is not the leader" error.
Describe the solution you'd like Export the already exists gRPC client.
Describe alternatives you've considered Supply a simple method to receive the current leader address so we can talk with him directly OR IMO even better, encapsulate this logic. if the non-leader receive request and he knows the current leader - he will proxy the request and response.
Additional context
Could you elaborate on when and how you run into this?
Sure. I deployed on my k8s cluster 3 servers and 1 agent and expose them using a k8s dns. Using a gRPC client (dial to the dns URL - which load balanced between the instances) and accessed the methods from the following proto: https://github.com/distribworks/dkron/blob/master/proto/dkron.proto (compiled version can be found at: github.com/distribworks/dkron/v3/plugin/types)
e.g.:
...
_, err := client.SetJob(ctx, &dkron.SetJobRequest{Job: &dktypes.Job{
Name: request.Name,
Displayname: request.Name,
Schedule: "@at " + request.At.Format(time.RFC3339),
Timezone: "UTC",
}})
When I did my tests locally using only container that serves as both the server and the agent everything works fine. on the cluster, some of the requests return error "node is not the leader" (sorry, don't have the snippet as I teared down the cluster)
Let me know if you need more information
What benefit do you get from using a gRPC client to get Dkron to do stuff? In other words: why aren't you using the REST API?
My client is written in Go, just like this library. I found gRPC really convenient, especially when I can use the original data struct and method to invoke. Currently, I do use the REST API but personally I'd prefer the gRPC one (especially when it is already written and used inside this project)
The gRPC API is not a 1:1 representation of the REST API, it's intended to be used internally only, this is why you are encountering those "is not the leader" messages, you will need to implement the leader logic in the your client to know the leader and forward the requests to it.
Said that, having a gRPC and the equivalent REST API is something to think about, could be a good idea to serve both "protocols".
@moshebe what methods are you calling? Because the methods that could fail already proxy the requests to the leader, see https://github.com/distribworks/dkron/blob/master/dkron/grpc.go#L166