Skip to content

Commit

Permalink
Feature/connect go (#2)
Browse files Browse the repository at this point in the history
* now use dgrpc
serve web connect
* move from deprecated `github.com/bufbuild/connect-go` to `connectrpc.com/connect`

---------

Co-authored-by: arnaudberger <[email protected]>
  • Loading branch information
billettc and ArnaudBger authored Feb 13, 2024
1 parent d80b734 commit 1ccdc05
Show file tree
Hide file tree
Showing 29 changed files with 811 additions and 2,837 deletions.
2 changes: 1 addition & 1 deletion server/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
badger3:
/.idea/
.idea
8 changes: 0 additions & 8 deletions server/.idea/.gitignore

This file was deleted.

8 changes: 0 additions & 8 deletions server/.idea/modules.xml

This file was deleted.

9 changes: 0 additions & 9 deletions server/.idea/server.iml

This file was deleted.

6 changes: 0 additions & 6 deletions server/.idea/vcs.xml

This file was deleted.

8 changes: 0 additions & 8 deletions server/.idea/watcherTasks.xml

This file was deleted.

9 changes: 2 additions & 7 deletions server/cmd/blockmeta/logger.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package main

import (
"log/slog"
"os"
"github.com/streamingfast/logging"
)

var logger *slog.Logger

func init() {
logger = slog.New(slog.NewJSONHandler(os.Stdout, nil))
}
var zlog, tracer = logging.RootLogger("blockmeta", "github.com/streamingfast/blockmeta-service/server/cmd/blockmeta")
75 changes: 33 additions & 42 deletions server/cmd/blockmeta/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,64 @@ import (
"context"
"flag"
"os"
"strings"
"time"
"regexp"

"github.com/streamingfast/dgrpc/server/factory"
"github.com/streamingfast/blockmeta-service/server"
"github.com/streamingfast/dauth"
"github.com/streamingfast/derr"
"go.uber.org/zap"
"google.golang.org/grpc"

pbbmsrv "github.com/streamingfast/blockmeta-service/pb/sf/blockmeta/v2"
"github.com/streamingfast/blockmeta-service/service"
derr "github.com/streamingfast/derr"
dgrpcserver "github.com/streamingfast/dgrpc/server"
)

var (
listenAddress = flag.String("grpc-listen-addr", "", "The gRPC server listen address")
sinkServerAddress = flag.String("sink-addr", "", "The sink server address")
listenAddress = flag.String("grpc-listen-addr", "", "The gRPC server listen address")
sinkServerAddress = flag.String("sink-addr", "", "The sink server address")
authUrl = flag.String("auth-url", "null://", "The URL of the auth server")
corsHostRegexAllowFlag = flag.String("cors-host-regex-allow", "^localhost", "Regex to allow CORS origin requests from, defaults to localhost only")
)

func main() {
flag.Parse()
ctx := context.Background()

if *sinkServerAddress == "" {
logger.Error("sink server address is required")
zlog.Error("sink server address is required")
os.Exit(1)
}

if *listenAddress == "" {
logger.Error("listen address is required")
zlog.Error("listen address is required")
os.Exit(1)
}

sinkClient := service.ConnectToSinkServer(*sinkServerAddress)
blockService := service.NewBlockService(sinkClient)
blockByTimeService := service.NewBlockByTimeService(sinkClient)
sinkClient := server.ConnectToSinkServer(*sinkServerAddress)

options := []dgrpcserver.Option{
dgrpcserver.WithLogger(zap.NewNop()),
dgrpcserver.WithHealthCheck(dgrpcserver.HealthCheckOverGRPC|dgrpcserver.HealthCheckOverHTTP, healthCheck()),
authenticator, err := dauth.New(*authUrl, zlog)
if err != nil {
zlog.Error("unable to create authenticator", zap.Error(err))
os.Exit(1)
}

if strings.Contains(*listenAddress, "*") {
options = append(options, dgrpcserver.WithInsecureServer())
} else {
options = append(options, dgrpcserver.WithPlainTextServer())
var corsHostRegexAllow *regexp.Regexp
if *corsHostRegexAllowFlag != "" {
hostRegex, err := regexp.Compile(*corsHostRegexAllowFlag)
if err != nil {
zlog.Error("unable to compile cors-host-regex-allow", zap.Error(err))
os.Exit(1)
}
corsHostRegexAllow = hostRegex
}

cleanListenAddress := strings.ReplaceAll(*listenAddress, "*", "")

grpcServer := factory.ServerFromOptions(options...)
grpcServer.RegisterService(func(gs grpc.ServiceRegistrar) {
pbbmsrv.RegisterBlockServer(gs, blockService)
pbbmsrv.RegisterBlockByTimeServer(gs, blockByTimeService)
})

grpcServer := server.NewGrpcServer(*listenAddress, sinkClient, corsHostRegexAllow, authenticator, zlog)
signal := derr.SetupSignalHandler(0)
go func() {
logger.Info("launching gRPC server", "listen_address", cleanListenAddress)
grpcServer.Launch(cleanListenAddress)
<-signal
grpcServer.Shutdown(nil)
}()

<-derr.SetupSignalHandler(30 * time.Second)
}

func healthCheck() dgrpcserver.HealthCheck {
return func(ctx context.Context) (isReady bool, out interface{}, err error) {
if derr.IsShuttingDown() {
return false, nil, nil
}
return true, nil, nil
grpcServer.Run(ctx)
<-grpcServer.Terminated()
if grpcServer.Err() != nil {
zlog.Error("server terminated with error", zap.Error(grpcServer.Err()))
os.Exit(1)
}
}
2 changes: 1 addition & 1 deletion server/cmd/tester/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"log"
"time"

pbbmsrv "github.com/streamingfast/blockmeta-service/pb/sf/blockmeta/v2"
pbbmsrv "github.com/streamingfast/blockmeta-service/server/pb/sf/blockmeta/v2"
"github.com/streamingfast/dgrpc"
"google.golang.org/protobuf/types/known/timestamppb"
)
Expand Down
110 changes: 46 additions & 64 deletions server/go.mod
Original file line number Diff line number Diff line change
@@ -1,93 +1,75 @@
module github.com/streamingfast/blockmeta-service
module github.com/streamingfast/blockmeta-service/server

go 1.22

require (
connectrpc.com/connect v1.14.0
github.com/rs/cors v1.8.3
github.com/streamingfast/dauth v0.0.0-20240213192022-da4946165b42
github.com/streamingfast/derr v0.0.0-20230515163924-8570aaa43fe1
github.com/streamingfast/dgrpc v0.0.0-20240119162453-69517bcc1a7f
google.golang.org/grpc v1.58.0
github.com/streamingfast/dgrpc v0.0.0-20240213191930-14e90f32025f
github.com/streamingfast/logging v0.0.0-20221209193439-bff11742bf4c
github.com/streamingfast/shutter v1.5.0
github.com/streamingfast/substreams-sink-kv v0.1.3-0.20240213164553-1d839b800880
go.uber.org/zap v1.24.0
google.golang.org/grpc v1.61.0
google.golang.org/protobuf v1.32.0
)

require (
cloud.google.com/go/compute v1.21.0 // indirect
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/container v1.22.1 // indirect
cloud.google.com/go/monitoring v1.15.1 // indirect
cloud.google.com/go/trace v1.10.1 // indirect
contrib.go.opencensus.io/exporter/stackdriver v0.12.6 // indirect
contrib.go.opencensus.io/exporter/zipkin v0.1.1 // indirect
cloud.google.com/go/trace v1.10.4 // indirect
connectrpc.com/grpchealth v1.3.0 // indirect
connectrpc.com/grpcreflect v1.2.0 // indirect
connectrpc.com/otelconnect v0.7.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v0.32.3 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.15.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.39.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/propagator v0.0.0-20221018185641-36f91511cfd7 // indirect
github.com/aws/aws-sdk-go v1.22.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blendle/zapdriver v1.3.1 // indirect
github.com/bufbuild/connect-go v1.8.0 // indirect
github.com/blendle/zapdriver v1.3.2-0.20200203083823-9200777f8a3d // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe // indirect
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 // indirect
github.com/envoyproxy/go-control-plane v0.11.1 // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.2 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 // indirect
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/openzipkin/zipkin-go v0.4.1 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.0 // indirect
github.com/rs/cors v1.8.3 // indirect
github.com/openzipkin/zipkin-go v0.4.2 // indirect
github.com/sethvargo/go-retry v0.2.3 // indirect
github.com/streamingfast/dtracing v0.0.0-20210811175635-d55665d3622a // indirect
github.com/streamingfast/logging v0.0.0-20220304214715-bc750a74b424 // indirect
github.com/streamingfast/sf-tracing v0.0.0-20230616174903-cd2ade641ca9 // indirect
github.com/streamingfast/shutter v1.5.0 // indirect
github.com/streamingfast/sf-tracing v0.0.0-20240209202324-9daa52c71a52 // indirect
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/detectors/gcp v1.9.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.36.4 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.15.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.15.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.15.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.15.1 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.15.1 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.15.1 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/sdk v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.opentelemetry.io/otel v1.23.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.23.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.23.1 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.23.1 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.23.1 // indirect
go.opentelemetry.io/otel/metric v1.23.1 // indirect
go.opentelemetry.io/otel/sdk v1.23.1 // indirect
go.opentelemetry.io/otel/trace v1.23.1 // indirect
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
google.golang.org/api v0.126.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.152.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 // indirect
)
Loading

0 comments on commit 1ccdc05

Please sign in to comment.