Skip to content

Commit e05bf98

Browse files
committed
add more detail error logs and abandon upstream name being consistent with conf
1 parent a2d2b5d commit e05bf98

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ stream {
5252
server 127.0.0.1:11111;
5353
5454
# all backend server will pull from consul when startup and will delete fake server
55-
upsync 127.0.0.1:8500/v1/kv/upstreams/test upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;
55+
upsync 127.0.0.1:8500/v1/kv/upstreams/test/ upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;
5656
upsync_dump_path /usr/local/nginx/conf/servers/servers_test.conf;
5757
}
5858
@@ -91,7 +91,7 @@ stream {
9191
server 127.0.0.1:11111;
9292
9393
# all backend server will pull from etcd when startup and will delete fake server
94-
upsync 127.0.0.1:8500/v2/keys/upstreams/test upsync_timeout=6m upsync_interval=500ms upsync_type=etcd strong_dependency=off;
94+
upsync 127.0.0.1:2379/v2/keys/upstreams/test upsync_timeout=6m upsync_interval=500ms upsync_type=etcd strong_dependency=off;
9595
upsync_dump_path /usr/local/nginx/conf/servers/servers_test.conf;
9696
}
9797
@@ -130,8 +130,8 @@ stream {
130130
# fake server otherwise ngx_http_upstream will report error when startup
131131
server 127.0.0.1:11111;
132132
133-
# all backend server will pull from consul/etcf when startup and will delete fake server
134-
upsync 127.0.0.1:8500/v1/kv/upstreams/test upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;
133+
# all backend server will pull from consul/etcd when startup and will delete fake server
134+
upsync 127.0.0.1:8500/v1/kv/upstreams/test/ upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;
135135
upsync_dump_path /usr/local/nginx/conf/servers/servers_test.conf;
136136
upsync_lb least_conn; //hash_ketama;
137137
}
@@ -169,19 +169,19 @@ stream {
169169
Description
170170
======
171171

172-
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:
172+
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:
173173

174174
* timely
175175

176-
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.
176+
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.
177177

178178
* performance
179179

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

182182
* stability
183183

184-
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.
184+
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.
185185

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

@@ -191,7 +191,7 @@ Diretives
191191
upsync
192192
-----------
193193
```
194-
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]
194+
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]
195195
```
196196
default: none, if parameters omitted, default parameters are upsync_interval=5s upsync_timeout=6m strong_dependency=off
197197

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

204204
* upsync_interval
205205

206-
pulling servers from consul interval time.
206+
pulling servers from consul/etcd interval time.
207207

208208
* upsync_timeout
209209

210-
pulling servers from consul request timeout.
210+
pulling servers from consul/etcd request timeout.
211211

212212
* upsync_type
213213

214214
pulling servers from conf server type.
215215

216216
* strong_dependency
217217

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

220220

221221
upsync_dump_path
@@ -309,11 +309,11 @@ Etcd_interface
309309

310310
you can add or delete backend server through http_interface.
311311

312-
mainly like consul, http_interface example:
312+
mainly like etcd, http_interface example:
313313

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

src/ngx_stream_upsync_module.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,9 +1545,9 @@ ngx_stream_upsync_etcd_parse_json(void *data)
15451545
static ngx_int_t
15461546
ngx_stream_upsync_check_key(u_char *key, ngx_str_t host)
15471547
{
1548-
u_char *last, *ip_p, *port_p, *u_p, *s_p;
1548+
u_char *last, *ip_p, *port_p, *s_p; // *u_p;
15491549
ngx_int_t port;
1550-
1550+
/*
15511551
u_p = (u_char *)ngx_strstr(key, host.data);
15521552
if (u_p == NULL) {
15531553
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
@@ -1558,7 +1558,7 @@ ngx_stream_upsync_check_key(u_char *key, ngx_str_t host)
15581558
if (*(u_p + host.len) != '/' || *(u_p - 1) != '/') {
15591559
return NGX_ERROR;
15601560
}
1561-
1561+
*/
15621562
s_p = (u_char *)ngx_strrchr(key, '/');
15631563
if (s_p == NULL) {
15641564
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
@@ -2022,7 +2022,8 @@ ngx_stream_upsync_init_process(ngx_cycle_t *cycle)
20222022
pool = ngx_create_pool(NGX_DEFAULT_POOL_SIZE, ngx_cycle->log);
20232023
if (pool == NULL) {
20242024
ngx_log_error(NGX_LOG_ERR, cycle->log, 0,
2025-
"upsync_init_process: recv not enough memory");
2025+
"upsync_init_process: recv error, "
2026+
"server no enough memory");
20262027
return NGX_ERROR;
20272028
}
20282029
ctx->pool = pool;
@@ -2037,7 +2038,8 @@ ngx_stream_upsync_init_process(ngx_cycle_t *cycle)
20372038

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

20422044
if (upsync_server[i].upscf->strong_dependency == 0) {
20432045
ngx_stream_upsync_parse_dump_file(&upsync_server[i]);
@@ -2316,7 +2318,9 @@ ngx_stream_upsync_parse_dump_file(ngx_stream_upsync_server_t *upsync_server)
23162318
if (ngx_stream_upsync_add_peers((ngx_cycle_t *)ngx_cycle,
23172319
upsync_server) != NGX_OK) {
23182320
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
2319-
"upsync_parse_dump_file: upstream add server error");
2321+
"upsync_parse_dump_file: "
2322+
"upstream add \"%V\" server error",
2323+
&upsync_server->host);
23202324
return NGX_ERROR;
23212325
}
23222326
}
@@ -2327,7 +2331,9 @@ ngx_stream_upsync_parse_dump_file(ngx_stream_upsync_server_t *upsync_server)
23272331
if (ngx_stream_upsync_del_peers((ngx_cycle_t *)ngx_cycle,
23282332
upsync_server) != NGX_OK) {
23292333
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
2330-
"upsync_parse_dump_file: upstream del server error");
2334+
"upsync_parse_dump_file: "
2335+
"upstream del \"%V\" server error",
2336+
&upsync_server->host);
23312337
return NGX_ERROR;
23322338
}
23332339
}
@@ -2666,8 +2672,10 @@ ngx_stream_upsync_recv_handler(ngx_event_t *event)
26662672

26672673
upsync_recv_fail:
26682674
ngx_log_error(NGX_LOG_ERR, event->log, 0,
2669-
"upsync_recv: recv error with upsync_server: %V",
2670-
upsync_server->pc.name);
2675+
"upsync_recv: recv error with upsync_server: %V, "
2676+
"upstream info : %V",
2677+
upsync_server->pc.name,
2678+
&upsync_server->upscf->upsync_send);
26712679

26722680
ngx_stream_upsync_clean_event(upsync_server);
26732681
}

0 commit comments

Comments
 (0)