Skip to content

Commit

Permalink
add more detail error logs and abandon upstream name being consistent…
Browse files Browse the repository at this point in the history
… with conf
  • Loading branch information
xiaokai-wang committed Jul 2, 2017
1 parent a2d2b5d commit e05bf98
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ stream {
server 127.0.0.1:11111;
# all backend server will pull from consul when startup and will delete fake server
upsync 127.0.0.1:8500/v1/kv/upstreams/test upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;
upsync 127.0.0.1:8500/v1/kv/upstreams/test/ upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;
upsync_dump_path /usr/local/nginx/conf/servers/servers_test.conf;
}
Expand Down Expand Up @@ -91,7 +91,7 @@ stream {
server 127.0.0.1:11111;
# all backend server will pull from etcd when startup and will delete fake server
upsync 127.0.0.1:8500/v2/keys/upstreams/test upsync_timeout=6m upsync_interval=500ms upsync_type=etcd strong_dependency=off;
upsync 127.0.0.1:2379/v2/keys/upstreams/test upsync_timeout=6m upsync_interval=500ms upsync_type=etcd strong_dependency=off;
upsync_dump_path /usr/local/nginx/conf/servers/servers_test.conf;
}
Expand Down Expand Up @@ -130,8 +130,8 @@ stream {
# fake server otherwise ngx_http_upstream will report error when startup
server 127.0.0.1:11111;
# all backend server will pull from consul/etcf when startup and will delete fake server
upsync 127.0.0.1:8500/v1/kv/upstreams/test upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;
# all backend server will pull from consul/etcd when startup and will delete fake server
upsync 127.0.0.1:8500/v1/kv/upstreams/test/ upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;
upsync_dump_path /usr/local/nginx/conf/servers/servers_test.conf;
upsync_lb least_conn; //hash_ketama;
}
Expand Down Expand Up @@ -169,19 +169,19 @@ stream {
Description
======

This module provides a method to discover backend servers. Supporting dynamicly adding or deleting backend server through consul and dynamicly adjusting backend servers weight, module will timely pull new backend server list from consul/etcd to upsync nginx ip router. Nginx needn't reload. Having some advantages than others:
This module provides a method to discover backend servers. Supporting dynamicly adding or deleting backend server through consul/etcd and dynamicly adjusting backend servers weight, module will timely pull new backend server list from consul/etcd to upsync nginx ip router. Nginx needn't reload. Having some advantages than others:

* timely

module send key to consul with index, consul will compare it with its index, if index doesn't change connection will hang five minutes, in the period any operation to the key-value, will feed back rightaway.
module send key to consul/etcd with index, consul/etcd will compare it with its index, if index doesn't change connection will hang five minutes, in the period any operation to the key-value, will feed back rightaway.

* performance

Pulling from consul equal a request to nginx, updating ip router nginx needn't reload, so affecting nginx performance is little.
Pulling from consul/etcd equal a request to nginx, updating ip router nginx needn't reload, so affecting nginx performance is little.

* stability

Even if one pulling failed, it will pull next upsync_interval, so guaranteing backend server stably provides service. And support dumping the latest config to location, so even if consul hung up, and nginx can be reload anytime.
Even if one pulling failed, it will pull next upsync_interval, so guaranteing backend server stably provides service. And support dumping the latest config to location, so even if consul/etcd hung up, and nginx can be reload anytime.

[Back to TOC](#table-of-contents)

Expand All @@ -191,7 +191,7 @@ Diretives
upsync
-----------
```
syntax: upsync $consul.api.com:$port/v1/kv/upstreams/$upstream_name [upsync_type=consul] [upsync_interval=second/minutes] [upsync_timeout=second/minutes] [strong_dependency=off/on]
syntax: upsync $consul/etcd.api.com:$port/v1/kv/upstreams/$upstream_name [upsync_type=consul/etcd] [upsync_interval=second/minutes] [upsync_timeout=second/minutes] [strong_dependency=off/on]
```
default: none, if parameters omitted, default parameters are upsync_interval=5s upsync_timeout=6m strong_dependency=off

Expand All @@ -203,19 +203,19 @@ The parameters' meanings are:

* upsync_interval

pulling servers from consul interval time.
pulling servers from consul/etcd interval time.

* upsync_timeout

pulling servers from consul request timeout.
pulling servers from consul/etcd request timeout.

* upsync_type

pulling servers from conf server type.

* strong_dependency

when nginx start up if depending on consul, and consul is not working, nginx will boot failed, otherwise booting normally.
when nginx start up if depending on consul/etcd, and consul/etcd is not working, nginx will boot failed, otherwise booting normally.


upsync_dump_path
Expand Down Expand Up @@ -309,11 +309,11 @@ Etcd_interface

you can add or delete backend server through http_interface.

mainly like consul, http_interface example:
mainly like etcd, http_interface example:

* add
```
curl -X PUT http://$consul_ip:$port/v2/keys/upstreams/$upstream_name/$backend_ip:$backend_port
curl -X PUT http://$etcd_ip:$port/v2/keys/upstreams/$upstream_name/$backend_ip:$backend_port
```
default: weight=1 max_fails=2 fail_timeout=10 down=0 backup=0;

Expand Down
26 changes: 17 additions & 9 deletions src/ngx_stream_upsync_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1545,9 +1545,9 @@ ngx_stream_upsync_etcd_parse_json(void *data)
static ngx_int_t
ngx_stream_upsync_check_key(u_char *key, ngx_str_t host)
{
u_char *last, *ip_p, *port_p, *u_p, *s_p;
u_char *last, *ip_p, *port_p, *s_p; // *u_p;
ngx_int_t port;

/*
u_p = (u_char *)ngx_strstr(key, host.data);
if (u_p == NULL) {
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
Expand All @@ -1558,7 +1558,7 @@ ngx_stream_upsync_check_key(u_char *key, ngx_str_t host)
if (*(u_p + host.len) != '/' || *(u_p - 1) != '/') {
return NGX_ERROR;
}

*/
s_p = (u_char *)ngx_strrchr(key, '/');
if (s_p == NULL) {
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
Expand Down Expand Up @@ -2022,7 +2022,8 @@ ngx_stream_upsync_init_process(ngx_cycle_t *cycle)
pool = ngx_create_pool(NGX_DEFAULT_POOL_SIZE, ngx_cycle->log);
if (pool == NULL) {
ngx_log_error(NGX_LOG_ERR, cycle->log, 0,
"upsync_init_process: recv not enough memory");
"upsync_init_process: recv error, "
"server no enough memory");
return NGX_ERROR;
}
ctx->pool = pool;
Expand All @@ -2037,7 +2038,8 @@ ngx_stream_upsync_init_process(ngx_cycle_t *cycle)

if (status != NGX_OK) {
ngx_log_error(NGX_LOG_ERR, cycle->log, 0,
"upsync_init_process: pull upstream conf failed");
"upsync_init_process: pull upstream \"%V\" conf failed",
&upsync_server->host);

if (upsync_server[i].upscf->strong_dependency == 0) {
ngx_stream_upsync_parse_dump_file(&upsync_server[i]);
Expand Down Expand Up @@ -2316,7 +2318,9 @@ ngx_stream_upsync_parse_dump_file(ngx_stream_upsync_server_t *upsync_server)
if (ngx_stream_upsync_add_peers((ngx_cycle_t *)ngx_cycle,
upsync_server) != NGX_OK) {
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
"upsync_parse_dump_file: upstream add server error");
"upsync_parse_dump_file: "
"upstream add \"%V\" server error",
&upsync_server->host);
return NGX_ERROR;
}
}
Expand All @@ -2327,7 +2331,9 @@ ngx_stream_upsync_parse_dump_file(ngx_stream_upsync_server_t *upsync_server)
if (ngx_stream_upsync_del_peers((ngx_cycle_t *)ngx_cycle,
upsync_server) != NGX_OK) {
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
"upsync_parse_dump_file: upstream del server error");
"upsync_parse_dump_file: "
"upstream del \"%V\" server error",
&upsync_server->host);
return NGX_ERROR;
}
}
Expand Down Expand Up @@ -2666,8 +2672,10 @@ ngx_stream_upsync_recv_handler(ngx_event_t *event)

upsync_recv_fail:
ngx_log_error(NGX_LOG_ERR, event->log, 0,
"upsync_recv: recv error with upsync_server: %V",
upsync_server->pc.name);
"upsync_recv: recv error with upsync_server: %V, "
"upstream info : %V",
upsync_server->pc.name,
&upsync_server->upscf->upsync_send);

ngx_stream_upsync_clean_event(upsync_server);
}
Expand Down

0 comments on commit e05bf98

Please sign in to comment.