Skip to content
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

add grpc-web gateways for REST access to Journal and Shard APIs #400

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:
# We upload this to the artifacts that are attached to the action just to make it easy for
# someone to pull down a build from another branch.
- name: "Upload Binaries"
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: "gazette-x86_64-linux-gnu.zip"
path: ".build-ci/gazette-x86_64-linux-gnu.zip"
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ ci-release-gazette-examples-targets = \
# Targets of protobufs which must be compiled.
protobuf-targets = \
./broker/protocol/protocol.pb.go \
./broker/protocol/protocol.pb.gw.go \
./consumer/protocol/protocol.pb.go \
./consumer/protocol/protocol.pb.gw.go \
./consumer/recoverylog/recorded_op.pb.go \
./examples/word-count/word_count.pb.go

Expand Down
200 changes: 200 additions & 0 deletions broker/protocol/protocol.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions broker/protocol/protocol_gateway.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type: google.api.Service
config_version: 3

http:
rules:
- selector: protocol.Journal.List
post: /v1/journals/list
body: "*"
- selector: protocol.Journal.Read
post: /v1/journals/read
body: "*"
11 changes: 10 additions & 1 deletion cmd/gazette/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"syscall"
"time"

"github.com/gogo/gateway"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/jessevdk/go-flags"
log "github.com/sirupsen/logrus"
"go.gazette.dev/core/allocator"
Expand Down Expand Up @@ -85,7 +87,7 @@ func (cmdServe) Execute(args []string) error {
}

// Bind our server listener, grabbing a random available port if Port is zero.
srv, err := server.New("", Config.Broker.Host, Config.Broker.Port, serverTLS, peerTLS, Config.Broker.MaxGRPCRecvSize)
srv, err := server.New("", Config.Broker.Host, Config.Broker.Port, serverTLS, peerTLS, Config.Broker.MaxGRPCRecvSize, nil)
mbp.Must(err, "building Server instance")

// If a file:// root was provided, ensure it exists and apply it.
Expand Down Expand Up @@ -116,6 +118,13 @@ func (cmdServe) Execute(args []string) error {
signalCh = make(chan os.Signal, 1)
)
pb.RegisterJournalServer(srv.GRPCServer, pb.NewVerifiedJournalServer(service, verifier))

var mux *runtime.ServeMux = runtime.NewServeMux(
runtime.WithMarshalerOption(runtime.MIMEWildcard, new(gateway.JSONPb)),
runtime.WithProtoErrorHandler(runtime.DefaultHTTPProtoErrorHandler),
)
pb.RegisterJournalHandler(tasks.Context(), mux, srv.GRPCLoopback)
srv.HTTPMux.Handle("/v1/", Config.Broker.CORSWrapper(mux))
srv.HTTPMux.Handle("/", http_gateway.NewGateway(pb.NewRoutedJournalClient(lo, pb.NoopDispatchRouter{})))
ks.WatchApplyDelay = Config.Broker.WatchDelay

Expand Down
Loading
Loading