Skip to content

Commit 1233892

Browse files
committed
update
1 parent 114e6a5 commit 1233892

File tree

4 files changed

+50
-17
lines changed

4 files changed

+50
-17
lines changed

go.mod

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/linkall-labs/vanus/client v0.1.0
2323
github.com/linkall-labs/vanus/proto v0.1.0
2424
github.com/linkall-labs/vanus/raft v0.1.0
25-
github.com/mwitkow/grpc-proxy v0.0.0-20220126150247-db34e7bfee32
25+
github.com/mwitkow/grpc-proxy v0.0.0
2626
github.com/ncw/directio v1.0.5
2727
github.com/pkg/errors v0.9.1
2828
github.com/prometheus/client_golang v1.11.1
@@ -46,10 +46,10 @@ replace (
4646
github.com/linkall-labs/vanus/client => ./client
4747
github.com/linkall-labs/vanus/proto => ./proto
4848
github.com/linkall-labs/vanus/raft => ./raft
49+
github.com/mwitkow/grpc-proxy => github.com/linkall-labs/grpc-proxy v0.0.0-20220624142509-a3b0cb2bb86c
4950
)
5051

5152
require (
52-
github.com/BurntSushi/toml v0.3.1 // indirect
5353
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220209173558-ad29539cd2e9 // indirect
5454
github.com/beorn7/perks v1.0.1 // indirect
5555
github.com/cespare/xxhash/v2 v2.1.1 // indirect
@@ -113,15 +113,11 @@ require (
113113
go.uber.org/multierr v1.6.0 // indirect
114114
go.uber.org/zap v1.17.0 // indirect
115115
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
116-
golang.org/x/mod v0.4.2 // indirect
117116
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
118117
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
119118
golang.org/x/text v0.3.7 // indirect
120-
golang.org/x/tools v0.1.5 // indirect
121-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
122119
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
123120
gopkg.in/yaml.v2 v2.4.0 // indirect
124-
honnef.co/go/tools v0.1.3 // indirect
125121
k8s.io/apimachinery v0.23.4 // indirect
126122
k8s.io/klog/v2 v2.30.0 // indirect
127123
k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect

go.sum

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ github.com/labstack/gommon v0.3.1 h1:OomWaJXm7xR6L1HmEtGyQf26TEn7V6X88mktX9kee9o
338338
github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
339339
github.com/linkall-labs/embed-etcd v0.0.1 h1:k1707kTZXS/HRqvt08K8fI3INJHiX1/VMPft5GWml0I=
340340
github.com/linkall-labs/embed-etcd v0.0.1/go.mod h1:2vIGENtcpLaQZ1JZvKq0LRUjvTlNCeY0r3ySTKwX0EA=
341+
github.com/linkall-labs/grpc-proxy v0.0.0-20220624142509-a3b0cb2bb86c h1:Psf/nuPqSfn3yF/AInrDmIs9bY2Rv56Cmf855i6//K0=
342+
github.com/linkall-labs/grpc-proxy v0.0.0-20220624142509-a3b0cb2bb86c/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0=
341343
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
342344
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
343345
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
@@ -373,8 +375,6 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY
373375
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
374376
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
375377
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
376-
github.com/mwitkow/grpc-proxy v0.0.0-20220126150247-db34e7bfee32 h1:CC9KzU7WPrK6DTppkUGiwmttoHCNwOLT7Z+stp1eIpU=
377-
github.com/mwitkow/grpc-proxy v0.0.0-20220126150247-db34e7bfee32/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0=
378378
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
379379
github.com/ncw/directio v1.0.5 h1:JSUBhdjEvVaJvOoyPAbcW0fnd0tvRXD76wEfZ1KcQz4=
380380
github.com/ncw/directio v1.0.5/go.mod h1:rX/pKEYkOXBGOggmcyJeJGloCkleSvphPx2eV3t6ROk=
@@ -603,7 +603,6 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
603603
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
604604
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
605605
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
606-
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
607606
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
608607
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
609608
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -677,6 +676,7 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ
677676
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
678677
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
679678
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
679+
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
680680
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
681681
golang.org/x/sys v0.0.0-20180816055513-1c9583448a9c/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
682682
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -979,7 +979,6 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
979979
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
980980
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
981981
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
982-
honnef.co/go/tools v0.1.3 h1:qTakTkI6ni6LFD5sBwwsdSO+AQqbSIxOauHTTQKZ/7o=
983982
honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las=
984983
k8s.io/api v0.23.4/go.mod h1:i77F4JfyNNrhOjZF7OwwNJS5Y1S9dpwvb9iYRYRczfI=
985984
k8s.io/apimachinery v0.23.4 h1:fhnuMd/xUL3Cjfl64j5ULKZ1/J9n8NuQEgNL+WXWfdM=

internal/gateway/grpc_proxy.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ package gateway
1717
import (
1818
"context"
1919
"fmt"
20-
ctrlpb "github.com/linkall-labs/vanus/proto/pkg/controller"
21-
"google.golang.org/grpc/credentials/insecure"
22-
"google.golang.org/protobuf/types/known/emptypb"
2320
"net"
2421
"sync"
2522
"time"
2623

2724
"github.com/linkall-labs/vanus/observability/log"
25+
ctrlpb "github.com/linkall-labs/vanus/proto/pkg/controller"
2826
"github.com/mwitkow/grpc-proxy/proxy"
2927
"google.golang.org/grpc"
3028
"google.golang.org/grpc/codes"
29+
"google.golang.org/grpc/credentials/insecure"
3130
"google.golang.org/grpc/metadata"
3231
"google.golang.org/grpc/status"
32+
"google.golang.org/protobuf/types/known/emptypb"
3333
)
3434

3535
func newCtrlProxy(port int, allowProxyMethod map[string]string, ctrlList []string) *ctrlProxy {
@@ -52,6 +52,7 @@ type ctrlProxy struct {
5252

5353
func (cp *ctrlProxy) start(ctx context.Context) error {
5454
grpcServer := grpc.NewServer(
55+
grpc.CustomCodec(proxy.Codec()),
5556
grpc.UnknownServiceHandler(proxy.TransparentHandler(cp.director)),
5657
)
5758
listen, err := net.Listen("tcp", fmt.Sprintf(":%d", cp.port))
@@ -179,6 +180,7 @@ func createGRPCConn(ctx context.Context, addr string) *grpc.ClientConn {
179180
var opts []grpc.DialOption
180181
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
181182
opts = append(opts, grpc.WithBlock())
183+
opts = append(opts, grpc.WithCodec(proxy.Codec()))
182184
ctx, cancel := context.WithCancel(ctx)
183185
timeout := false
184186
go func() {

internal/gateway/grpc_proxy_test.go

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ package gateway
1717
import (
1818
stdCtx "context"
1919
"fmt"
20+
"net"
21+
"testing"
22+
"time"
23+
2024
"github.com/golang/mock/gomock"
2125
"github.com/golang/protobuf/ptypes/empty"
26+
metapb "github.com/linkall-labs/vanus/proto/pkg/meta"
2227
"google.golang.org/grpc/credentials/insecure"
2328
"google.golang.org/protobuf/types/known/emptypb"
24-
"net"
25-
"testing"
26-
"time"
2729

2830
ctrlpb "github.com/linkall-labs/vanus/proto/pkg/controller"
2931
. "github.com/smartystreets/goconvey/convey"
@@ -108,7 +110,7 @@ func Test_A(t *testing.T) {
108110
})
109111

110112
Convey("test ping", func() {
111-
cp.allowProxyMethod["/linkall.vanus.controller.PingServer/Ping"] = "/linkall.vanus.controller.PingServer/Ping"
113+
cp.allowProxyMethod["/linkall.vanus.controller.PingServer/Ping"] = "ALLOW"
112114
pingCli := ctrlpb.NewPingServerClient(conn)
113115
time.Sleep(100 * time.Millisecond)
114116
res, err := pingCli.Ping(stdCtx.Background(), &empty.Empty{})
@@ -122,7 +124,41 @@ func Test_A(t *testing.T) {
122124
So(err, ShouldBeNil)
123125
So(res.LeaderAddr, ShouldEqual, "127.0.0.1:20003")
124126
So(res.GatewayAddr, ShouldEqual, "127.0.0.1:12345")
127+
})
125128

129+
Convey("test list eventbus", func() {
130+
cp.allowProxyMethod["/linkall.vanus.controller.PingServer/Ping"] = "ALLOW"
131+
cp.allowProxyMethod["/linkall.vanus.controller.EventBusController/ListEventBus"] = "ALLOW"
132+
ebCli := ctrlpb.NewEventBusControllerClient(conn)
133+
time.Sleep(100 * time.Millisecond)
134+
135+
ebSvc1.EXPECT().ListEventBus(gomock.Any(), gomock.Any()).Times(1).Return(&ctrlpb.ListEventbusResponse{
136+
Eventbus: []*metapb.EventBus{
137+
{
138+
Name: "battle1",
139+
LogNumber: 1,
140+
Id: 1,
141+
},
142+
{
143+
Name: "battle2",
144+
LogNumber: 2,
145+
Id: 2,
146+
},
147+
{
148+
Name: "battle3",
149+
LogNumber: 4,
150+
Id: 3,
151+
},
152+
{
153+
Name: "battle4",
154+
LogNumber: 4,
155+
Id: 4,
156+
},
157+
},
158+
}, nil)
159+
res, err := ebCli.ListEventBus(ctx, &empty.Empty{})
160+
So(err, ShouldBeNil)
161+
So(res.Eventbus, ShouldHaveLength, 4)
126162
})
127163

128164
cancel()

0 commit comments

Comments
 (0)