feast-dev / feast-dev/feast-java-old

[Discuss] Use gRPC gateway to generate REST endpoints

Đang mở
#20 8 bình luận 0 reaction 1 người được giao Được giao cho @woop Xem trên GitHub
Ngôn ngữ chính
Java
Star
12
Fork
26
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

## Introduction

Right now, feast-java uses `RestController` ([example code](https://github.com/feast-dev/feast-java/blob/8541f36ecf28569db7ece35e936b5e9d83db3cde/serving/src/main/java/feast/serving/controller/ServingServiceRestController.java)) 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](https://github.com/grpc-ecosystem/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](http://supervisord.org/) 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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.