Repository navigation
Open
Description
Introduction
Right now, feast-java uses RestController (example code) to implement REST endpoints for both feast-core and feast-serving. However, this approach will increase maintenance cost. Therefore, generating REST endpoint from proto definitions is a cleaner way.
Proposed Change
Use grpc-gateway to generate the REST endpoint.
Steps
1. Add gateway server to translate REST call into gRPC call to another process inside the container
The example gateway server will look like:
package main
import (
"context"
"flag"
"fmt"
"net/http"
"github.com/golang/glog"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
coreGateWay "pkg/gateway/generated/feast/core"
servingGateWay "pkg/gateway/generated/feast/serving"
)
// gRPC serving endpoint
var servingServerEndpoint = flag.String("serving-server-endpoint", "localhost:6566", "gRPC server endpoint")
func run() error {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
mux := runtime.NewServeMux()
opts := []grpc.DialOption{grpc.WithInsecure()}
// Register ServingServing endpoint
err = servingGateWay.RegisterServingServiceHandlerFromEndpoint(ctx, mux, *servingServerEndpoint, opts)
if err != nil {
return err
}
// Start HTTP server (and proxy calls to gRPC server endpoint)
return http.ListenAndServe(":8000", mux)
}
func main() {
flag.Parse()
defer glog.Flush()
if err := run(); err != nil {
fmt.Println(err)
glog.Fatal(err)
}
}
2. Use supervisord to start two processes inside a container
We can provide instructions to use different entry points. Here's an example config:
[supervisord]
nodaemon=true
[program:serving]
directory=/
user=root
command=java -jar /opt/feast/feast-serving.jar --spring.config.location=classpath:/application.yml,file:/etc/feast/%(ENV_FEAST_SERVING_YML_NAME)s
[program:gateway]
directory=/
user=root
command=/opt/feast/gateway_server
--serving-server-endpoint=%(ENV_FEAST_SERVING_URL)s
numprocs=1
3. Remove existing REST controllers' code
As titled.
Metadata
Metadata
Assignees
Labels
No labels
Activity
randxie commentedon Apr 4, 2021
@woop Please feel free to also add other reviewers to the proposal.
woop commentedon Apr 4, 2021
Thanks @randxie.
I think what would be useful would be discussing the pros and cons of this approach vs sticking to what we have. It seems like what we're saying is
Pros
Cons
feast-javarepoDo you agree?
Questions
cc @pyalex
randxie commentedon Apr 4, 2021
@woop The pros/cons make sense to me. I would like to clarify a few points regarding the proposal:
Regarding the question, please see below:
nodaemonso it will run in foreground. I think either running in subprocess or a separate process sounds good to me. If the serving service crashes, it will be restarted. As the gateway is still up, the request could timeout.java -jar serving.jar, a single Java process will be run. If the user specifiessupervisord -d superviosrd.conf, then both the java binary and the go binary will be run.To summarize, the Golang server and supervisord config will be added into the container. We can use them if needed. Otherwise, everything will remain the same as before.
woop commentedon Apr 4, 2021
Somehow I missed this. Noted.
Overall it sounds ok to me. Would like to have some of the others also add their opinions.
randxie commentedon Apr 10, 2021
@woop Any updates on the review? I can start making the changes if we agree on the proposal.
woop commentedon Apr 10, 2021
Hey @randxie.
I ran the idea past @khorshuheng and some of the others. Summary
Since none of those community members have felt strongly enough about the topic to voice concerns, would you be open to the idea of adding the functionality (as proposed) but documenting it as "experimental"? We'll say that REST won't come with the same guarantees as gRPC in terms of stability, compatibility, or performance.
Also, is there any reason we can't use
systemdas opposed tosupervisord?randxie commentedon Apr 28, 2021
@woop Sure, documenting it as experimental makes perfect sense to me. Also, we shouldn't expect REST having same performance as gRPC provides.
Regarding
systemdvssupervisord, I don't have any preference. I will explore systemd a bit to see how it works.woop commentedon Apr 28, 2021
Great, happy to move forward then. I have a slight preference for
systemd, but not major. Just want to keep things simple.