Skip to content

Commit

Permalink
Merge branch 'master' into grpc_compression
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia committed Oct 9, 2023
2 parents 783a633 + f50f39e commit ea955a3
Show file tree
Hide file tree
Showing 44 changed files with 1,721 additions and 287 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.21.1]
go-version: [1.21.2]
steps:
- name: Install Go
uses: actions/setup-go@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
strategy:
matrix:
go-version: [1.21.1]
go-version: [1.21.2]
tarantool-version: [2.7.2]
steps:
- name: Install Go
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/FZambia/statik v0.1.2-0.20180217151304-b9f012bb2a1b
github.com/FZambia/tarantool v0.3.1
github.com/FZambia/viper-lite v0.0.0-20220110144934-1899f66c7d0e
github.com/centrifugal/centrifuge v0.30.2
github.com/centrifugal/centrifuge v0.30.3-0.20231009162654-6036b763c9aa
github.com/centrifugal/protocol v0.10.0
github.com/cristalhq/jwt/v5 v5.1.0
github.com/gobwas/glob v0.2.3
Expand Down Expand Up @@ -38,7 +38,7 @@ require (
go.opentelemetry.io/otel/trace v1.19.0
go.uber.org/automaxprocs v1.5.3
golang.org/x/crypto v0.13.0
golang.org/x/sync v0.3.0
golang.org/x/sync v0.4.0
golang.org/x/time v0.3.0
google.golang.org/grpc v1.58.2
google.golang.org/protobuf v1.31.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/centrifugal/centrifuge v0.30.2 h1:Ru/6lPpOMdqTTDRG/gr74HPUBRq7h574WDVwA47lv0U=
github.com/centrifugal/centrifuge v0.30.2/go.mod h1:6aIBCCjAnwpqr6SfkkU36Z0B9s/IZK+Z5faippXPXbI=
github.com/centrifugal/centrifuge v0.30.3-0.20231009162654-6036b763c9aa h1:EFaapglrL6ebSlWBfzhBqBPwVfUq1kPQWjPNPgD4qv0=
github.com/centrifugal/centrifuge v0.30.3-0.20231009162654-6036b763c9aa/go.mod h1:ojcxqaWUcxfQ9t5dVNwOe2/N66AdQMwrYbjymTfkLvs=
github.com/centrifugal/protocol v0.10.0 h1:Lac48ATVjVjirYPTHxbSMmiQXXajx7dhARKHy1UOL+A=
github.com/centrifugal/protocol v0.10.0/go.mod h1:Tq5I1mBpLHkLxNM9gfb3Gth+sTE2kKU5hH3cVgmVs9s=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
Expand Down Expand Up @@ -246,8 +246,8 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
32 changes: 22 additions & 10 deletions internal/api/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,40 @@ func GRPCKeyAuth(key string) grpc.ServerOption {
}

// GRPCAPIServiceConfig for GRPC API Service.
type GRPCAPIServiceConfig struct{}
type GRPCAPIServiceConfig struct {
UseOpenTelemetry bool
UseTransportErrorMode bool
}

// RegisterGRPCServerAPI registers GRPC API service in provided GRPC server.
func RegisterGRPCServerAPI(n *centrifuge.Node, apiExecutor *Executor, server *grpc.Server, config GRPCAPIServiceConfig, useOpenTelemetry bool) error {
RegisterCentrifugoApiServer(server, newGRPCAPIService(n, apiExecutor, config, useOpenTelemetry))
func RegisterGRPCServerAPI(n *centrifuge.Node, apiExecutor *Executor, server *grpc.Server, config GRPCAPIServiceConfig) error {
RegisterCentrifugoApiServer(server, newGRPCAPIService(n, apiExecutor, config))
return nil
}

// grpcAPIService can answer on GRPC API requests.
type grpcAPIService struct {
UnimplementedCentrifugoApiServer

config GRPCAPIServiceConfig
api *Executor
useOpenTelemetry bool
config GRPCAPIServiceConfig
api *Executor
}

// newGRPCAPIService creates new Service.
func newGRPCAPIService(_ *centrifuge.Node, apiExecutor *Executor, c GRPCAPIServiceConfig, useOpenTelemetry bool) *grpcAPIService {
func newGRPCAPIService(_ *centrifuge.Node, apiExecutor *Executor, c GRPCAPIServiceConfig) *grpcAPIService {
return &grpcAPIService{
config: c,
api: apiExecutor,
useOpenTelemetry: useOpenTelemetry,
config: c,
api: apiExecutor,
}
}

func (s *grpcAPIService) useTransportErrorMode(ctx context.Context) bool {
if s.config.UseTransportErrorMode {
return true
}
if md, ok := metadata.FromIncomingContext(ctx); ok {
errorMode := md.Get("x-centrifugo-error-mode")
return len(errorMode) > 0 && errorMode[0] == "transport"
}
return false
}
92 changes: 79 additions & 13 deletions internal/api/grpc_handler_gen.go

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

13 changes: 12 additions & 1 deletion internal/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (

// Config configures APIHandler.
type Config struct {
UseOpenTelemetry bool
UseOpenTelemetry bool
UseTransportErrorMode bool
}

// Handler is responsible for processing API commands over HTTP.
Expand Down Expand Up @@ -413,3 +414,13 @@ func (s *Handler) writeJson(w http.ResponseWriter, data []byte) {
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write(data)
}

func (s *Handler) writeJsonCustomStatus(w http.ResponseWriter, statusCode int, data []byte) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(statusCode)
_, _ = w.Write(data)
}

func (s *Handler) useTransportErrorMode(r *http.Request) bool {
return s.config.UseTransportErrorMode || r.Header.Get("X-Centrifugo-Error-Mode") == "transport"
}
Loading

0 comments on commit ea955a3

Please sign in to comment.