fagongzi / manba Goto Github PK
View Code? Open in Web Editor NEWHTTP API Gateway
License: Apache License 2.0
HTTP API Gateway
License: Apache License 2.0
启动 proxy 或 admin 都会报错 proxy flag redefined: crash,
我现在是将log注释掉才能运行,请问是我什么原因呢?
我在启动admin服务的时候,出现一个 panic: runtime error: invalid memory address or nil pointer dereference,位置是
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x154f4bd]goroutine 1 [running]:
github.com/fagongzi/gateway/cmd/admin/pkg/server.NewAdminServer(0x7fff5fbffa64, 0x5, 0x7fff5fbffa7a, 0x15, 0x7fff5fbffa99, 0x3, 0x16b1d8b, 0x5, 0x16b1d8b, 0x5, ...)
/src/github.com/fagongzi/gateway/cmd/admin/pkg/server/server.go:32 +0x6d
main.main()
/src/github.com/fagongzi/gateway/cmd/admin/admin.go:29 +0x182
有UI配置页面嘛?
这个项目的Dockerfile文件里面能配置一个支持consul的吗?谢谢啊。
当底层服务挂掉后,health check时间间隔会不断增长,最终变得无限大,此时若服务恢复,也不能及时检测到。所以需要一个间隔时间的天花板值,使得某服务down掉很长时间后恢复,gateway也能快速检测到并提供服务。
期望能在分钟级检测到服务恢复,所以建议天花板值能否设置在60s?
譬如合并10个后端接口,这个10个接口内容我只需要几个字段输出给前端就行,且能做一些简单的字段值转换。譬如时间戳转换为时间字符串格式(2017-8-25 11:11:11 ) ,这样做的 目的可以屏蔽一些冗余的字段内容输出节省前端流量,在一定程度上也简化了 输出接口的字段结构复杂度。
Hola! @iodone has created a ZenHub account for the fagongzi organization. ZenHub is the only project management tool integrated natively in GitHub – created specifically for fast-moving, software-driven teams.
To get set up with ZenHub, all you have to do is download the browser extension and log in with your GitHub account. Once you do, you’ll get access to ZenHub’s complete feature-set immediately.
ZenHub adds a series of enhancements directly inside the GitHub UI:
Still curious? See more ZenHub features or read user reviews. This issue was written by your friendly ZenHub bot, posted by request from @iodone.
admin创建api时没有Domain参数, 判断api.match时会判断Domain
无法启动 proxy 服务
提示如下信息,已经验证过 127.0.0.1:2379 服务是可以正常put get的。
2017/06/24 22:29:06 proxy.go:64: [PANIC] init etcd store error
[error]: not support: etcd://127.0.0.1:2379
[stack]:
2 /src/github.com/fagongzi/gateway/proxy/proxy.go:64
github.com/fagongzi/gateway/proxy.(*Proxy).init
1 /src/github.com/fagongzi/gateway/proxy/proxy.go:56
github.com/fagongzi/gateway/proxy.NewProxy
0 /src/github.com/fagongzi/gateway/cmd/proxy/proxy.go:56
main.main
请问routings板块该怎么去定义路由?这个的作用是什么?
Consul与etcd比较起来是不是会更有优势呢?
能写点例子吗?能更好让其他人员上手!
通过Restful API添加API后请求网关代理会导致网关无法提供服务。进程并没有退出,只是无法响应请求,使用Ctrl+c
退出程序发现长时间卡住。
复现步骤:
1、添加API并使用API聚合功能,配置renderTemplate
2、使用下面的数据模版配置,即flatAttrs为false时,同级的name为空
3、发起API请求
"renderTemplate":{
"objects":[
{
"name":"",
"attrs":[
{
"name":"store",
"extractExp":"store.result"
},
{
"name":"store_v2",
"extractExp":"store_v2.data"
}
],
"flatAttrs":false
},
{
"name": "",
"attrs": [
{
"name": "code",
"extractExp": "store_v2.code"
}
],
"flatAttrs":true
}
]
}
日志
2018/04/28 11:50:35.827528 [info] filter: 127.0.0.1 GET "/api/v2/stores/d03bac5c-cd8e-43ab-b641-234978ba4693" 200 "curl/7.54.0" 127.0.0.1:3000 249.968512ms
2018/04/28 11:50:35 panic: runtime error: index out of range
Stack trace:
goroutine 329 [running]:
runtime/debug.Stack(0xc4204d3658, 0x461e960, 0x4ab7410)
/usr/local/Cellar/go/1.10/libexec/src/runtime/debug/stack.go:24 +0xa7
github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp.(*workerPool).workerFunc.func1(0xc42016d080, 0xc4204d3f68)
/Users/weihl/GoPath/src/github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp/workerpool.go:207 +0x88
panic(0x461e960, 0x4ab7410)
/usr/local/Cellar/go/1.10/libexec/src/runtime/panic.go:505 +0x229
github.com/fagongzi/gateway/vendor/github.com/buger/jsonparser.createInsertComponent(0xc4204d39b8, 0x1, 0x1, 0xc4202fd653, 0x1, 0x9ad, 0x0, 0x0, 0x0, 0x0)
/Users/weihl/GoPath/src/github.com/fagongzi/gateway/vendor/github.com/buger/jsonparser/parser.go:566 +0x499
github.com/fagongzi/gateway/vendor/github.com/buger/jsonparser.Set(0x4a7d20e, 0x2, 0x2, 0xc4202fd653, 0x1, 0x9ad, 0xc4204d39b8, 0x1, 0x1, 0x0, ...)
/Users/weihl/GoPath/src/github.com/fagongzi/gateway/vendor/github.com/buger/jsonparser/parser.go:753 +0x373
github.com/fagongzi/gateway/pkg/proxy.(*render).extract(0xc420498480, 0xc4202fd000, 0xbcc, 0x1000, 0x435cfa1, 0x4acbab0, 0x46dc5a0, 0xc4202fa5a0, 0xc4204d3a40)
/Users/weihl/GoPath/src/github.com/fagongzi/gateway/pkg/proxy/render.go:193 +0x2f9
github.com/fagongzi/gateway/pkg/proxy.(*render).renderTemplate(0xc420498480, 0xc420442000, 0xc4202fd000, 0xbcc, 0x1000)
/Users/weihl/GoPath/src/github.com/fagongzi/gateway/pkg/proxy/render.go:158 +0x53
github.com/fagongzi/gateway/pkg/proxy.(*render).renderMulti(0xc420498480, 0xc420442000)
/Users/weihl/GoPath/src/github.com/fagongzi/gateway/pkg/proxy/render.go:125 +0x333
github.com/fagongzi/gateway/pkg/proxy.(*render).(github.com/fagongzi/gateway/pkg/proxy.renderMulti)-fm(0xc420442000)
/Users/weihl/GoPath/src/github.com/fagongzi/gateway/pkg/proxy/render.go:30 +0x34
github.com/fagongzi/gateway/pkg/proxy.(*render).render(0xc420498480, 0xc420442000, 0xc42017bce0)
/Users/weihl/GoPath/src/github.com/fagongzi/gateway/pkg/proxy/render.go:47 +0x118
github.com/fagongzi/gateway/pkg/proxy.(*Proxy).ReverseProxyHandler(0xc4201762a0, 0xc420442000)
/Users/weihl/GoPath/src/github.com/fagongzi/gateway/pkg/proxy/proxy.go:320 +0x75b
github.com/fagongzi/gateway/pkg/proxy.(*Proxy).ReverseProxyHandler-fm(0xc420442000)
/Users/weihl/GoPath/src/github.com/fagongzi/gateway/pkg/proxy/proxy.go:102 +0x34
github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp.(*Server).serveConn(0xc420348f00, 0x47710e0, 0xc420164010, 0x1, 0xc420250101)
/Users/weihl/GoPath/src/github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp/server.go:1494 +0x611
github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp.(*Server).(github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp.serveConn)-fm(0x47710e0, 0xc420164010, 0xc42016d001, 0xc42025af68)
/Users/weihl/GoPath/src/github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp/server.go:1223 +0x3e
github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp.(*workerPool).workerFunc(0xc42016d080, 0xc420244c60)
/Users/weihl/GoPath/src/github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp/workerpool.go:224 +0x117
github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp.(*workerPool).getCh.func1(0xc42016d080, 0xc420244c60, 0x45c1b20, 0xc420244c60)
/Users/weihl/GoPath/src/github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp/workerpool.go:183 +0x35
created by github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp.(*workerPool).getCh
/Users/weihl/GoPath/src/github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp/workerpool.go:182 +0x119
2018/05/30 03:30:54.938525 [warning] server <%!s(uint64=1001)> change to close
2018/05/30 03:30:54 panic: runtime error: invalid memory address or nil pointer dereference
Stack trace:
goroutine 487 [running]:
runtime/debug.Stack(0xc420615638, 0xa14580, 0xea81a0)
/usr/local/Cellar/go/1.10/libexec/src/runtime/debug/stack.go:24 +0xa7
github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp.(*workerPool).workerFunc.func1(0xc420320480, 0xc420615f68)
/GoPath/src/github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp/workerpool.go:207 +0x88
panic(0xa14580, 0xea81a0)
/usr/local/Cellar/go/1.10/libexec/src/runtime/panic.go:505 +0x229
github.com/fagongzi/gateway/vendor/github.com/fagongzi/goetty.(*TimeoutWheel).Schedule(0x0, 0x2540be400, 0xc4202f4410, 0x0, 0x0, 0xc420615828, 0x94b123, 0xc420190990, 0x3e9)
/GoPath/src/github.com/fagongzi/gateway/vendor/github.com/fagongzi/goetty/timewheel.go:248 +0x26
github.com/fagongzi/gateway/pkg/proxy.(*serverRuntime).circuitToClose(0xc420475cc0)
/GoPath/src/github.com/fagongzi/gateway/pkg/proxy/runtime.go:153 +0x117
github.com/fagongzi/gateway/pkg/proxy.(*proxyContext).changeCircuitStatusToClose(0xc4204b51a0)
/GoPath/src/github.com/fagongzi/gateway/pkg/proxy/filter.go:139 +0x33
github.com/fagongzi/gateway/pkg/proxy.(*CircuitBreakeFilter).Pre(0xedc170, 0xb66560, 0xc4204b51a0, 0xc8, 0x0, 0x0)
/GoPath/src/github.com/fagongzi/gateway/pkg/proxy/filter_circuit_breaker.go:58 +0x143
github.com/fagongzi/gateway/pkg/proxy.(*Proxy).doPreFilters(0xc4201e62a0, 0xb66560, 0xc4204b51a0, 0xc4201df080, 0xc42035a360, 0x6, 0x0, 0x0)
/GoPath/src/github.com/fagongzi/gateway/pkg/proxy/filter.go:17 +0xbe
github.com/fagongzi/gateway/pkg/proxy.(*Proxy).doProxy(0xc4201e62a0, 0xc42035a360)
/GoPath/src/github.com/fagongzi/gateway/pkg/proxy/proxy.go:400 +0x1b1
github.com/fagongzi/gateway/pkg/proxy.(*Proxy).ReverseProxyHandler(0xc4201e62a0, 0xc420538000)
/GoPath/src/github.com/fagongzi/gateway/pkg/proxy/proxy.go:311 +0x54d
github.com/fagongzi/gateway/pkg/proxy.(*Proxy).ReverseProxyHandler-fm(0xc420538000)
/GoPath/src/github.com/fagongzi/gateway/pkg/proxy/proxy.go:102 +0x34
github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp.(*Server).serveConn(0xc420386a00, 0xb657c0, 0xc4201a8080, 0x1, 0xc420320101)
/GoPath/src/github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp/server.go:1494 +0x611
github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp.(*Server).(github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp.serveConn)-fm(0xb657c0, 0xc4201a8080, 0x1, 0x0)
/GoPath/src/github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp/server.go:1223 +0x3e
github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp.(*workerPool).workerFunc(0xc420320480, 0xc4201436a0)
/GoPath/src/github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp/workerpool.go:224 +0x117
github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp.(*workerPool).getCh.func1(0xc420320480, 0xc4201436a0, 0x9b8580, 0xc4201436a0)
/GoPath/src/github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp/workerpool.go:183 +0x35
created by github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp.(*workerPool).getCh
/GoPath/src/github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp/workerpool.go:182 +0x119
server配置
{
"id": 1001,
"addr": "my_server:80",
"protocol": 0,
"max_qps": 100,
"heath_check": {
"path": "/path/to/heath_check",
"body": "{\"error_code\":0,\"error_msg\":\"成功\",\"result\":\"ok\"}",
"check_interval": 5000000000,
"timeout": 10000000000
},
"circuit_breaker": {
"close_timeout": 10000000000,
"half_traffic_rate": 5,
"rate_check_period": 1000000000,
"failure_rate_to_close": 5,
"succeed_rate_to_open": 90
}
}
$ ./proxy -version
GitCommit: ad08d43
BuildTime: 2018-05-29T15:03:26+0800
GoVersion: go version go1.10 darwin/amd64
the protocol of the backend api 能否自己扩展?例如对消息队列的支持。
hi @zhangxu19830126 ,
自定义filter,希望处理失败时,返回客户端还是一段固定的json,http code 为200
比如 {"code":499, "msg":"session 校验失败"}
不知是否可以支持?
您好,对这个项目不是很了解,可能在配置上有点问题,不知道是怎么回事,麻烦帮忙指点下,多谢。
我的环境下:
## gateway的log如下:
2016/06/30 19:57:18 log.go:31: [INFO] set log level to
2016/06/30 19:57:18 gateway.go:68: [INFO] conf:<&{Addr::80 MgrAddr::8081 EtcdAddr:http://127.0.0.1:2379 EtcdPrefix:/gateway LogLevel:info EnableRuntimeVal:false EnableCookieVal:false EnableHeadVal:false ReqHeadStaticMapping:map[] RspHeadStaticMapping:map[]}>
2016/06/30 19:57:18 ruletable.go:467: [INFO] RouteTable start watch.
2016/06/30 19:57:18 etcd.go:379: [INFO] Etcd watch at:
2016/06/30 19:57:18 ruletable.go:564: [WARN] Load clusters fail.
[error]: 100: Key not found (/gateway) [5]
2016/06/30 19:57:18 ruletable.go:579: [WARN] Load servers from etcd fail.
[error]: 100: Key not found (/gateway) [5]
2016/06/30 19:57:18 ruletable.go:610: [WARN] Load binds from etcd fail.
[error]: 100: Key not found (/gateway) [5]
2016/06/30 19:57:18 ruletable.go:625: [WARN] Load aggregations from etcd fail.
[error]: 100: Key not found (/gateway) [5]
2016/06/30 19:57:18 ruletable.go:595: [WARN] Load routings from etcd fail.
[error]: 100: Key not found (/gateway) [5]
2016/06/30 19:57:18 manager.go:72: [INFO] Mgr listen at :8081.
## admin的log如下:
start at 192.168.2.56:9090
time=2016-06-30T20:04:01-07:00, remote_ip=192.168.2.71, method=GET, uri=/, status=404, took=958.284µs, sent=9 bytes
time=2016-06-30T20:04:11-07:00, remote_ip=192.168.2.71, method=GET, uri=/gateway, status=404, took=2.547534ms, sent=9 bytes
不知道为什么admin访问的时候老是404“Not Found”。使用的用户名和密码都是:admin
刚刚下载最新版的镜像
docker pull fagongzi/gateway
运行命令docker -d -P fagongzi/gateway
然后我访问由8080映射出来的32788端口,都不能访问。显示拒绝链接。
宿主防火墙确认开放了的。
在微服务构建上,当前使用Consul的很多,如果在整个技术栈里,同时维护etcd还有Consul会增加维护成本。强烈建议大侠增加这个网关对于Consul的支持。
需求就是,可以采用Consul替代etcd。并实现Consul的服务发现注册。
谢谢!!
如题
Readme中的微信群二维码已经过期,需要更新一下
If delete a cluster or server which has bind info. API will not work, return 503
use the reate button in the page to add route info into the gateway, the response of /api/routings is ok, but can not see any new route info in the /#/routings page. I check the code pkg/model/store_consul.go:422 and find the code "pairs, _, err := s.client.KV().List(s.apisDir, nil)", maybe "pairs, _, err := s.client.KV().List(s.routingsDir, nil)" is corrected.
请问这个框架是否有在实际的线上生产环境中运行使用,稳定性是否可靠
负载均衡加多个proxy,rate-limiter的qps计算是不是会有问题?
计算qps好像是有状态的,proxy不是完全stateless的吧
我单节点部署proxy是,在centos7上部署,机器有内网ip和公网ip,用内网ip部署正常,用公网ip部署时会报错,启动失败。
[root@iZ2ze0yas4kb5a8o6z2m46Z gateway-2.0.0]# ./proxy -addr=47.95.XX.XX:8500
2018/03/26 15:34:57.882652 [info] filter added, filter=<&{Name:WHITELIST External:false ExternalPluginFile: ExternalCfg:}>
2018/03/26 15:34:57.882726 [info] filter added, filter=<&{Name:BLACKLIST External:false ExternalPluginFile: ExternalCfg:}>
2018/03/26 15:34:57.882732 [info] filter added, filter=<&{Name:ANALYSIS External:false ExternalPluginFile: ExternalCfg:}>
2018/03/26 15:34:57.882745 [info] filter added, filter=<&{Name:RATE-LIMITING External:false ExternalPluginFile: ExternalCfg:}>
2018/03/26 15:34:57.882750 [info] filter added, filter=<&{Name:CIRCUIT-BREAKER External:false ExternalPluginFile: ExternalCfg:}>
2018/03/26 15:34:57.882755 [info] filter added, filter=<&{Name:HTTP-ACCESS External:false ExternalPluginFile: ExternalCfg:}>
2018/03/26 15:34:57.882761 [info] filter added, filter=<&{Name:HEADER External:false ExternalPluginFile: ExternalCfg:}>
2018/03/26 15:34:57.882767 [info] filter added, filter=<&{Name:XFORWARD External:false ExternalPluginFile: ExternalCfg:}>
2018/03/26 15:34:57.882773 [info] filter added, filter=<&{Name:VALIDATION External:false ExternalPluginFile: ExternalCfg:}>
2018/03/26 15:34:57.883557 [info] start server check worker
2018/03/26 15:34:57.885411 [info] load proxies
2018/03/26 15:34:57.885524 [info] router start watch meta data
2018/03/26 15:34:57.885554 [info] watch event at:
2018/03/26 15:34:57.885937 [info] proxy <000047.95.XX.XX:8500> added
2018/03/26 15:34:57.885951 [info] proxy <00172.17.175.XX:8500> added
2018/03/26 15:34:57.885968 [info] load clusters
2018/03/26 15:34:57.886458 [info] cluster <10> added, data <id:10 name:"c1" >
2018/03/26 15:34:57.886467 [info] load servers
2018/03/26 15:34:57.888486 [info] analysis: added, key=<1004> interval=<1s>
2018/03/26 15:34:57.888636 [info] server <1004> added, data <id:1004 addr:"60.205.XX.XX:8000" maxQPS:50 heathCheck:<path:"/ping" checkInterval:10000000000 timeout:30000000000 > >
2018/03/26 15:34:57.888653 [info] load binds
2018/03/26 15:34:57.891992 [info] server <1004> UP
2018/03/26 15:34:57.892011 [info] bind <10,1004> created
2018/03/26 15:34:57.892015 [info] bind <10,1004> actived
2018/03/26 15:34:57.892017 [info] load apis
proto: no coders for metapb.Parameter
proto: no encoder for Parameter metapb.Parameter [GetProperties]
proto: no slice oenc for reflect.rtype = []reflect.rtype
proto: no encoder for Rules []metapb.ValidationRule [GetProperties]
2018/03/26 15:34:57.892604 [info] api <1008> added, data <id:1008 name:"api3" urlPattern:"/pc/(.+)" method:"" status:Up nodes:<clusterID:10 > >
2018/03/26 15:34:57.892637 [info] api <1009> added, data <id:1009 name:"api3" urlPattern:"/ping/(.+)" method:"" status:Up nodes:<clusterID:10 > >
2018/03/26 15:34:57.892654 [info] api <1010> added, data <id:1010 name:"api3" urlPattern:"/weixin/(.+)" method:"*" nodes:<clusterID:10 > >
2018/03/26 15:34:57.892658 [info] load routings
2018/03/26 15:34:57.893561 [info] gateway proxy started at <47.95.XX.XX:8500>
2018/03/26 15:34:57.893619 [fatal] gateway proxy start failed, errors:
listen tcp4 47.95.xx.xx:8500: bind: cannot assign requested address
请问这个能不能支持consul呢??付费也可以。能联系我一下吗?
当 go build cmd/proxy/proxy.go
时候,报错:
pkg/lb/lb.go:6:2: cannot find package "github.com/valyala/fasthttp" in any of:
/Users/apple/work/gowork/src/github.com/fagongzi/gateway/vendor/github.com/valyala/fasthttp (vendor tree)
/usr/local/go/src/github.com/valyala/fasthttp (from $GOROOT)
/Users/apple/work/gowork/src/github.com/valyala/fasthttp (from $GOPATH)
也就是没有任何地方调用newJob,有点看不懂这个task的运行机制
我用的是最近的发布版(2月5号),测试api状态更新时,有异常。
examples里的api.go的130行和132行。代码调用后,apiserver返回的api状态没有产生任何变化,和创建api时状态一样。
// 下线API
c.NewAPIBuilder().Use(*api).Down().Commit()
// 上线API
c.NewAPIBuilder().Use(*api).UP().Commit()
关闭了,是我代码调用的问题,解决了。
如题
server -> list -> bind button, 弹出对话框, 此时背景变暗, 选对话框上的cluster, 然后点"Bind"按钮, 对话框消失, 但页面背景仍然是暗的, 并且不再响应鼠标。
文件上传怎么处理?
在mac下按照文档clone下来代码后,进入项目根目录下,运行go build cmd/proxy/proxy.go 报如下错误:
go install command-line-arguments: build output "proxy" already exists and is a directory
请问下这个问题怎么解决呢?
我的go sdk环境配置如下:
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="~/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.8.1/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.8.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/jz/yzzkw_gs5z701z5_x47403gw0000gn/T/go-build946663768=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
gateway存放目录:
~/go/src/github.com/fagongzi/gateway
server bind、unbind 的时候,如果server没有设置OpenToCloseCollectSeconds或OpenToCloseCollectSeconds=0, proxy会挂掉,
是不是创建server的时候做参数验证或给默认值
panic: non-positive interval for NewTicker
goroutine 58 [running]:
time.NewTicker(0x0, 0xc420011ad0)
/usr/local/go/src/time/tick.go:23 +0x1b4
github.com/fagongzi/gateway/pkg/model.(*Analysis).AddRecentCount(0xc4200166e0, 0xc4201938b0, 0xe, 0x0)
/Users/weisd/gopath/src/github.com/fagongzi/gateway/pkg/model/analysis.go:154 +0x1ce
github.com/fagongzi/gateway/pkg/model.(*RouteTable).UpdateServer(0xc420060310, 0xc4201962d0, 0x0, 0x0)
/Users/weisd/gopath/src/github.com/fagongzi/gateway/pkg/model/ruletable.go:238 +0x155
github.com/fagongzi/gateway/pkg/model.(*RouteTable).doReceiveServer(0xc420060310, 0xc4201bf380)
/Users/weisd/gopath/src/github.com/fagongzi/gateway/pkg/model/ruletable.go:586 +0x6c
github.com/fagongzi/gateway/pkg/model.(*RouteTable).doEvtReceive(0xc420060310)
/Users/weisd/gopath/src/github.com/fagongzi/gateway/pkg/model/ruletable.go:529 +0x19d
created by github.com/fagongzi/gateway/pkg/model.(*RouteTable).watch
/Users/weisd/gopath/src/github.com/fagongzi/gateway/pkg/model/ruletable.go:514 +0xb8
as title
设置的Server CheckResponsedBody 为空,健康检查的时间间隔为2s。经日志追踪,server xxxxx第一次健康检查失败的日志出现时,却展示累计25次失败。server.go:233: [WARN] Server <xxxxx, /check/status, 25> check fail.
经分析源码pkg/model/server.go func (s *Server) check() 中 if s.CheckResponsedBody == "" { return true} 在这块逻辑中没有设置succ标识为true,而直接return。这会导致succ标识的值一直为false,进而checkFailCount++ (检查失败的次数会持续累加),s.useCheckDuration += s.useCheckDuration / 2(健康检查的时间间隔会在每次健康检查后延长当次间隔的一半)。 造成的影响就是随着proxy代理server服务的时间越久,一旦server服务异常又快速恢复,但随着健康检查间隔的延长,要等到下次健康检查时间到来,才能重新bind server。
应该是:
git clone https://github.com/fagongzi/gateway.git
在使用的场景中,配置4个server,4个server分别属于4个cluster,并且所有api匹配规则不存在交叉的情况。在应用的场景中,需要先访问server1的api,然后再访问其他server的api,这时经常会碰到404的请求,经排查多个server的访问日志,发现404是由于api请求转发错乱导致,server1的api请求被转发到其他server服务上。
比如我们有一个活动的h5页面,如果服务器不可用了,就直接给用户暴露出了{"code":200,"data":"","msg":"服务异常,请重新尝试"},如果能跳转到指定的页面,会更友好。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.