Giter VIP home page Giter VIP logo

abtestinggateway's Introduction

基于动态策略的灰度发布系统

  • ABTestingGateway 是一个可以动态设置分流策略的灰度发布系统,工作在7层,基于nginx和ngx-lua开发,使用 redis 作为分流策略数据库,可以实现动态调度功能。

  • nginx是目前使用较多的7层服务器,可以实现高性能的转发和响应;ABTestingGateway 是在 nginx 转发的框架内,在转向 upstream 前,根据 用户请求特征 和 系统的分流策略 ,查找出目标upstream,进而实现分流。

  • ABTestingGateway 是新浪微博内部的动态路由系统 dygateway 的一部分,因此本文档中的 dygateway 主要是指其子功能 ABTestingGateway。动态路由系统dygateway目前应用于手机微博7层、微博头条等产品线。

在以往的基于 nginx 实现的灰度系统中,分流逻辑往往通过 rewrite 阶段的 if 和 rewrite 指令等实现,优点是性能较高,缺点是功能受限容易出错,以及转发规则固定,只能静态分流。针对这些缺点,我们设计实现了ABTestingGateway,采用 ngx-lua 实现系统功能,通过启用lua-shared-dictlua-resty-lock作为系统缓存和缓存锁,系统获得了较为接近原生nginx转发的性能。

ABTestingGateway 的架构简图

如果在使用过程中有任何问题,欢迎大家来吐槽,一起完善、一起提高、一起使用!

email: [email protected] [email protected]

压测数据:压测报告

项目演讲:演讲文档

Features:

  • 支持多种分流方式,目前包括iprange、uidrange、uid尾数和指定uid分流

  • 动态设置分流策略,即时生效,无需重启

  • 可扩展性,提供了开发框架,开发者可以灵活添加新的分流方式,实现二次开发

  • 高性能,压测数据接近原生nginx转发

  • 灰度系统配置写在nginx配置文件中,方便管理员配置

  • 适用于多种场景:灰度发布、AB测试和负载均衡等

  • new feature: 支持多级分流

灰度发布系统功能简介

对于ab管理功能而言,步骤是以下三步:

  1. 向系统添加策略,将策略写入策略数据库中
  2. 为具体的server设置运行时信息,将某个分流策略设置为运行时策略
  3. 之后可以进行分流操作

详细解释参见: ab分流功能须知

对于ab分流功能而言,分流流程图如图所示

分流过程流程图

系统部署

软件依赖

  • openresty
  • ngx_lua
  • LuaJIT
  • lua-cjson
  • redis

注意:建议选用openresty最新版,但是从openresty-1.9.15.1开始,lua-resty-core有些api变更,因此建议先使用openresty-1.9.7.5,原因是:必读

注意:tengine用户仍然可以使用本项目,只需要从openresty软件包中获取最新的ngx_lua、LuaJIT以及lua-cjson等,并注意:必读

how to start

repo中的utils/conf文件夹中有灰度系统部署所需的最小示例

目前repo的master分支是支持多级分流的版本,如果只想体验单级分流,可以fork single_diversion_release分支,具体文档都在相关分支的readme中。

1. git clone https://github.com/SinaMSRE/ABTestingGateway
2. cd /path/to/ABTestingGateway/utils && mkdir logs

# 启动redis数据库
3. redis-server conf/redis.conf 

# 启动upstream server,其中stable为默认upstream
4. /usr/local/nginx/sbin/nginx -p `pwd` -c conf/stable.conf
5. /usr/local/nginx/sbin/nginx -p `pwd` -c conf/beta1.conf
6. /usr/local/nginx/sbin/nginx -p `pwd` -c conf/beta2.conf
7. /usr/local/nginx/sbin/nginx -p `pwd` -c conf/beta3.conf
8. /usr/local/nginx/sbin/nginx -p `pwd` -c conf/beta4.conf

# 启动灰度系统,proxy server,灰度系统的配置也写在conf/nginx.conf中
9. /usr/local/nginx/sbin/nginx -p `pwd` -c conf/nginx.conf

# 简单验证:添加分流策略组
$ curl 127.0.0.1:8080/ab_admin?action=policygroup_set -d '{"1":{"divtype":"uidsuffix","divdata":[{"suffix":"1","upstream":"beta1"},{"suffix":"3","upstream":"beta2"},{"suffix":"5","upstream":"beta1"},{"suffix":"0","upstream":"beta3"}]},"2":{"divtype":"arg_city","divdata":[{"city":"BJ","upstream":"beta1"},{"city":"SH","upstream":"beta2"},{"city":"XA","upstream":"beta1"},{"city":"HZ","upstream":"beta3"}]},"3":{"divtype":"iprange","divdata":[{"range":{"start":1111,"end":2222},"upstream":"beta1"},{"range":{"start":3333,"end":4444},"upstream":"beta2"},{"range":{"start":7777,"end":2130706433},"upstream":"beta2"}]}}'

{"desc":"success ","code":200,"data":{"groupid":0,"group":[0,1,2]}}

# 简单验证:设置运行时策略

$ curl "127.0.0.1:8080/ab_admin?action=runtime_set&hostname=api.weibo.cn&policygroupid=0"

# 分流
$ curl 127.0.0.1:8030 -H 'X-Uid:39' -H 'X-Real-IP:192.168.1.1'
this is stable server

$ curl 127.0.0.1:8030 -H 'X-Uid:30' -H 'X-Real-IP:192.168.1.1'
this is beta3 server

$ curl 127.0.0.1:8030/?city=BJ -H 'X-Uid:39' -H 'X-Real-IP:192.168.1.1'
this is beta1 server

配置过程

  • 由于内部部署时以dygateway项目名部署,因此下文中的所有配置,都应将ABTestingGateway文件夹重命名为dygateway

nginx.conf配置过程

redis.conf配置过程

系统使用

ab分流策略

  • ab功能目前支持的分流策略有

    • iprange: ip段分流
    • uidrange: 用户uid段分流
    • uidsuffix: uid尾数分流
    • uidappoint: uid白名单分流
  • 可以灵活添加新的分流方式

ab分流策略格式和样例

ab功能接口

    * 策略管理:增删改查
    /ab_admin?action=policy_check
    /ab_admin?action=policy_set
    /ab_admin?action=policy_get
    /ab_admin?action=policy_del

    * 策略组管理(用于多级分流)
    /ab_admin?action=policygroup_check
    /ab_admin?action=policygroup_set
    /ab_admin?action=policygroup_get
    /ab_admin?action=policygroup_del

    * 运行时信息管理
        * 其中runtime_set接受policyid和policygroupid参数,分别用于单级分流和多级分流

    /ab_admin?action=runtime_get
    /ab_admin?action=runtime_set
    /ab_admin?action=runtime_del

压测结果:

压测环境下灰度系统与原生nginx转发的对比图

压测环境下灰度系统与原生nginx转发的数据对比

如图所示,用户请求完全命中cache是理想中的情况,灰度系统在理想情况下可以达到十分接近原生nginx转发的性能。

产生图中压测结果的场景是:用户请求经过proxy server转向upstream server,访问1KB大小的静态文件。

proxy server的硬件配置:

  • CPU:E5620 2.4GHz 16核
  • Mem:24GB
  • Nic:千兆网卡,多队列,理论流量峰值为125MB/s
  • 注:压测结果是单级分流模式的压力测试结果,多级压测与单级压测的数据像差不多,因为ngx_lua的执行时间仅占ab功能的小部分,瓶颈不在于此

线上部署简图:

FAQ

  • 启动时报错,提示ngx_http_lua_ffi_semaphore_new未定义
    • 这个是ngx_lua比较新的版本中带有的 resty.semaphore模块,请确定ngx_lua版本包含该模块
    • LuaJIT也请采用openresty软件包中提供的版本
    • 其实直接采用openresty最好,使用最新版本的openresty不会用软件依赖问题,只是我所在的项目组有tengine的需求,所以用tengine
  • 为什么都root用户了还会提示Permission denied, solution

TODO LIST

  • 开发nginx shm storage模块,扩展 ngx-shared-dict 的功能
    • 目前 ngx-shared-dict 提供高效快速的 kv 式简单存储
    • 简单高效的存储,不足之处最直接的体现在不支持缓存 lua table。[lua-resty-lrucache提供LuaVM级别的缓存,不能跨worker共享]
    • 目前团队同学基于红黑树实现了类似于ngx-shared-dict的存储功能,可以存储任意类型,查找方式由用户自定义。项目地址:ngx-shared-rbtree
    • ngx-shared-rbtree的不足之处在于“模块只能存储一颗红黑树”,不能实现复杂用法,因此需要被进一步扩展。类似于如下所示的使用方法:
local dict = ngx.shared.ngxdb
-----------------------------------

local db_tab = "db_tab"
local k_tab = {["a"]=1, ["b"]=2}
local v_tab = {1, 2, 3}

dict:set(db_tab, k_tab, v_tab)

local v_tab = dict:get(db_tab, k_tab)
-----------------------------------

local db_kv = "db_kv"
local k = "foo"
local v = "bar"

dict:set(db_kv, k, v)

local getv = dict:get(db_kv, v)
-----------------------------------
  • 扩展ABTestingGateway的功能

    • 由于该项目最初是为手机微博7层开发的,所以只关注了分流功能。
    • 而项目在公司内部使用过程中发现,不同业务对于ab项目这层转发工作的期许不太一样
    • 有的业务需要将用户分流到不同的服务器上
    • 有的业务需要在这步处理中根据策略增减用户请求的uri参数或者header头
    • 所以扩展ab项目的这层转发很有必要,目前随着在公司内部的推广,也在不停的收集需求,探索新的玩法
    • 其实整个AB项目并没有太高的技术含量,大家关于ab和分流的玩法都大同小异,所不同的是,我们在这种范式下,能发出多少有趣的花样,期待大家多多交流
  • 逐步开源dygateway的所有功能

abtestinggateway's People

Contributors

20100507 avatar bg2bkk avatar michael2008s avatar uknownothingsnow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

abtestinggateway's Issues

对同一个策略可以重复设置以及查询分流策略时提示参数无效的问题

1 我对同一个策略进行了重复设置,都能成功。如下是我的输出,这样合理吗。
[root@data2-node logs]# curl 127.0.0.1:8080/ab_admin?action=policy_set -d '{"divtype":"uidsuffix","divdata":[{"suffix":"1","upstream":"beta1"},{"suffix":"3",2"},{"suffix":"5","upstream":"beta1"},{"suffix":"0","upstream":"beta3"}]}'
{"code":200,"desc":"success the id of new policy is 8"}
[root@data2-node logs]# curl 127.0.0.1:8080/ab_admin?action=policy_set -d '{"divtype":"uidsuffix","divdata":[{"suffix":"1","upstream":"beta1"},{"suffix":"3",2"},{"suffix":"5","upstream":"beta1"},{"suffix":"0","upstream":"beta3"}]}'
{"code":200,"desc":"success the id of new policy is 9"}

2 为什么在查询策略时,一直提示策略参数有误呢,如下是我的提示。(严格按照readme操作的)
[root@data2-node logs]# curl 127.0.0.1:8080/ab_admin?action=policy_get&arg_policyid=4
[1] 77281
[root@data2-node logs]# {"code":50104,"desc":"parameter type error for policyID invalid"}

[1]+ Done curl 127.0.0.1:8080/ab_admin?action=policy_get
[root@data2-node logs]# curl 127.0.0.1:8080/ab_admin?action=policy_get&&arg_policyid=4
{"code":50104,"desc":"parameter type error for policyID invalid"}
[root@data2-node logs]# curl 127.0.0.1:8080/ab_admin?action=policy_get
{"code":50104,"desc":"parameter type error for policyID invalid"}
[root@data2-node logs]#
[root@data2-node logs]# curl 127.0.0.1:8080/ab_admin?action=policy_get&policyid=4
[1] 77296
[root@data2-node logs]# {"code":50104,"desc":"parameter type error for policyID invalid"}

[1]+ Done curl 127.0.0.1:8080/ab_admin?action=policy_get
[root@data2-node logs]# curl 127.0.0.1:8080/ab_admin?action=runtime_get&hostname=api.weibo.cn
[1] 77305
[root@data2-node logs]# {"code":50104,"desc":"parameter type error for arg hostname invalid: "}

按照uid 和 iprange 两个或多个条件来分流到一个beta机器

现在demo上是一个分流条件,例如:根据uid分流,根据iprange分流,根据city分流 等等,

现在我想做成 多个分流条件,例如按照uid 和 iprange 两个或多个条件来分流到一个beta机器。

还有个问题 如果upstream 分流到一个集群,而不是某台beta机器,如何做动态配置?如何处理呢 ?有相关的lua库吗?

在nginx.conf中关于设置backend变量的值的疑问?

location ~*  /abc/(i|f)/ {

	set $backend 'stable';
	rewrite_by_lua_file '../diversion/diversion.lua';
	proxy_pass http://$backend;
}

请问一下,在$backend中默认将其赋值为 ‘stable’,实际上由 '../diversion/diversion.lua'的功能模块进行策略的分析与赋值,然后转向相应的streaming中,如果'../diversion/diversion.lua'的功能模块获取失败,那么就对应stable streaming了???请问,这里是这样理解吗。

demo中nginx.conf配置文件中的$request_uid无法生效

Hi:
我按照片你们给的的demo来试用了,我安装tengine-2.1.0 redis-2.8.19 lua版本如下:

rpm -qa | grep lua

lua-lpeg-0.9-3.el6.x86_64
lua-5.1.4-4.1.el6.x86_64
lua-devel-5.1.4-4.1.el6.x86_64
lua-json-1.3.2-2.el6.noarch

lua-jit版本是LuaJIT-2.0.4

我git你们给出的demo 然后运行 # /usr/local/nginx/sbin/nginx -p pwd -c conf/nginx.conf
发现在一些问题:
a.nginx: [emerg] unknown directive "set_real_ip_from" in /opt/ABTestingGateway/utils/conf/nginx.conf:26
b.nginx: [emerg] unknown directive "real_ip_header" in /opt/ABTestingGateway/utils/conf/nginx.conf:27
c.nginx: [alert] lua_code_cache is off; this will hurt performance in /opt/ABTestingGateway/utils/conf/nginx.conf:56
d.nginx: [emerg] unknown "request_uid" variable

前面三个我把选项注释之后,不会再报错,但是最后一个request_uid这个参数在Nginx的变量中是没有的。现在很想知道这个变量代表的是什么意思,如何配置正常,才能启动?
再者,把这个参数去掉之后,可以正常启动,我找不到如何进入到后台?

添加策略组时返回404

您好。
我按照示例,添加策略组的时候:

curl 127.0.0.1:8080/ab_admin?action=policygroup_set -d '{"1":{"divtype":"uidsuffix","divdata":[{"suffix":"1","upstream":"beta1"},{"suffix":"3","upstream":"beta2"},{"suffix":"5","upstream":"beta1"},{"suffix":"0","upstream":"beta3"}]},"2":{"divtype":"arg_city","divdata":[{"city":"BJ","upstream":"beta1"},{"city":"SH","upstream":"beta2"},{"city":"XA","upstream":"beta1"},{"city":"HZ","upstream":"beta3"}]},"3":{"divtype":"iprange","divdata":[{"range":{"start":1111,"end":2222},"upstream":"beta1"},{"range":{"start":3333,"end":4444},"upstream":"beta2"},{"range":{"start":7777,"end":2130706433},"upstream":"beta2"}]}}'

返回了404错误:

<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>

是否接口有了改动而文档没有更新?

iprange设置cache的key/value

读了代码,在iprange的分流方式的时候,在nginx的cache里面设置的key/value是用户访问的ip2long的值/upstream值,如果用户访问量很大的话,会不会有问题?
另外,cache的超时时间设置多少比较适合?

启动时报错!!!

执行tengine-2.1.2/objs/nginx -p pwd -c conf/nginx.conf时报错
nginx: [emerg] unknown directive "set" in /path/to/ABTestingGateway-master/utils/conf/default.conf:22

tengine信息如下

/root/soft/tengine-2.1.2/objs/nginx -V

Tengine version: Tengine/2.1.2 (nginx/1.6.2)
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
TLS SNI support enabled
configure arguments: --with-ld-opt=-Wl,-rpath,/usr/local/web/LuaJIT-2.0.1/lib --with-luajit-inc=/usr/local/web/LuaJIT-2.0.1/include/luajit-2.0 --with-luajit-lib=/usr/local/web/LuaJIT-2.0.1/lib --without-http_rewrite_module --add-module=../lua-nginx-module-0.10.4
loaded modules:
ngx_core_module (static)
ngx_errlog_module (static)
ngx_conf_module (static)
ngx_dso_module (static)
ngx_syslog_module (static)
ngx_events_module (static)
ngx_event_core_module (static)
ngx_epoll_module (static)
ngx_procs_module (static)
ngx_proc_core_module (static)
ngx_openssl_module (static)
ngx_http_module (static)
ngx_http_core_module (static)
ngx_http_log_module (static)
ngx_http_upstream_module (static)
ngx_http_static_module (static)
ngx_http_autoindex_module (static)
ngx_http_index_module (static)
ngx_http_auth_basic_module (static)
ngx_http_access_module (static)
ngx_http_limit_conn_module (static)
ngx_http_limit_req_module (static)
ngx_http_geo_module (static)
ngx_http_map_module (static)
ngx_http_split_clients_module (static)
ngx_http_referer_module (static)
ngx_http_ssl_module (static)
ngx_http_proxy_module (static)
ngx_http_fastcgi_module (static)
ngx_http_uwsgi_module (static)
ngx_http_scgi_module (static)
ngx_http_memcached_module (static)
ngx_http_empty_gif_module (static)
ngx_http_browser_module (static)
ngx_http_user_agent_module (static)
ngx_http_upstream_ip_hash_module (static)
ngx_http_upstream_consistent_hash_module (static)
ngx_http_upstream_check_module (static)
ngx_http_upstream_least_conn_module (static)
ngx_http_upstream_keepalive_module (static)
ngx_http_upstream_dynamic_module (static)
ngx_http_stub_status_module (static)
ngx_http_write_filter_module (static)
ngx_http_header_filter_module (static)
ngx_http_chunked_filter_module (static)
ngx_http_range_header_filter_module (static)
ngx_http_gzip_filter_module (static)
ngx_http_postpone_filter_module (static)
ngx_http_ssi_filter_module (static)
ngx_http_charset_filter_module (static)
ngx_http_userid_filter_module (static)
ngx_http_footer_filter_module (static)
ngx_http_trim_filter_module (static)
ngx_http_headers_filter_module (static)
ngx_http_upstream_session_sticky_module (static)
ngx_http_reqstat_module (static)
ngx_http_lua_module (static)
ngx_http_copy_filter_module (static)
ngx_http_range_body_filter_module (static)
ngx_http_not_modified_filter_module (static)

为什么都root用户了还会提示Permission denied

请求任何接口都返回404,日志里提示
cannot open /path/to/ABTestingGateway-master/utils/../admin/ab_action.lua: Permission denied
现在都是root用户了怎么还会这样,权限也改成777了
-rwxrwxrwx 1 root root 2681 May 11 15:54 ab_action.lua
-rwxrwxrwx 1 root root 2303 May 11 15:54 action.lua
-rwxrwxrwx 1 root root 7857 May 11 15:54 policygroup.lua
-rwxrwxrwx 1 root root 6093 May 11 15:54 policy.lua
-rwxrwxrwx 1 root root 7173 May 11 15:54 runtime.lua

请问有没QQ交流群

经过调研,发现你们这个分流发布引擎特别适合我们目前的场景,由于本人是个java程序员,不太懂里面一些东西,demo如何跑起来,希望能有个QQ群或者QQ,非常感谢,觉得你们的产品做的很好,也希望我能成功把你们的产品引入公司,发挥它的作用!

手机端进行灰度测试时先POST /mobile/integral/getIntegralInfo.do HTTP/1.1请求直接开始调用策略丢弃

您好:
我用手机端业务进行测试时,登陆ID后需要手势密码解锁后进行APP内容加载,在进行灰度ID策略设置后,查看vhost_error.log日志,点击登陆只会出现post请求(如标题),然后无法找到对应police后走stable节点,正常连接请求日志为先post请求,输入手势解锁后进行get id信息 图片加载等,是否在策略模块中只配置对GET请求进行灰度,如何配置,请指点~在线等,谢谢!

关于启动管理后台错误

我在启动管理后台,
/usr/local/nginx/sbin/nginx -p pwd -c conf/vhost.conf
提示这个:
nginx: [emerg] "lua_shared_dict" directive is not allowed here in /usr/local/dygateway/utils/conf/vhost.conf:1

是因为版本不对吗?

多级分流的读取upstream的step4循环读取数据库

将多级分流的admin/diversion.lua的第二个pfunc的step4修改成循环全部divsteps
本地跑的时候读取redis总是只有第一个循环才读的到数据。例如:多级分流把uidappoint设置成policy:0,把iprange设置成policy:1,则lua只有uidappoint的getUpstream读得出redis值;反之,多级分流把iprange设置成policy:0,把uidappoint设置成policy:1,则lua只有iprange的getUpstream读得出redis值
这个什么原因?

访问出现500错误,错误提示undefined symbol: ngx_http_lua_ffi_semaphore_new

image
查看错误日志:
2016/11/24 18:57:31 [error] 2804#2804: *8 lua entry thread aborted: runtime error: ../lib/lua-resty-core/lib/ngx/semaphore.lua:63: /usr/local/openresty/luajit/lib/libluajit- 5.1.so.2: undefined symbol: ngx_http_lua_ffi_semaphore_new stack traceback: coroutine 0: [C]: in function 'require' /www/abtesting/utils/../diversion/diversion.lua:11: in function </www/abtesting/utils/../diversion/diversion.lua:1>, client: 127.0.0.1, server: api.weibo.cn, request : "GET / HTTP/1.1", host: "127.0.0.1:8030"
分流策略设置都正常,出现的错误 undefined symbol: ngx_http_lua_ffi_semaphore_new,是luajit或niginx版本不对吗?
luajit 版本:LuaJIT 2.1.0-beta2 -- Copyright (C) 2005-2016 Mike Pall. http://luajit.org/
niginx版本:nginx version: openresty/1.9.15.1

能同时设定多个分流策略吗?

比如我需要同时设定不同的分流策略,如按照uid分流和按照ip分流,管理接口该如何设置?
对应的,如果能够同时设定不同的分流策略,我需要单独移除其中某个策略,该如何操作?我看runtime/del接口不能指定策略id,只能全部清除。

运行示例的时候出错

你好,

我是nginx新手,
按照README里的示例,在跑到
# 启动灰度系统,proxy server,灰度系统的配置也写在conf/nginx.conf中
9. /usr/local/nginx/sbin/nginx -p pwd -c conf/nginx.conf

的时候出现下面错误
"nginx: [emerg] unknown directive "uniqueid_prefix" in xxx"

请问,unqiueid_prefix是哪个module里的命令。 给的示例又需要哪些module才能跑呢?

按请求参数设置分流策略问题

在搭建完ABTestingGateway后,进行策略配置时,其URL如下:
curl 127.0.0.1:8080/ab_admin?action=policygroup_set -d '{"1":{"divtype":"arg__userId","divdata":[{"_userId":3100080,"upstream":"beta1"},{"_userId":3100081,"upstream":"beta1"}]}}'
返回信息为:
{"code":50104,"desc":"parameter type error for unsupported divtype"}

但如使用以下URL则设置成功:
curl 127.0.0.1:8080/ab_admin?action=policygroup_set -d '{"1":{"divtype":"arg_city","divdata":[{"city":"BJ","upstream":"beta1"},{"city":"SH","upstream":"beta2"}]}}'
{"desc":"success ","code":200,"data":{"groupid":1,"group":[3]}}

现是否只支持参数为city,其余参数不支持,望请解答,谢谢!

[在线等~~]加载 abtesting.utils.sema 失败

嗨~
我在执行:curl 127.0.0.1:8030 -H 'X-Uid:30' -H 'X-Real-IP:192.168.1.1
报如下错误:
2016/05/04 00:16:22 [error] 7189#0: *31 lua entry thread aborted: runtime error: ...ABTestingGateway-master/utils/../diversion/diversion.lua:12: loop or previous error loading module 'abtesting.utils.sema'
stack traceback:
coroutine 0:
[C]: in function 'require'
...ABTestingGateway-master/utils/../diversion/diversion.lua:12: in function <...ABTestingGateway-master/utils/../diversion/diversion.lua:1>, client: 127.0.0.1, server: api.weibo.cn, request: "GET / HTTP/1.1", host: "127.0.0.1:8030"

疑问:
cat sema.lua
local modulename = "abtestingSema"
local _M = {}
local semaphore = require("lua-resty-core.lib.ngx.semaphore")

_M.sema = semaphore.new(1)
_M.upsSema = semaphore.new(1)

lua-resty-core.lib.ngx.semaphore 加载失败。。。 这个有什么作用呢 ?

local sem, err = sema:wait(0.01)
if sem then sema:post(1) end
等等~ 锁相关的吗 ? 学习下。

:)

访问404与如何进入web管理界面

你好,
1,README 中详细讲解了如何配置各种策略与运行时环境,但是没有提如何配置主服务与beta服务的访问,你们给出的策略例子只能访问根目录,其它目录都报404,我们的项目url比较多,我们想按照不同的用户分流到不同的服务器上,该如何配置url,可否给出个例子
2,没有发现项目中嵌入web管理页面

hi,哥们,我打算基于你的这个项目做一个基于tengine的百分比降级项目,你觉得可行吗?

大概的思路是这样的:

location /ab_admin {
content_by_lua_file '../admin/ab_action.lua';
}

location /degrade_admin{
    content_by_lua_file '../admin/degrade_action.lua';
}

仿照你的ab_admin 写一个degrade_admin,用于降级规则的设置,删除和查看。其规则的配置也仿照你的规则:
curl 127.0.0.1:8080/degrade_admin/action=degrade_set -d '{"degtype":"uidsuffix","degdata":[{"suffix":"1","percent":"90"}]}'

表示降级规则类型为uid后缀,若后缀为1,则降级百分之90.。

然后在 server {
listen 8050
access_by_lua_file '../degrade/degrade.lua';
location /test {
}
xxxxxx
}
用degrade.lua来做降级逻辑。

这样可以复用你的很多模块,error,handler,redis,cache等模块。

你觉得这样可行吗?真实的部署会不会有问题?因为刚开始接触实际项目,没啥经验:)

谢谢了:)

ABTestionGateway扩展分流类型问题咨询

咨询一下如何扩展分流策略,比如我现在要按照参数年龄age分流,我按照以前有同事提供的,在init.luaabtesting\utils 的init.lua中_M.divtypes添加 ["arg_age"] = 'ageParser',然后启动,我添加策略时报错,如下所示:
[root@data2-node utils]# curl 127.0.0.1:8080/ab_admin?action=policy_set -d '{"divtype":"arg_age","divdata":[{"age":"1","upstream":"data1"},{"age":"2","upstream":"core"}]}'
{"code":40201,"desc":"lua runtime error ../lib/abtesting/adapter/policy.lua:95: module 'abtesting.diversion.arg_age' not found:\n\tno field package.preload['abtesting.diversion.arg_age']\n\tno file '../abtesting/diversion/arg_age.lua'\n\tno file '../lib/abtesting/diversion/arg_age.lua'\n\tno file '../lib/lua-resty-core/lib/abtesting/diversion/arg_age.lua'\n\tno file '/usr/local/openresty/lualib/abtesting/diversion/arg_age.lua'\n\tno file '/usr/local/openresty/lualib/abtesting/diversion/arg_age/init.lua'\n\tno file './abtesting/diversion/arg_age.lua'\n\tno file '/usr/local/openresty/luajit/share/luajit-2.1.0-beta1/abtesting/diversion/arg_age.lua'\n\tno file '/usr/local/share/lua/5.1/abtesting/diversion/arg_age.lua'\n\tno file '/usr/local/share/lua/5.1/abtesting/diversion/arg_age/init.lua'\n\tno file '/usr/local/openresty/luajit/share/lua/5.1/abtesting/diversion/arg_age.lua'\n\tno file '/usr/local/openresty/luajit/share/lua/5.1/abtesting/diversion/arg_age/init.lua'\n\tno file '/usr/local/openresty/lualib/abtesting/diversion/arg_age.so'\n\tno file './abtesting/diversion/arg_age.so'\n\tno file '/usr/local/lib/lua/5.1/abtesting/diversion/arg_age.so'\n\tno file '/usr/local/openresty/luajit/lib/lua/5.1/abtesting/diversion/arg_age.so'\n\tno file '/usr/local/lib/lua/5.1/loadall.so'\n\tno file '/usr/local/openresty/lualib/abtesting.so'\n\tno file './abtesting.so'\n\tno file '/usr/local/lib/lua/5.1/abtesting.so'\n\tno file '/usr/local/openresty/luajit/lib/lua/5.1/abtesting.so'\n\tno file '/usr/local/lib/lua/5.1/loadall.so'"}

发现可能是代码逻辑错误

你好,在使用过程中发现此处bug
在模块 local modulename = "abtestingCache" 代码中


_M.getUpstream = function(self, divsteps, usertable)
    local upstable = {}
    local cache = self.cache
    for i = 1, divsteps do
        local idx   = indices[i]
        local info  = usertable[idx]
        -- ups will be an actually value or nil
        if info then
            local ups   = cache:get(info)
            upstable[idx] = ups
        end
    end
    return upstable
end

_M.setUpstream = function(self, info, upstream)
    local cache  = self.cache
    local expire = shdict_expire
    cache:set(info, upstream, expire)
end

这个是用户获取分流upstream以及写入upstream 但是这个地方并没有加入hosts ,因为有cache关系可能会造成用户分流了上次cache中的upstream。

如何与现有架构结合部署

现在面临一个问题,现在生产环境都是使用的nginx同时前端有elb负载器,现在准备接入这个系统,如何部署,不影响线上的业务。

1、部署是否可以独立出来?
2、如何转移流量过来做算法配置。

额...在部署的时候遇到的问题。。

现在有两个问题:
1,部署问题
2,在cache失效时,回源到redis时的效率问题。

1,部署问题
现有的部署是只有一个管理机,一个redis主库。但现在的问题是,为了不让管理机出现单点故障,需要多台管理机构成管理机集群,就Redis的部署问题。
多台管理机构成的集群依然只会写入一个Redis主库,但Redis主库挂掉后怎么办?
其实想过管理机和业务nginx都使用同一个Redis集群,但是担心网络延时问题(主要是业务nginx)。
有没有什么好的部署方案:)

2,在业务nginx中,如果lua cache超时失效,回源redis时,那么这时候请求会阻塞吧,这个问题怎么解决呢?

(流量比较大。。:))

是否可以无痛使用redis 3.0?

因为前段nginx 会有多台,如果使用单台redis 会有很严重的单点问题,如果引入reids 的ha 方案,又增加整体复杂度,是否可以使用redis 3.0 虽然目前不是那么靠谱

访问时,遇到问题,不知是否部署错误,请指导

2016/09/30 16:04:24 [error] 17653#0: *66 lua entry thread aborted: runtime error: /usr/local/openresty/nginx/../admin/ab_action.lua:1: module 'abtesting.adapter.policy' not found:
no field package.preload['abtesting.adapter.policy']
no file '../abtesting/adapter/policy.lua'
no file '../lib/abtesting/adapter/policy.lua'
no file '../lib/lua-resty-core/lib/abtesting/adapter/policy.lua'
no file '/usr/local/openresty/site/lualib/abtesting/adapter/policy.lua'
no file '/usr/local/openresty/site/lualib/abtesting/adapter/policy/init.lua'
no file '/usr/local/openresty/lualib/abtesting/adapter/policy.lua'
no file '/usr/local/openresty/lualib/abtesting/adapter/policy/init.lua'
no file './abtesting/adapter/policy.lua'
no file '/usr/local/openresty/luajit/share/luajit-2.1.0-beta2/abtesting/adapter/policy.lua'
no file '/usr/local/share/lua/5.1/abtesting/adapter/policy.lua'
no file '/usr/local/share/lua/5.1/abtesting/adapter/policy/init.lua'
no file '/usr/local/openresty/luajit/share/lua/5.1/abtesting/adapter/policy.lua'
no file '/usr/local/openresty/luajit/share/lua/5.1/abtesting/adapter/policy/init.lua'
no file '/usr/local/openresty/site/lualib/abtesting/adapter/policy.so'
no file '/usr/local/openresty/lualib/abtesting/adapter/policy.so'
no file './abtesting/adapter/policy.so'
no file '/usr/local/lib/lua/5.1/abtesting/adapter/policy.so'
no file '/usr/local/openresty/luajit/lib/lua/5.1/abtesting/adapter/policy.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file '/usr/local/openresty/site/lualib/abtesting.so'
no file '/usr/local/openresty/lualib/abtesting.so'
no file './abtesting.so'
no file '/usr/local/lib/lua/5.1/abtesting.so'
no file '/usr/local/openresty/luajit/lib/lua/5.1/abtesting.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
coroutine 0:
[C]: in function 'require'
/usr/local/openresty/nginx/../admin/ab_action.lua:1: in function </usr/local/openresty/nginx/../admin/ab_action.lua:1>, client: 10.135.192.59, server: localhost, request: "GET /ab_admin HTTP/1.1", host: "10.137.86.126:8020"

关于依赖软件这块的文档提个建议

1、首先文档上写着:建议选用openresty最新版,但是从openresty-1.9.15.1开始,lua-resty-core有些api变更,因此建议先使用openresty-1.9.7.5及以下。这句话让人很糊涂,先说让用最新版,后说建议先使用openresty-1.9.7.5及以下,容易让人误解。我在准备环境的时候安装的是openresty-1.9.7.5。
2、我按照文档上的步骤执行utils下的demo,到第9步开始遇到 #48 ,然后我按照 #27 中提供的解决方案,我先是把Luajit替换成openresty维护的版本,然后从/usr/local/oprensty/lualib中将ngx和resty目录 copy 到ABTestingGateway的lib/lua-resty-core目录下替换,仍旧报 #48 ,我现在迷糊了。
3、建议依赖的软件指定具体的版本号, #48 问题建议在readme中给出能用的解决方案。

灰度发布智能分流引擎 Regal

  • Hello, Due

    我看了你们的项目,觉得非常的酷,新浪的技术确实闻名于业界;

    我自己也有一个和灰度发布有关的项目(中间件)Regal,有时间的话,可以交流一下

upstream支持多个服务配置吗

满足策略后跳转的这些配置服务器
upstream beta2 {
keepalive 1000;
server server1:8021,server2:8021;
}
如上所示,满足beta2的策略走 下面连个server

如何在网站里加入自定义的'X-Uid:30'请求头?

我用的是golang开发的后端服务器,现在实例里面都是通过 curl 请求的测试是可以通过的,但是不知道怎么添加自定义的请求头?
有什么方法可以为网页添加自定义的请求头?

Redis集群支持么?

我们现在也准备做AB Test,但是我们这边只让用Redis集群,我们这个项目支持么?

分流功能和设定功能的分开

还是想问一下:
为什么没有考虑把分流功能和设定功能完全分开;
因为我可能有很多的域名,没必要每个域名都配置location = /admin/policy/set之类的;
就是有一种设想,使用redis当中间数据库,ABTestingGateway这个应用只是一个读库来分流。使用另一个单独的应用,直接操作redis数据库来配置整个ABTestingGateway各个域名的策略。

大家好,我对灰度系统进行了重构

大家好,我对灰度系统进行了重构,主要是添加了router、优化了代码结构、优化代码风格,采用模块化设计,在develop分之。目前唯一的缺陷是压测性能略低于现有master分支,另外是router的加入导致的api改变,所以大家有兴趣的话可以试用下。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.