forked from cep21/healthcheck_nginx_upstreams
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx.patch
176 lines (150 loc) · 6.76 KB
/
nginx.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
diff -ru nginx-1.0.10/src/http/ngx_http_upstream.c nginx-1.0.10-patched/src/http/ngx_http_upstream.c
--- nginx-1.0.10/src/http/ngx_http_upstream.c 2011-11-01 10:18:10.000000000 -0400
+++ nginx-1.0.10-patched/src/http/ngx_http_upstream.c 2011-11-30 20:34:10.000000000 -0500
@@ -4293,6 +4293,17 @@
uscf->line = cf->conf_file->line;
uscf->port = u->port;
uscf->default_port = u->default_port;
+#if (NGX_HTTP_HEALTHCHECK)
+ uscf->healthcheck_enabled = 0;
+ uscf->health_delay = 10000;
+ uscf->health_timeout = 2000;
+ uscf->health_failcount = 2;
+ uscf->health_buffersize = 1000;
+ uscf->health_send.data = (u_char*)"";
+ uscf->health_send.len = 0;
+ uscf->health_expected.len = NGX_CONF_UNSET_SIZE;
+ uscf->health_expected.data = NGX_CONF_UNSET_PTR;
+#endif
if (u->naddrs == 1) {
uscf->servers = ngx_array_create(cf->pool, 1,
Only in nginx-1.0.10-patched/src/http: ngx_http_upstream.c.orig
diff -ru nginx-1.0.10/src/http/ngx_http_upstream.h nginx-1.0.10-patched/src/http/ngx_http_upstream.h
--- nginx-1.0.10/src/http/ngx_http_upstream.h 2011-11-01 10:18:10.000000000 -0400
+++ nginx-1.0.10-patched/src/http/ngx_http_upstream.h 2011-11-30 20:34:10.000000000 -0500
@@ -109,6 +109,24 @@
ngx_array_t *servers; /* ngx_http_upstream_server_t */
+#if (NGX_HTTP_HEALTHCHECK)
+ // If true, healthchecking is enabled for this upstream
+ unsigned healthcheck_enabled:1;
+ // Delay between healthchecks (in sec)
+ time_t health_delay;
+ // Total time a healthcheck is allowed to execute
+ ngx_msec_t health_timeout;
+ // Number of good/bad results indicate the node is up/down
+ ngx_int_t health_failcount;
+ // Size of the body+headers buffer
+ ngx_int_t health_buffersize;
+ // What is sent to initiate the healthcheck
+ ngx_str_t health_send;
+ // Expected from healthcheck, excluding headers
+ ngx_str_t health_expected;
+#endif
+
+
ngx_uint_t flags;
ngx_str_t host;
u_char *file_name;
Only in nginx-1.0.10-patched/src/http: ngx_http_upstream.h.orig
diff -ru nginx-1.0.10/src/http/ngx_http_upstream_round_robin.c nginx-1.0.10-patched/src/http/ngx_http_upstream_round_robin.c
--- nginx-1.0.10/src/http/ngx_http_upstream_round_robin.c 2011-09-30 10:30:01.000000000 -0400
+++ nginx-1.0.10-patched/src/http/ngx_http_upstream_round_robin.c 2011-11-30 20:34:10.000000000 -0500
@@ -4,6 +4,8 @@
*/
+/* on top, so it won't collide with ngx_supervisord's patch */
+#include <ngx_http_healthcheck_module.h>
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
@@ -12,7 +14,8 @@
static ngx_int_t ngx_http_upstream_cmp_servers(const void *one,
const void *two);
static ngx_uint_t
-ngx_http_upstream_get_peer(ngx_http_upstream_rr_peers_t *peers);
+ngx_http_upstream_get_peer(ngx_http_upstream_rr_peers_t *peers,
+ ngx_log_t * log);
#if (NGX_HTTP_SSL)
@@ -32,6 +35,7 @@
ngx_uint_t i, j, n;
ngx_http_upstream_server_t *server;
ngx_http_upstream_rr_peers_t *peers, *backup;
+ ngx_int_t health_index;
us->peer.init = ngx_http_upstream_init_round_robin_peer;
@@ -66,6 +70,14 @@
continue;
}
+ /* on top, so it won't collide with ngx_supervisord's patch */
+ health_index = ngx_http_healthcheck_add_peer(us,
+ &server[i].addrs[j], cf->pool);
+ if (health_index == NGX_ERROR) {
+ return NGX_ERROR;
+ }
+ peers->peer[n].health_index = health_index;
+
peers->peer[n].sockaddr = server[i].addrs[j].sockaddr;
peers->peer[n].socklen = server[i].addrs[j].socklen;
peers->peer[n].name = server[i].addrs[j].name;
@@ -377,6 +389,7 @@
ngx_connection_t *c;
ngx_http_upstream_rr_peer_t *peer;
ngx_http_upstream_rr_peers_t *peers;
+ ngx_int_t healthy;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
"get rr peer, try: %ui", pc->tries);
@@ -422,7 +435,7 @@
i = pc->tries;
for ( ;; ) {
- rrp->current = ngx_http_upstream_get_peer(rrp->peers);
+ rrp->current = ngx_http_upstream_get_peer(rrp->peers, pc->log);
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0,
"get rr peer, current: %ui %i",
@@ -483,7 +496,11 @@
peer = &rrp->peers->peer[rrp->current];
- if (!peer->down) {
+ healthy = !ngx_http_healthcheck_is_down(
+ peer->health_index,
+ pc->log);
+
+ if ((!peer->down) && healthy) {
if (peer->max_fails == 0
|| peer->fails < peer->max_fails)
@@ -588,12 +605,14 @@
static ngx_uint_t
-ngx_http_upstream_get_peer(ngx_http_upstream_rr_peers_t *peers)
+ngx_http_upstream_get_peer(ngx_http_upstream_rr_peers_t *peers, ngx_log_t *log)
{
ngx_uint_t i, n, reset = 0;
ngx_http_upstream_rr_peer_t *peer;
+ ngx_uint_t health_check_rounds;
peer = &peers->peer[0];
+ health_check_rounds = 2;
for ( ;; ) {
@@ -613,6 +632,11 @@
continue;
}
+ if (health_check_rounds && ngx_http_healthcheck_is_down(
+ peer[i].health_index,
+ log))
+ continue;
+
if (peer[n].current_weight * 1000 / peer[i].current_weight
> peer[n].weight * 1000 / peer[i].weight)
{
@@ -633,6 +657,9 @@
return 0;
}
+ if (health_check_rounds)
+ --health_check_rounds;
+
for (i = 0; i < peers->number; i++) {
peer[i].current_weight = peer[i].weight;
}
Only in nginx-1.0.10-patched/src/http: ngx_http_upstream_round_robin.c.orig
diff -ru nginx-1.0.10/src/http/ngx_http_upstream_round_robin.h nginx-1.0.10-patched/src/http/ngx_http_upstream_round_robin.h
--- nginx-1.0.10/src/http/ngx_http_upstream_round_robin.h 2009-11-02 07:41:56.000000000 -0500
+++ nginx-1.0.10-patched/src/http/ngx_http_upstream_round_robin.h 2011-11-30 20:34:10.000000000 -0500
@@ -26,6 +26,7 @@
ngx_uint_t max_fails;
time_t fail_timeout;
+ ngx_int_t health_index;
ngx_uint_t down; /* unsigned down:1; */