Skip to content

Commit

Permalink
proxy: add check api
Browse files Browse the repository at this point in the history
  • Loading branch information
jarviszeng-zjc committed Dec 8, 2020
1 parent d146e9f commit 1142b7a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 14 deletions.
26 changes: 20 additions & 6 deletions c/proxy/conf/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ http {
}

server {
listen 9390 http2;
server_name grpc_proxy;
listen 9300;
server_name http_proxy;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
access_by_lua_file 'lua/router.lua';
grpc_pass grpc://grpc_cluster;
proxy_pass http://http_cluster;
}

#error_page 404 /404.html;
Expand All @@ -71,16 +71,16 @@ http {
}

server {
listen 9330;
server_name http_proxy;
listen 9390 http2;
server_name grpc_proxy;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
access_by_lua_file 'lua/router.lua';
proxy_pass http://http_cluster;
grpc_pass grpc://grpc_cluster;
}

#error_page 404 /404.html;
Expand All @@ -92,4 +92,18 @@ http {
root html;
}
}

server {
listen 9302;
server_name test_proxy;

location /test {
content_by_lua_file 'lua/check.lua';
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
12 changes: 8 additions & 4 deletions c/proxy/conf/route_table.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
default:
proxy:
- host: 127.0.0.1
port: 9373
port: 9390
local:
test_proxy:
- host: 127.0.0.1
port: 9302
9999:
proxy:
- host: 127.0.0.1
port: 9373
port: 9390
fateflow:
- host: 127.0.0.1
port: 9360
10000:
proxy:
- host: 127.0.0.1
port: 9373
port: 9390
fateflow:
- host: 127.0.0.1
port: 9362
port: 9360
29 changes: 29 additions & 0 deletions c/proxy/lua/check.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--
-- Copyright 2019 The FATE Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
local _M = {
_VERSION = '0.1'
}

local ngx = ngx
local math = require "math"
local string = require "string"

local function check()
ngx.say("ok")
end

check()

8 changes: 4 additions & 4 deletions c/proxy/lua/router.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ local function get_dest_server(dest_env, dest_service)
end

local route = route_table.get_route()
local party_services = route:get(dest_env)
local env_services = route:get(dest_env)
local server
if party_services ~= nil then
local service = party_services[dest_service]
if env_services ~= nil then
local service = env_services[dest_service]
server = get_server_address(service[math.random(1, #service)])
ngx.log(ngx.INFO, string.format("get %s %s server: %s", dest_env, dest_service, server))
else
Expand All @@ -54,7 +54,7 @@ local function get_request_dest()
return headers
end

function routing()
local function routing()
local request_headers = get_request_dest()
local dest_env = request_headers["dest-party-id"]
if dest_env == nil then
Expand Down

0 comments on commit 1142b7a

Please sign in to comment.