Skip to content

Commit 567e6fc

Browse files
committed
grpc upstream
1 parent 68c78b0 commit 567e6fc

File tree

9 files changed

+1605
-77
lines changed

9 files changed

+1605
-77
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
sudo apt install -y cpanminus build-essential libncurses5-dev libreadline-dev libssl-dev perl luarocks libpcre3 libpcre3-dev zlib1g-dev
3333
sudo luarocks install lua-resty-http > build.log 2>&1 || (cat build.log && exit 1)
3434
sudo luarocks install lua-resty-openssl > build.log 2>&1 || (cat build.log && exit 1)
35+
sudo cd t/assets/grpc && ./setup.sh > build.log 2>&1 || (cat build.log && exit 1) && popd
3536
3637
- name: Before install
3738
run: |

src/ngx_http_apisix_module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ ngx_http_apisix_is_upstream_pass_trailers(ngx_http_request_t *r)
10741074
ctx = ngx_http_apisix_get_module_ctx(r);
10751075

10761076
if (ctx != NULL && ctx->upstream_pass_trailers_set) {
1077-
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "upstream_pass_trailers_set: %d", ctx->upstream_pass_trailers);
1077+
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "apisix upstream pass trailers set: %d", ctx->upstream_pass_trailers);
10781078
return ctx->upstream_pass_trailers;
10791079
}
10801080

t/assets/grpc/a6/route.pb.go

Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package a6
19+
20+
import (
21+
context "context"
22+
fmt "fmt"
23+
proto "github.com/golang/protobuf/proto"
24+
grpc "google.golang.org/grpc"
25+
codes "google.golang.org/grpc/codes"
26+
status "google.golang.org/grpc/status"
27+
math "math"
28+
)
29+
30+
// Reference imports to suppress errors if they are not otherwise used.
31+
var _ = proto.Marshal
32+
var _ = fmt.Errorf
33+
var _ = math.Inf
34+
35+
// This is a compile-time assertion to ensure that this generated file
36+
// is compatible with the proto package it is being compiled against.
37+
// A compilation error at this line likely means your copy of the
38+
// proto package needs to be updated.
39+
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
40+
41+
type Query struct {
42+
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
43+
XXX_NoUnkeyedLiteral struct{} `json:"-"`
44+
XXX_unrecognized []byte `json:"-"`
45+
XXX_sizecache int32 `json:"-"`
46+
}
47+
48+
func (m *Query) Reset() { *m = Query{} }
49+
func (m *Query) String() string { return proto.CompactTextString(m) }
50+
func (*Query) ProtoMessage() {}
51+
func (*Query) Descriptor() ([]byte, []int) {
52+
return fileDescriptor_0984d49a362b6b9f, []int{0}
53+
}
54+
55+
func (m *Query) XXX_Unmarshal(b []byte) error {
56+
return xxx_messageInfo_Query.Unmarshal(m, b)
57+
}
58+
func (m *Query) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
59+
return xxx_messageInfo_Query.Marshal(b, m, deterministic)
60+
}
61+
func (m *Query) XXX_Merge(src proto.Message) {
62+
xxx_messageInfo_Query.Merge(m, src)
63+
}
64+
func (m *Query) XXX_Size() int {
65+
return xxx_messageInfo_Query.Size(m)
66+
}
67+
func (m *Query) XXX_DiscardUnknown() {
68+
xxx_messageInfo_Query.DiscardUnknown(m)
69+
}
70+
71+
var xxx_messageInfo_Query proto.InternalMessageInfo
72+
73+
func (m *Query) GetName() string {
74+
if m != nil {
75+
return m.Name
76+
}
77+
return ""
78+
}
79+
80+
type Route struct {
81+
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
82+
Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"`
83+
XXX_NoUnkeyedLiteral struct{} `json:"-"`
84+
XXX_unrecognized []byte `json:"-"`
85+
XXX_sizecache int32 `json:"-"`
86+
}
87+
88+
func (m *Route) Reset() { *m = Route{} }
89+
func (m *Route) String() string { return proto.CompactTextString(m) }
90+
func (*Route) ProtoMessage() {}
91+
func (*Route) Descriptor() ([]byte, []int) {
92+
return fileDescriptor_0984d49a362b6b9f, []int{1}
93+
}
94+
95+
func (m *Route) XXX_Unmarshal(b []byte) error {
96+
return xxx_messageInfo_Route.Unmarshal(m, b)
97+
}
98+
func (m *Route) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
99+
return xxx_messageInfo_Route.Marshal(b, m, deterministic)
100+
}
101+
func (m *Route) XXX_Merge(src proto.Message) {
102+
xxx_messageInfo_Route.Merge(m, src)
103+
}
104+
func (m *Route) XXX_Size() int {
105+
return xxx_messageInfo_Route.Size(m)
106+
}
107+
func (m *Route) XXX_DiscardUnknown() {
108+
xxx_messageInfo_Route.DiscardUnknown(m)
109+
}
110+
111+
var xxx_messageInfo_Route proto.InternalMessageInfo
112+
113+
func (m *Route) GetName() string {
114+
if m != nil {
115+
return m.Name
116+
}
117+
return ""
118+
}
119+
120+
func (m *Route) GetPath() string {
121+
if m != nil {
122+
return m.Path
123+
}
124+
return ""
125+
}
126+
127+
func init() {
128+
proto.RegisterType((*Query)(nil), "a6.Query")
129+
proto.RegisterType((*Route)(nil), "a6.Route")
130+
}
131+
132+
func init() { proto.RegisterFile("route.proto", fileDescriptor_0984d49a362b6b9f) }
133+
134+
var fileDescriptor_0984d49a362b6b9f = []byte{
135+
// 149 bytes of a gzipped FileDescriptorProto
136+
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2e, 0xca, 0x2f, 0x2d,
137+
0x49, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x4a, 0x34, 0x53, 0x92, 0xe6, 0x62, 0x0d,
138+
0x2c, 0x4d, 0x2d, 0xaa, 0x14, 0x12, 0xe2, 0x62, 0xc9, 0x4b, 0xcc, 0x4d, 0x95, 0x60, 0x54, 0x60,
139+
0xd4, 0xe0, 0x0c, 0x02, 0xb3, 0x95, 0xf4, 0xb9, 0x58, 0x83, 0x40, 0xea, 0xb1, 0x49, 0x82, 0xc4,
140+
0x0a, 0x12, 0x4b, 0x32, 0x24, 0x98, 0x20, 0x62, 0x20, 0xb6, 0x51, 0x24, 0x17, 0x0f, 0x58, 0x43,
141+
0x70, 0x6a, 0x51, 0x59, 0x66, 0x72, 0xaa, 0x90, 0x12, 0x17, 0x87, 0x7b, 0x6a, 0x09, 0xc4, 0x0c,
142+
0x4e, 0xbd, 0x44, 0x33, 0x3d, 0xb0, 0x5d, 0x52, 0x60, 0x26, 0x58, 0x54, 0x89, 0x41, 0x48, 0x95,
143+
0x8b, 0x13, 0xa6, 0xa6, 0x18, 0x97, 0x22, 0x03, 0x46, 0x27, 0xf6, 0x28, 0x56, 0x3d, 0x7d, 0xeb,
144+
0x44, 0xb3, 0x24, 0x36, 0xb0, 0xe3, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x54, 0xf0, 0x73,
145+
0x63, 0xcb, 0x00, 0x00, 0x00,
146+
}
147+
148+
// Reference imports to suppress errors if they are not otherwise used.
149+
var _ context.Context
150+
var _ grpc.ClientConn
151+
152+
// This is a compile-time assertion to ensure that this generated file
153+
// is compatible with the grpc package it is being compiled against.
154+
const _ = grpc.SupportPackageIsVersion4
155+
156+
// RouteServiceClient is the client API for RouteService service.
157+
//
158+
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
159+
type RouteServiceClient interface {
160+
GetRoute(ctx context.Context, in *Query, opts ...grpc.CallOption) (*Route, error)
161+
GetRoutes(ctx context.Context, in *Query, opts ...grpc.CallOption) (RouteService_GetRoutesClient, error)
162+
}
163+
164+
type routeServiceClient struct {
165+
cc *grpc.ClientConn
166+
}
167+
168+
func NewRouteServiceClient(cc *grpc.ClientConn) RouteServiceClient {
169+
return &routeServiceClient{cc}
170+
}
171+
172+
func (c *routeServiceClient) GetRoute(ctx context.Context, in *Query, opts ...grpc.CallOption) (*Route, error) {
173+
out := new(Route)
174+
err := c.cc.Invoke(ctx, "/a6.RouteService/GetRoute", in, out, opts...)
175+
if err != nil {
176+
return nil, err
177+
}
178+
return out, nil
179+
}
180+
181+
func (c *routeServiceClient) GetRoutes(ctx context.Context, in *Query, opts ...grpc.CallOption) (RouteService_GetRoutesClient, error) {
182+
stream, err := c.cc.NewStream(ctx, &_RouteService_serviceDesc.Streams[0], "/a6.RouteService/GetRoutes", opts...)
183+
if err != nil {
184+
return nil, err
185+
}
186+
x := &routeServiceGetRoutesClient{stream}
187+
if err := x.ClientStream.SendMsg(in); err != nil {
188+
return nil, err
189+
}
190+
if err := x.ClientStream.CloseSend(); err != nil {
191+
return nil, err
192+
}
193+
return x, nil
194+
}
195+
196+
type RouteService_GetRoutesClient interface {
197+
Recv() (*Route, error)
198+
grpc.ClientStream
199+
}
200+
201+
type routeServiceGetRoutesClient struct {
202+
grpc.ClientStream
203+
}
204+
205+
func (x *routeServiceGetRoutesClient) Recv() (*Route, error) {
206+
m := new(Route)
207+
if err := x.ClientStream.RecvMsg(m); err != nil {
208+
return nil, err
209+
}
210+
return m, nil
211+
}
212+
213+
// RouteServiceServer is the server API for RouteService service.
214+
type RouteServiceServer interface {
215+
GetRoute(context.Context, *Query) (*Route, error)
216+
GetRoutes(*Query, RouteService_GetRoutesServer) error
217+
}
218+
219+
// UnimplementedRouteServiceServer can be embedded to have forward compatible implementations.
220+
type UnimplementedRouteServiceServer struct {
221+
}
222+
223+
func (*UnimplementedRouteServiceServer) GetRoute(ctx context.Context, req *Query) (*Route, error) {
224+
return nil, status.Errorf(codes.Unimplemented, "method GetRoute not implemented")
225+
}
226+
func (*UnimplementedRouteServiceServer) GetRoutes(req *Query, srv RouteService_GetRoutesServer) error {
227+
return status.Errorf(codes.Unimplemented, "method GetRoutes not implemented")
228+
}
229+
230+
func RegisterRouteServiceServer(s *grpc.Server, srv RouteServiceServer) {
231+
s.RegisterService(&_RouteService_serviceDesc, srv)
232+
}
233+
234+
func _RouteService_GetRoute_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
235+
in := new(Query)
236+
if err := dec(in); err != nil {
237+
return nil, err
238+
}
239+
if interceptor == nil {
240+
return srv.(RouteServiceServer).GetRoute(ctx, in)
241+
}
242+
info := &grpc.UnaryServerInfo{
243+
Server: srv,
244+
FullMethod: "/a6.RouteService/GetRoute",
245+
}
246+
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
247+
return srv.(RouteServiceServer).GetRoute(ctx, req.(*Query))
248+
}
249+
return interceptor(ctx, in, info, handler)
250+
}
251+
252+
func _RouteService_GetRoutes_Handler(srv interface{}, stream grpc.ServerStream) error {
253+
m := new(Query)
254+
if err := stream.RecvMsg(m); err != nil {
255+
return err
256+
}
257+
return srv.(RouteServiceServer).GetRoutes(m, &routeServiceGetRoutesServer{stream})
258+
}
259+
260+
type RouteService_GetRoutesServer interface {
261+
Send(*Route) error
262+
grpc.ServerStream
263+
}
264+
265+
type routeServiceGetRoutesServer struct {
266+
grpc.ServerStream
267+
}
268+
269+
func (x *routeServiceGetRoutesServer) Send(m *Route) error {
270+
return x.ServerStream.SendMsg(m)
271+
}
272+
273+
var _RouteService_serviceDesc = grpc.ServiceDesc{
274+
ServiceName: "a6.RouteService",
275+
HandlerType: (*RouteServiceServer)(nil),
276+
Methods: []grpc.MethodDesc{
277+
{
278+
MethodName: "GetRoute",
279+
Handler: _RouteService_GetRoute_Handler,
280+
},
281+
},
282+
Streams: []grpc.StreamDesc{
283+
{
284+
StreamName: "GetRoutes",
285+
Handler: _RouteService_GetRoutes_Handler,
286+
ServerStreams: true,
287+
},
288+
},
289+
Metadata: "route.proto",
290+
}

t/assets/grpc/a6/route.proto

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one or more
3+
// contributor license agreements. See the NOTICE file distributed with
4+
// this work for additional information regarding copyright ownership.
5+
// The ASF licenses this file to You under the Apache License, Version 2.0
6+
// (the "License"); you may not use this file except in compliance with
7+
// the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
//
17+
18+
syntax = "proto3";
19+
20+
package a6;
21+
22+
option go_package = "./;a6";
23+
24+
service RouteService {
25+
rpc GetRoute(Query) returns (Route) {}
26+
rpc GetRoutes(Query) returns (stream Route) {}
27+
}
28+
29+
message Query {
30+
string name = 1;
31+
}
32+
33+
message Route {
34+
string name = 1;
35+
string path = 2;
36+
}

t/assets/grpc/go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module apisix.apache.org/plugin/grpc-web
2+
3+
go 1.16
4+
5+
require (
6+
github.com/golang/protobuf v1.5.2
7+
google.golang.org/grpc v1.53.0
8+
)

0 commit comments

Comments
 (0)