From 5b3e590cf24fd912893791121f49a4b495258119 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Mon, 14 Oct 2019 22:27:23 +0800 Subject: [PATCH 01/13] feat grpc proxy doc && test case --- .travis/linux_runner.sh | 33 +++++++++++++++++++++++--- .travis/osx_runner.sh | 21 +++++++++++++++++ doc/grpc-proxy-cn.md | 52 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 doc/grpc-proxy-cn.md diff --git a/.travis/linux_runner.sh b/.travis/linux_runner.sh index bf1dfeb74e3a..59874a4c5ba7 100755 --- a/.travis/linux_runner.sh +++ b/.travis/linux_runner.sh @@ -17,7 +17,7 @@ export_or_prefix() { } create_lua_deps() { - WITHOUT_DASHBOARD=1 sudo luarocks make --lua-dir=${OPENRESTY_PREFIX}/luajit rockspec/apisix-dev-1.0-0.rockspec --tree=deps --only-deps --local + sudo luarocks make --lua-dir=${OPENRESTY_PREFIX}/luajit rockspec/apisix-dev-1.0-0.rockspec --tree=deps --only-deps --local sudo luarocks install --lua-dir=${OPENRESTY_PREFIX}/luajit lua-resty-libr3 --tree=deps --local echo "Create lua deps cache" sudo rm -rf build-cache/deps @@ -66,15 +66,22 @@ do_install() { ls -l ./ if [ ! -f "build-cache/grpc_server_example" ]; then sudo apt-get install golang - git clone https://github.com/iresty/grpc_server_example.git grpc_server_example - cd grpc_server_example/ go build -o grpc_server_example main.go mv grpc_server_example ../build-cache/ + mv proto/ ../build-cache/ cd .. fi + if [ ! -f "build-cache/grpcurl" ]; then + sudo apt-get install golang + git clone https://github.com/fullstorydev/grpcurl.git grpcurl + cd grpcurl + go build -o grpcurl ./cmd/grpcurl + mv grpcurl ../build-cache/ + cd .. + fi } script() { @@ -91,10 +98,30 @@ script() { ./bin/apisix start mkdir -p logs sleep 1 + + #test grpc proxy + curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d ' + { + "methods": ["POST", "GET"], + "uri": "/helloworld.Greeter/SayHello", + "service_protocol": "grpc", + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:50051": 1 + } + } + }' + + ./build-cache/grpcurl -insecure -import-path ./build-cache/proto -proto helloworld.proto -d '{"name":"apisix"}' 127.0.0.1:9443 helloworld.Greeter.SayHello + + sleep 1 + ./bin/apisix stop sleep 1 make check || exit 1 APISIX_ENABLE_LUACOV=1 prove -Itest-nginx/lib -r t + } after_success() { diff --git a/.travis/osx_runner.sh b/.travis/osx_runner.sh index 4cf7dad9db75..2179ba7e94be 100755 --- a/.travis/osx_runner.sh +++ b/.travis/osx_runner.sh @@ -44,6 +44,8 @@ do_install() { cd grpc_server_example/ go build -o grpc_server_example main.go cd .. + + brew install grpcurl } script() { @@ -64,6 +66,25 @@ script() { sudo make run mkdir -p logs sleep 1 + + #test grpc proxy + curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d ' + { + "methods": ["POST", "GET"], + "uri": "/helloworld.Greeter/SayHello", + "service_protocol": "grpc", + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:50051": 1 + } + } + }' + + grpcurl -insecure -import-path ./grpc_server_example/proto -proto helloworld.proto -d '{"name":"apisix"}' 127.0.0.1:9443 helloworld.Greeter.SayHello + + sleep 1 + sudo make stop sleep 1 diff --git a/doc/grpc-proxy-cn.md b/doc/grpc-proxy-cn.md new file mode 100644 index 000000000000..41d5b28dc63f --- /dev/null +++ b/doc/grpc-proxy-cn.md @@ -0,0 +1,52 @@ +[English](grpc-proxy.md) +# grpc-proxy + +通过apisix代理grpc连接,并使用apisix的大部分特性管理你的grpc服务。 + + + +### 参数 + +* `service_protocol": "`: 这个 route 的属性`service_protocal` 必须设置为 `grpc` +* `uri`: 格式为 /service/method 如:/helloworld.Greeter/SayHello + + + +### 示例 + +#### 创建代理grpc的route + +在指定 route 中,代理 grpc 服务接口: + +* 注意: 这个 route 的属性`service_protocal` 必须设置为 `grpc` +* 例子所代理的 grpc 服务可参考:[grpc_server_example](https://github.com/nic-chen/grpc_server_example) + +```shell +curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d ' +{ + "methods": ["POST", "GET"], + "uri": "/helloworld.Greeter/SayHello", + "service_protocol": "grpc", + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:50051": 1 + } + } +}' +``` + + +#### 测试 + +访问上面配置的 route: + +```shell +$ grpcurl -insecure -import-path /pathtoprotos -proto helloworld.proto -d '{"name":"apisix"}' 127.0.0.1:9443 helloworld.Greeter.SayHello +{ + "message": "Hello apisix" +} +``` + +这表示已成功代理。 + From 2c546acea230faa3854cbedf93f028e1baeac874 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Mon, 14 Oct 2019 22:40:47 +0800 Subject: [PATCH 02/13] fix mv proto --- .travis/linux_runner.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.travis/linux_runner.sh b/.travis/linux_runner.sh index 59874a4c5ba7..b6be3b2ee288 100755 --- a/.travis/linux_runner.sh +++ b/.travis/linux_runner.sh @@ -70,6 +70,12 @@ do_install() { cd grpc_server_example/ go build -o grpc_server_example main.go mv grpc_server_example ../build-cache/ + cd .. + fi + + if [ ! -f "build-cache/proto/helloworld.proto" ]; then + git clone https://github.com/iresty/grpc_server_example.git grpc_server_example + cd grpc_server_example/ mv proto/ ../build-cache/ cd .. fi From 796a2fb1fcf667c830692708b5afc909c7dfd462 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Wed, 16 Oct 2019 21:21:22 +0800 Subject: [PATCH 03/13] feat: add english doc --- doc/grpc-proxy.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 doc/grpc-proxy.md diff --git a/doc/grpc-proxy.md b/doc/grpc-proxy.md new file mode 100644 index 000000000000..783bb375142f --- /dev/null +++ b/doc/grpc-proxy.md @@ -0,0 +1,51 @@ +[中文](grpc-proxy-cn.md) +# grpc-proxy + +proxying gRPC traffic: +gRPC client -> APISIX -> gRPC server + +### Parameters + +* `service_protocol": "`: the route's option `service_protocal` must be `grpc` +* `uri`: format likes /service/method , Example:/helloworld.Greeter/SayHello + + + +### Example + +#### create proxying gRPC route + +Here's an example, to proxying gRPC service by specified route: + +* attention: the route's option `service_protocal` must be `grpc` +* the grpc server example:[grpc_server_example](https://github.com/nic-chen/grpc_server_example) + +```shell +curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d ' +{ + "methods": ["POST", "GET"], + "uri": "/helloworld.Greeter/SayHello", + "service_protocol": "grpc", + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:50051": 1 + } + } +}' +``` + + +#### testing + +Invoking the route created before: + +```shell +$ grpcurl -insecure -import-path /pathtoprotos -proto helloworld.proto -d '{"name":"apisix"}' 127.0.0.1:9443 helloworld.Greeter.SayHello +{ + "message": "Hello apisix" +} +``` + +This means that the proxying is working. + From 1737e2a067255e6208434dc99500b1e03dbb9b01 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Wed, 16 Oct 2019 21:24:32 +0800 Subject: [PATCH 04/13] feat: add doc gRPC proxy doc link --- README.md | 1 + README_CN.md | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 464ee138f08c..638b10839cd1 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ For more detailed information, see the [White Paper](https://www.iresty.com/down - **[Proxy Rewrite](doc/plugins/proxy-rewrite.md)**: Support for rewriting the `host`, `uri`, `schema`, `enable_websocket`, `headers` information upstream of the request. - **OpenTracing: [support Apache Skywalking and Zipkin](doc/plugins/zipkin.md)** - **Monitoring And Metrics**: [Prometheus](doc/plugins/prometheus.md) +- **[gRPC proxy](doc/grpc-proxy.md)**:Proxying gRPC traffic. - **[gRPC transcoding](doc/plugins/grpc-transcoding.md)**:Supports protocol transcoding so that clients can access your gRPC API by using HTTP/JSON. - **[Serverless](doc/plugins/serverless.md)**: Invoke functions in each phase in APISIX. - **Custom plugins**: Allows hooking of common phases, such as `rewrite`, `access`, `header filer`, `body filter` and `log`, also allows to hook the `balancer` stage. diff --git a/README_CN.md b/README_CN.md index 8fbb52e67733..6111ae215775 100644 --- a/README_CN.md +++ b/README_CN.md @@ -42,6 +42,7 @@ APISIX 通过插件机制,提供动态负载平衡、身份验证、限流限 - **[代理请求重写](doc/plugins/proxy-rewrite.md)**: 支持重写请求上游的`host`、`uri`、`schema`、`enable_websocket`、`headers`信息。 - **OpenTracing: [支持 Apache Skywalking 和 Zipkin](doc/plugins/zipkin.md)** - **监控和指标**: [Prometheus](doc/plugins/prometheus-cn.md) +- **[gRPC 代理](doc/grpc-proxy-cn.md)**:通过apisix代理grpc连接,并使用apisix的大部分特性管理你的grpc服务。 - **[gRPC 协议转换](doc/plugins/grpc-transcoding-cn.md)**:支持协议的转换,这样客户端可以通过 HTTP/JSON 来访问你的 gRPC API。 - **[Serverless](doc/plugins/serverless-cn.md)**: 在 APISIX 的每一个阶段,你都可以添加并调用自己编写的函数。 - **自定义插件**: 允许挂载常见阶段,例如`rewrite`,`access`,`header filer`,`body filter`和`log`,还允许挂载 `balancer` 阶段。 From 22f371961abcec6eb75dbf275f305f0f0ff3f6fd Mon Sep 17 00:00:00 2001 From: nic-chen Date: Wed, 16 Oct 2019 21:33:30 +0800 Subject: [PATCH 05/13] fix: typo --- README_CN.md | 2 +- doc/grpc-proxy-cn.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README_CN.md b/README_CN.md index 6111ae215775..6a7f00c16516 100644 --- a/README_CN.md +++ b/README_CN.md @@ -42,7 +42,7 @@ APISIX 通过插件机制,提供动态负载平衡、身份验证、限流限 - **[代理请求重写](doc/plugins/proxy-rewrite.md)**: 支持重写请求上游的`host`、`uri`、`schema`、`enable_websocket`、`headers`信息。 - **OpenTracing: [支持 Apache Skywalking 和 Zipkin](doc/plugins/zipkin.md)** - **监控和指标**: [Prometheus](doc/plugins/prometheus-cn.md) -- **[gRPC 代理](doc/grpc-proxy-cn.md)**:通过apisix代理grpc连接,并使用apisix的大部分特性管理你的grpc服务。 +- **[gRPC 代理](doc/grpc-proxy-cn.md)**:通过APISIX代理grpc连接,并使用APISIX的大部分特性管理你的gRPC服务。 - **[gRPC 协议转换](doc/plugins/grpc-transcoding-cn.md)**:支持协议的转换,这样客户端可以通过 HTTP/JSON 来访问你的 gRPC API。 - **[Serverless](doc/plugins/serverless-cn.md)**: 在 APISIX 的每一个阶段,你都可以添加并调用自己编写的函数。 - **自定义插件**: 允许挂载常见阶段,例如`rewrite`,`access`,`header filer`,`body filter`和`log`,还允许挂载 `balancer` 阶段。 diff --git a/doc/grpc-proxy-cn.md b/doc/grpc-proxy-cn.md index 41d5b28dc63f..cd07b377711d 100644 --- a/doc/grpc-proxy-cn.md +++ b/doc/grpc-proxy-cn.md @@ -1,7 +1,7 @@ [English](grpc-proxy.md) # grpc-proxy -通过apisix代理grpc连接,并使用apisix的大部分特性管理你的grpc服务。 +通过APISIX代理gRPC连接,并使用APISIX的大部分特性管理你的grpc服务。 @@ -16,10 +16,10 @@ #### 创建代理grpc的route -在指定 route 中,代理 grpc 服务接口: +在指定 route 中,代理 gRPC 服务接口: * 注意: 这个 route 的属性`service_protocal` 必须设置为 `grpc` -* 例子所代理的 grpc 服务可参考:[grpc_server_example](https://github.com/nic-chen/grpc_server_example) +* 例子所代理的 gRPC 服务可参考:[grpc_server_example](https://github.com/nic-chen/grpc_server_example) ```shell curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d ' From 623ec91b7ab29895715fbf76d0b931b4c9002576 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Sat, 26 Oct 2019 21:55:20 +0800 Subject: [PATCH 06/13] doc: optimize grpc proxy doc --- doc/admin-api-cn.md | 2 +- doc/grpc-proxy-cn.md | 1 + doc/grpc-proxy.md | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/admin-api-cn.md b/doc/admin-api-cn.md index fd065dc48afe..8ef8b13797b1 100644 --- a/doc/admin-api-cn.md +++ b/doc/admin-api-cn.md @@ -38,7 +38,7 @@ |upstream |可选 |Upstream|启用的 Upstream 配置,详见 [Upstream](architecture-design-cn.md#upstream)|| |upstream_id|可选 |Upstream|启用的 upstream id,详见 [Upstream](architecture-design-cn.md#upstream)|| |service_id|可选 |Service|绑定的 Service 配置,详见 [Service](architecture-design-cn.md#service)|| -|service_protocol|可选|上游协议类型|只可以是 "grpc", "http" 二选一。|默认 "http"| +|service_protocol|可选|上游协议类型|只可以是 "grpc", "http" 二选一。|默认 "http",使用gRPC proxy 或gRPC transcode 时,必须用"grpc"| 对于同一类参数比如 `host` 与 `hosts`,`remote_addr` 与 `remote_addrs`,是不能同时存在,二者只能选择其一。如果同时启用,接口会报错。 diff --git a/doc/grpc-proxy-cn.md b/doc/grpc-proxy-cn.md index cd07b377711d..821b78880268 100644 --- a/doc/grpc-proxy-cn.md +++ b/doc/grpc-proxy-cn.md @@ -19,6 +19,7 @@ 在指定 route 中,代理 gRPC 服务接口: * 注意: 这个 route 的属性`service_protocal` 必须设置为 `grpc` +* 注意: APISIX 使用TLS加密的HTTP/2暴露gRPC服务, 所以需要先[配置SSL证书](https://github.com/iresty/apisix/blob/master/doc/https-cn.md) * 例子所代理的 gRPC 服务可参考:[grpc_server_example](https://github.com/nic-chen/grpc_server_example) ```shell diff --git a/doc/grpc-proxy.md b/doc/grpc-proxy.md index 783bb375142f..4e6eb70bcda5 100644 --- a/doc/grpc-proxy.md +++ b/doc/grpc-proxy.md @@ -6,7 +6,7 @@ gRPC client -> APISIX -> gRPC server ### Parameters -* `service_protocol": "`: the route's option `service_protocal` must be `grpc` +* `service_protocol`: the route's option `service_protocal` must be `grpc` * `uri`: format likes /service/method , Example:/helloworld.Greeter/SayHello @@ -18,6 +18,7 @@ gRPC client -> APISIX -> gRPC server Here's an example, to proxying gRPC service by specified route: * attention: the route's option `service_protocal` must be `grpc` +* attention: APISIX use TLS‑encrypted HTTP/2 to expose gRPC service, so need to [config SSL certificate](https://github.com/iresty/apisix/blob/master/doc/https.md) * the grpc server example:[grpc_server_example](https://github.com/nic-chen/grpc_server_example) ```shell From b1cc7725055d853bdaa265273feb56add3b37631 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Mon, 14 Oct 2019 22:27:23 +0800 Subject: [PATCH 07/13] feat grpc proxy doc && test case --- .travis/linux_runner.sh | 33 ++++++++++++++++++++++++-- .travis/osx_runner.sh | 21 +++++++++++++++++ doc/grpc-proxy-cn.md | 52 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 doc/grpc-proxy-cn.md diff --git a/.travis/linux_runner.sh b/.travis/linux_runner.sh index 57aa4ff09cdb..db5b3cbe03f2 100755 --- a/.travis/linux_runner.sh +++ b/.travis/linux_runner.sh @@ -18,6 +18,8 @@ export_or_prefix() { create_lua_deps() { WITHOUT_DASHBOARD=1 sudo luarocks make --lua-dir=${OPENRESTY_PREFIX}/luajit rockspec/apisix-master-0.rockspec --tree=deps --only-deps --local + sudo luarocks make --lua-dir=${OPENRESTY_PREFIX}/luajit rockspec/apisix-dev-1.0-0.rockspec --tree=deps --only-deps --local + sudo luarocks install --lua-dir=${OPENRESTY_PREFIX}/luajit lua-resty-libr3 --tree=deps --local echo "Create lua deps cache" sudo rm -rf build-cache/deps sudo cp -r deps build-cache/ @@ -65,15 +67,22 @@ do_install() { ls -l ./ if [ ! -f "build-cache/grpc_server_example" ]; then sudo apt-get install golang - git clone https://github.com/iresty/grpc_server_example.git grpc_server_example - cd grpc_server_example/ go build -o grpc_server_example main.go mv grpc_server_example ../build-cache/ + mv proto/ ../build-cache/ cd .. fi + if [ ! -f "build-cache/grpcurl" ]; then + sudo apt-get install golang + git clone https://github.com/fullstorydev/grpcurl.git grpcurl + cd grpcurl + go build -o grpcurl ./cmd/grpcurl + mv grpcurl ../build-cache/ + cd .. + fi } script() { @@ -90,10 +99,30 @@ script() { ./bin/apisix start mkdir -p logs sleep 1 + + #test grpc proxy + curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d ' + { + "methods": ["POST", "GET"], + "uri": "/helloworld.Greeter/SayHello", + "service_protocol": "grpc", + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:50051": 1 + } + } + }' + + ./build-cache/grpcurl -insecure -import-path ./build-cache/proto -proto helloworld.proto -d '{"name":"apisix"}' 127.0.0.1:9443 helloworld.Greeter.SayHello + + sleep 1 + ./bin/apisix stop sleep 1 make check || exit 1 APISIX_ENABLE_LUACOV=1 prove -Itest-nginx/lib -r t + } after_success() { diff --git a/.travis/osx_runner.sh b/.travis/osx_runner.sh index 699c4c05de53..fe53fe3d3f6b 100755 --- a/.travis/osx_runner.sh +++ b/.travis/osx_runner.sh @@ -43,6 +43,8 @@ do_install() { cd grpc_server_example/ go build -o grpc_server_example main.go cd .. + + brew install grpcurl } script() { @@ -63,6 +65,25 @@ script() { sudo make run mkdir -p logs sleep 1 + + #test grpc proxy + curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d ' + { + "methods": ["POST", "GET"], + "uri": "/helloworld.Greeter/SayHello", + "service_protocol": "grpc", + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:50051": 1 + } + } + }' + + grpcurl -insecure -import-path ./grpc_server_example/proto -proto helloworld.proto -d '{"name":"apisix"}' 127.0.0.1:9443 helloworld.Greeter.SayHello + + sleep 1 + sudo make stop sleep 1 diff --git a/doc/grpc-proxy-cn.md b/doc/grpc-proxy-cn.md new file mode 100644 index 000000000000..41d5b28dc63f --- /dev/null +++ b/doc/grpc-proxy-cn.md @@ -0,0 +1,52 @@ +[English](grpc-proxy.md) +# grpc-proxy + +通过apisix代理grpc连接,并使用apisix的大部分特性管理你的grpc服务。 + + + +### 参数 + +* `service_protocol": "`: 这个 route 的属性`service_protocal` 必须设置为 `grpc` +* `uri`: 格式为 /service/method 如:/helloworld.Greeter/SayHello + + + +### 示例 + +#### 创建代理grpc的route + +在指定 route 中,代理 grpc 服务接口: + +* 注意: 这个 route 的属性`service_protocal` 必须设置为 `grpc` +* 例子所代理的 grpc 服务可参考:[grpc_server_example](https://github.com/nic-chen/grpc_server_example) + +```shell +curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d ' +{ + "methods": ["POST", "GET"], + "uri": "/helloworld.Greeter/SayHello", + "service_protocol": "grpc", + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:50051": 1 + } + } +}' +``` + + +#### 测试 + +访问上面配置的 route: + +```shell +$ grpcurl -insecure -import-path /pathtoprotos -proto helloworld.proto -d '{"name":"apisix"}' 127.0.0.1:9443 helloworld.Greeter.SayHello +{ + "message": "Hello apisix" +} +``` + +这表示已成功代理。 + From 4c0c866317de1cfebb26bf294eb09c4dfc0ab1a0 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Mon, 14 Oct 2019 22:40:47 +0800 Subject: [PATCH 08/13] fix mv proto --- .travis/linux_runner.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.travis/linux_runner.sh b/.travis/linux_runner.sh index db5b3cbe03f2..fe634c82767b 100755 --- a/.travis/linux_runner.sh +++ b/.travis/linux_runner.sh @@ -71,6 +71,12 @@ do_install() { cd grpc_server_example/ go build -o grpc_server_example main.go mv grpc_server_example ../build-cache/ + cd .. + fi + + if [ ! -f "build-cache/proto/helloworld.proto" ]; then + git clone https://github.com/iresty/grpc_server_example.git grpc_server_example + cd grpc_server_example/ mv proto/ ../build-cache/ cd .. fi From d77927f10ce75611a6f9413c6e89f436cfa43dda Mon Sep 17 00:00:00 2001 From: nic-chen Date: Wed, 16 Oct 2019 21:21:22 +0800 Subject: [PATCH 09/13] feat: add english doc --- doc/grpc-proxy.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 doc/grpc-proxy.md diff --git a/doc/grpc-proxy.md b/doc/grpc-proxy.md new file mode 100644 index 000000000000..783bb375142f --- /dev/null +++ b/doc/grpc-proxy.md @@ -0,0 +1,51 @@ +[中文](grpc-proxy-cn.md) +# grpc-proxy + +proxying gRPC traffic: +gRPC client -> APISIX -> gRPC server + +### Parameters + +* `service_protocol": "`: the route's option `service_protocal` must be `grpc` +* `uri`: format likes /service/method , Example:/helloworld.Greeter/SayHello + + + +### Example + +#### create proxying gRPC route + +Here's an example, to proxying gRPC service by specified route: + +* attention: the route's option `service_protocal` must be `grpc` +* the grpc server example:[grpc_server_example](https://github.com/nic-chen/grpc_server_example) + +```shell +curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d ' +{ + "methods": ["POST", "GET"], + "uri": "/helloworld.Greeter/SayHello", + "service_protocol": "grpc", + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:50051": 1 + } + } +}' +``` + + +#### testing + +Invoking the route created before: + +```shell +$ grpcurl -insecure -import-path /pathtoprotos -proto helloworld.proto -d '{"name":"apisix"}' 127.0.0.1:9443 helloworld.Greeter.SayHello +{ + "message": "Hello apisix" +} +``` + +This means that the proxying is working. + From 6e005400abfee87bda15aa446638c597d639926c Mon Sep 17 00:00:00 2001 From: nic-chen Date: Wed, 16 Oct 2019 21:24:32 +0800 Subject: [PATCH 10/13] feat: add doc gRPC proxy doc link --- README.md | 1 + README_CN.md | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 162c404047f4..402dbb25264d 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ For more detailed information, see the [White Paper](https://www.iresty.com/down - **[Proxy Rewrite](doc/plugins/proxy-rewrite.md)**: Support for rewriting the `host`, `uri`, `schema`, `enable_websocket`, `headers` information upstream of the request. - **OpenTracing: [support Apache Skywalking and Zipkin](doc/plugins/zipkin.md)** - **Monitoring And Metrics**: [Prometheus](doc/plugins/prometheus.md) +- **[gRPC proxy](doc/grpc-proxy.md)**:Proxying gRPC traffic. - **[gRPC transcoding](doc/plugins/grpc-transcoding.md)**:Supports protocol transcoding so that clients can access your gRPC API by using HTTP/JSON. - **[Serverless](doc/plugins/serverless.md)**: Invoke functions in each phase in APISIX. - **Custom plugins**: Allows hooking of common phases, such as `rewrite`, `access`, `header filer`, `body filter` and `log`, also allows to hook the `balancer` stage. diff --git a/README_CN.md b/README_CN.md index 0239df582a78..a1cb9e560a52 100644 --- a/README_CN.md +++ b/README_CN.md @@ -42,6 +42,7 @@ APISIX 通过插件机制,提供动态负载平衡、身份验证、限流限 - **[代理请求重写](doc/plugins/proxy-rewrite.md)**: 支持重写请求上游的`host`、`uri`、`schema`、`enable_websocket`、`headers`信息。 - **OpenTracing: [支持 Apache Skywalking 和 Zipkin](doc/plugins/zipkin.md)** - **监控和指标**: [Prometheus](doc/plugins/prometheus-cn.md) +- **[gRPC 代理](doc/grpc-proxy-cn.md)**:通过apisix代理grpc连接,并使用apisix的大部分特性管理你的grpc服务。 - **[gRPC 协议转换](doc/plugins/grpc-transcoding-cn.md)**:支持协议的转换,这样客户端可以通过 HTTP/JSON 来访问你的 gRPC API。 - **[Serverless](doc/plugins/serverless-cn.md)**: 在 APISIX 的每一个阶段,你都可以添加并调用自己编写的函数。 - **自定义插件**: 允许挂载常见阶段,例如`rewrite`,`access`,`header filer`,`body filter`和`log`,还允许挂载 `balancer` 阶段。 From db4b852d944ff6d06314f840fbaa34d4a6ff006a Mon Sep 17 00:00:00 2001 From: nic-chen Date: Wed, 16 Oct 2019 21:33:30 +0800 Subject: [PATCH 11/13] fix: typo --- README_CN.md | 2 +- doc/grpc-proxy-cn.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README_CN.md b/README_CN.md index a1cb9e560a52..09253c13512e 100644 --- a/README_CN.md +++ b/README_CN.md @@ -42,7 +42,7 @@ APISIX 通过插件机制,提供动态负载平衡、身份验证、限流限 - **[代理请求重写](doc/plugins/proxy-rewrite.md)**: 支持重写请求上游的`host`、`uri`、`schema`、`enable_websocket`、`headers`信息。 - **OpenTracing: [支持 Apache Skywalking 和 Zipkin](doc/plugins/zipkin.md)** - **监控和指标**: [Prometheus](doc/plugins/prometheus-cn.md) -- **[gRPC 代理](doc/grpc-proxy-cn.md)**:通过apisix代理grpc连接,并使用apisix的大部分特性管理你的grpc服务。 +- **[gRPC 代理](doc/grpc-proxy-cn.md)**:通过APISIX代理grpc连接,并使用APISIX的大部分特性管理你的gRPC服务。 - **[gRPC 协议转换](doc/plugins/grpc-transcoding-cn.md)**:支持协议的转换,这样客户端可以通过 HTTP/JSON 来访问你的 gRPC API。 - **[Serverless](doc/plugins/serverless-cn.md)**: 在 APISIX 的每一个阶段,你都可以添加并调用自己编写的函数。 - **自定义插件**: 允许挂载常见阶段,例如`rewrite`,`access`,`header filer`,`body filter`和`log`,还允许挂载 `balancer` 阶段。 diff --git a/doc/grpc-proxy-cn.md b/doc/grpc-proxy-cn.md index 41d5b28dc63f..cd07b377711d 100644 --- a/doc/grpc-proxy-cn.md +++ b/doc/grpc-proxy-cn.md @@ -1,7 +1,7 @@ [English](grpc-proxy.md) # grpc-proxy -通过apisix代理grpc连接,并使用apisix的大部分特性管理你的grpc服务。 +通过APISIX代理gRPC连接,并使用APISIX的大部分特性管理你的grpc服务。 @@ -16,10 +16,10 @@ #### 创建代理grpc的route -在指定 route 中,代理 grpc 服务接口: +在指定 route 中,代理 gRPC 服务接口: * 注意: 这个 route 的属性`service_protocal` 必须设置为 `grpc` -* 例子所代理的 grpc 服务可参考:[grpc_server_example](https://github.com/nic-chen/grpc_server_example) +* 例子所代理的 gRPC 服务可参考:[grpc_server_example](https://github.com/nic-chen/grpc_server_example) ```shell curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d ' From 6003f5bc17ba6fbd22376b9894c8f1f7ec8d4b51 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Sat, 26 Oct 2019 21:55:20 +0800 Subject: [PATCH 12/13] doc: optimize grpc proxy doc --- doc/admin-api-cn.md | 2 +- doc/grpc-proxy-cn.md | 1 + doc/grpc-proxy.md | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/admin-api-cn.md b/doc/admin-api-cn.md index fd065dc48afe..8ef8b13797b1 100644 --- a/doc/admin-api-cn.md +++ b/doc/admin-api-cn.md @@ -38,7 +38,7 @@ |upstream |可选 |Upstream|启用的 Upstream 配置,详见 [Upstream](architecture-design-cn.md#upstream)|| |upstream_id|可选 |Upstream|启用的 upstream id,详见 [Upstream](architecture-design-cn.md#upstream)|| |service_id|可选 |Service|绑定的 Service 配置,详见 [Service](architecture-design-cn.md#service)|| -|service_protocol|可选|上游协议类型|只可以是 "grpc", "http" 二选一。|默认 "http"| +|service_protocol|可选|上游协议类型|只可以是 "grpc", "http" 二选一。|默认 "http",使用gRPC proxy 或gRPC transcode 时,必须用"grpc"| 对于同一类参数比如 `host` 与 `hosts`,`remote_addr` 与 `remote_addrs`,是不能同时存在,二者只能选择其一。如果同时启用,接口会报错。 diff --git a/doc/grpc-proxy-cn.md b/doc/grpc-proxy-cn.md index cd07b377711d..821b78880268 100644 --- a/doc/grpc-proxy-cn.md +++ b/doc/grpc-proxy-cn.md @@ -19,6 +19,7 @@ 在指定 route 中,代理 gRPC 服务接口: * 注意: 这个 route 的属性`service_protocal` 必须设置为 `grpc` +* 注意: APISIX 使用TLS加密的HTTP/2暴露gRPC服务, 所以需要先[配置SSL证书](https://github.com/iresty/apisix/blob/master/doc/https-cn.md) * 例子所代理的 gRPC 服务可参考:[grpc_server_example](https://github.com/nic-chen/grpc_server_example) ```shell diff --git a/doc/grpc-proxy.md b/doc/grpc-proxy.md index 783bb375142f..4e6eb70bcda5 100644 --- a/doc/grpc-proxy.md +++ b/doc/grpc-proxy.md @@ -6,7 +6,7 @@ gRPC client -> APISIX -> gRPC server ### Parameters -* `service_protocol": "`: the route's option `service_protocal` must be `grpc` +* `service_protocol`: the route's option `service_protocal` must be `grpc` * `uri`: format likes /service/method , Example:/helloworld.Greeter/SayHello @@ -18,6 +18,7 @@ gRPC client -> APISIX -> gRPC server Here's an example, to proxying gRPC service by specified route: * attention: the route's option `service_protocal` must be `grpc` +* attention: APISIX use TLS‑encrypted HTTP/2 to expose gRPC service, so need to [config SSL certificate](https://github.com/iresty/apisix/blob/master/doc/https.md) * the grpc server example:[grpc_server_example](https://github.com/nic-chen/grpc_server_example) ```shell From d1695fe9210bdbb83b0f2ef24ccbaf746427eb06 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Sat, 26 Oct 2019 22:32:54 +0800 Subject: [PATCH 13/13] feat: separate grpc test case code --- .travis/linux_runner.sh | 27 +++++++-------------------- README_CN.md | 2 +- doc/grpc-proxy-cn.md | 6 +++--- t/grpc-proxy-test.sh | 17 +++++++++++++++++ 4 files changed, 28 insertions(+), 24 deletions(-) create mode 100644 t/grpc-proxy-test.sh diff --git a/.travis/linux_runner.sh b/.travis/linux_runner.sh index fe634c82767b..33571a95a505 100755 --- a/.travis/linux_runner.sh +++ b/.travis/linux_runner.sh @@ -18,8 +18,6 @@ export_or_prefix() { create_lua_deps() { WITHOUT_DASHBOARD=1 sudo luarocks make --lua-dir=${OPENRESTY_PREFIX}/luajit rockspec/apisix-master-0.rockspec --tree=deps --only-deps --local - sudo luarocks make --lua-dir=${OPENRESTY_PREFIX}/luajit rockspec/apisix-dev-1.0-0.rockspec --tree=deps --only-deps --local - sudo luarocks install --lua-dir=${OPENRESTY_PREFIX}/luajit lua-resty-libr3 --tree=deps --local echo "Create lua deps cache" sudo rm -rf build-cache/deps sudo cp -r deps build-cache/ @@ -75,7 +73,11 @@ do_install() { fi if [ ! -f "build-cache/proto/helloworld.proto" ]; then - git clone https://github.com/iresty/grpc_server_example.git grpc_server_example + + if [ ! -f "grpc_server_example/main.go" ]; then + git clone https://github.com/iresty/grpc_server_example.git grpc_server_example + fi + cd grpc_server_example/ mv proto/ ../build-cache/ cd .. @@ -106,29 +108,14 @@ script() { mkdir -p logs sleep 1 - #test grpc proxy - curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d ' - { - "methods": ["POST", "GET"], - "uri": "/helloworld.Greeter/SayHello", - "service_protocol": "grpc", - "upstream": { - "type": "roundrobin", - "nodes": { - "127.0.0.1:50051": 1 - } - } - }' - - ./build-cache/grpcurl -insecure -import-path ./build-cache/proto -proto helloworld.proto -d '{"name":"apisix"}' 127.0.0.1:9443 helloworld.Greeter.SayHello - + sudo sh ./t/grpc-proxy-test.sh sleep 1 ./bin/apisix stop sleep 1 + make check || exit 1 APISIX_ENABLE_LUACOV=1 prove -Itest-nginx/lib -r t - } after_success() { diff --git a/README_CN.md b/README_CN.md index 09253c13512e..2d3f62842c7b 100644 --- a/README_CN.md +++ b/README_CN.md @@ -42,7 +42,7 @@ APISIX 通过插件机制,提供动态负载平衡、身份验证、限流限 - **[代理请求重写](doc/plugins/proxy-rewrite.md)**: 支持重写请求上游的`host`、`uri`、`schema`、`enable_websocket`、`headers`信息。 - **OpenTracing: [支持 Apache Skywalking 和 Zipkin](doc/plugins/zipkin.md)** - **监控和指标**: [Prometheus](doc/plugins/prometheus-cn.md) -- **[gRPC 代理](doc/grpc-proxy-cn.md)**:通过APISIX代理grpc连接,并使用APISIX的大部分特性管理你的gRPC服务。 +- **[gRPC 代理](doc/grpc-proxy-cn.md)**:通过 APISIX 代理 gRPC 连接,并使用 APISIX 的大部分特性管理你的 gRPC 服务。 - **[gRPC 协议转换](doc/plugins/grpc-transcoding-cn.md)**:支持协议的转换,这样客户端可以通过 HTTP/JSON 来访问你的 gRPC API。 - **[Serverless](doc/plugins/serverless-cn.md)**: 在 APISIX 的每一个阶段,你都可以添加并调用自己编写的函数。 - **自定义插件**: 允许挂载常见阶段,例如`rewrite`,`access`,`header filer`,`body filter`和`log`,还允许挂载 `balancer` 阶段。 diff --git a/doc/grpc-proxy-cn.md b/doc/grpc-proxy-cn.md index 821b78880268..6bbf9043359c 100644 --- a/doc/grpc-proxy-cn.md +++ b/doc/grpc-proxy-cn.md @@ -7,7 +7,7 @@ ### 参数 -* `service_protocol": "`: 这个 route 的属性`service_protocal` 必须设置为 `grpc` +* `service_protocol`: 这个 route 的属性 `service_protocal` 必须设置为 `grpc` * `uri`: 格式为 /service/method 如:/helloworld.Greeter/SayHello @@ -18,8 +18,8 @@ 在指定 route 中,代理 gRPC 服务接口: -* 注意: 这个 route 的属性`service_protocal` 必须设置为 `grpc` -* 注意: APISIX 使用TLS加密的HTTP/2暴露gRPC服务, 所以需要先[配置SSL证书](https://github.com/iresty/apisix/blob/master/doc/https-cn.md) +* 注意: 这个 route 的属性 `service_protocal` 必须设置为 `grpc` +* 注意: APISIX 使用 TLS 加密的 HTTP/2 暴露 gRPC 服务, 所以需要先[配置 SSL 证书](https://github.com/iresty/apisix/blob/master/doc/https-cn.md) * 例子所代理的 gRPC 服务可参考:[grpc_server_example](https://github.com/nic-chen/grpc_server_example) ```shell diff --git a/t/grpc-proxy-test.sh b/t/grpc-proxy-test.sh new file mode 100644 index 000000000000..62470aa4cb1e --- /dev/null +++ b/t/grpc-proxy-test.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +#test grpc proxy +curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d ' +{ + "methods": ["POST"], + "uri": "/helloworld.Greeter/SayHello", + "service_protocol": "grpc", + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:50051": 1 + } + } +}' + +./build-cache/grpcurl -insecure -import-path ./build-cache/proto -proto helloworld.proto -d '{"name":"apisix"}' 127.0.0.1:9443 helloworld.Greeter.SayHello