Permalink
Browse files

Job routerv2 becomes router. Create a job router_next for next-genera…

…tion router. Create package nginx_next for nginx 1.2.

Change-Id: I0fb31221dcbf402537bd9ab6bcee4fa6e49946ab
  • Loading branch information...
anferneeg
anferneeg committed Apr 11, 2012
1 parent 02d7dc3 commit d57285c7318d1d5025f3e434dd20287c2e11720f
View
@@ -7,9 +7,6 @@
[submodule "src/tools"]
path = src/tools
url = git@github.com:cloudfoundry/vcap-tools.git
-[submodule "src/core_routerv2"]
- path = src/core_routerv2
- url = git@github.com:cloudfoundry/vcap.git
[submodule "src/vblob_src"]
path = src/vblob_src
url = git@github.com:cloudfoundry/vblob.git
View
@@ -493,3 +493,16 @@ dashboard/dashboard-1.0-SNAPSHOT-ea587daf.war:
object_id: eyJvaWQiOiI0ZTRlNzhiY2ExMWUxMjEwMDRlNGU3ZDUxMWY4MjEwNGY5OWE2%0AZDdkYTRlNSIsInNpZyI6Ik4wdmltNHA4RkhuVXhTb2lhMmhpTkRnQ29Baz0i%0AfQ==%0A
sha: fd96a1dff68c13719ecfcc322afa5e5d398fa740
size: 16571890
+nginx/nginx-1.1.17.tar.gz:
+ object_id: eyJvaWQiOiI0ZTRlNzhiY2ExMWUxMjIyMDRlNGU5ODYzOGI3NjMwNGY2Y2Uy%0AMDZiNTI0NiIsInNpZyI6IitOWUdtQUNjWjA0VVdUT3BFcHZPdlBOeWlKWT0i%0AfQ==%0A
+ sha: 60c02ddc7e742d8aa959531f5a63684380e798e8
+nginx/nginx-lua.v0.4.1.tar.gz:
+ object_id: eyJvaWQiOiI0ZTRlNzhiY2E2MWUxMjEyMDRlNGU4NmVlYmU1OTEwNGY2Y2Uy%0AMTAxNjZlYSIsInNpZyI6IkhVNG5UWjNSbG8wZmIybDlRSnNCYk02MUNhQT0i%0AfQ==%0A
+ sha: fd37ffa48a618b2e521ea9797d13f523640fad4f
+nginx/pcre-8.21.tar.gz:
+ object_id: eyJvaWQiOiI0ZTRlNzhiY2EyMWUxMjIyMDRlNGU5ODYzOTI2YjEwNGY2Y2Uy%0AMTllZTYzOCIsInNpZyI6ImpUNkxCbkNnR09BTlBwbFEySE1NNVJ3bW9TWT0i%0AfQ==%0A
+ sha: dffb43eff9729c0999843a86ef97961b8c4f6ac8
+nginx/nginx-1.2.0.tar.gz:
+ object_id: eyJvaWQiOiI0ZTRlNzhiY2ExMWUxMjIwMDRlNGU4ZWM2NDg0MzEwNGZhMGE4%0AZDYxMTJmMiIsInNpZyI6InowZ1hkV1JOaWtpOUZhTndiTVFqVzZpdEdDND0i%0AfQ==%0A
+ sha: 15cec8d1b8dbf2007f9f99594a08a2f45814034e
+ size: 716067
View
@@ -2,16 +2,16 @@
name: router
templates:
- nginx_ctl: bin/nginx_ctl
- router_ctl: bin/router_ctl
- router.yml.erb: config/router.yml
- nginx.conf.erb: config/nginx.conf
- mime.types: config/mime.types
+ nginx_ctl: bin/nginx_ctl
+ router_ctl: bin/router_ctl
+ router.yml.erb: config/router.yml
+ nginx.conf.erb: config/nginx.conf
+ mime.types: config/mime.types
syslog_forwarder.conf.erb: config/syslog_forwarder.conf
packages:
- common
- router
- nginx
- ruby
- - syslog_aggregator
+ - syslog_aggregator
@@ -1,6 +1,7 @@
-<% require "base64" %>
+
user root root;
worker_processes 1;
+worker_rlimit_nofile 16384;
error_log /var/vcap/sys/log/nginx/nginx.error.log;
pid /var/vcap/sys/run/nginx/nginx.pid;
@@ -39,10 +40,6 @@ http {
client_max_body_size 256M;
- upstream router {
- server unix:/var/vcap/sys/run/router/router.sock;
- }
-
<% if properties.router.status %>
upstream router_status {
server <%= spec.networks.send(properties.networks.apps).ip %>:<%= properties.router.status.port %>;
@@ -54,6 +51,17 @@ http {
server_name "<%= properties.domain %>";
server_name_in_redirect off;
+ #TODO: how to make this internal location totally transparent to outside
+ location = /vcapuls {
+ internal;
+ # We should use rewrite_by_lua to scrub subrequest headers
+ # as uls doesn't care those headers at all.
+ # Given there are some exceptions to clear some headers,
+ # we just leave them as is.
+
+ proxy_pass http://unix:/var/vcap/sys/run/router/router.sock:/;
+ }
+
location / {
access_log /var/vcap/sys/log/nginx/router.access.log main;
proxy_buffering off;
@@ -64,6 +72,7 @@ http {
proxy_send_timeout <%= properties.router.client_inactivity_timeout || 30 %>;
proxy_read_timeout <%= properties.router.app_inactivity_timeout || 30 %>;
+ set $health_monitor '';
<% if properties.router.status %>
if ($http_user_agent = "HTTP-Monitor/1.1") {
set $health_monitor T;
@@ -72,13 +81,60 @@ http {
set $health_monitor "${health_monitor}T";
}
if ($health_monitor = TT) {
+ # Trigger a subrequest to sync the latest few stats of the worker to uls,
+ # if we have multiple workers, there will be still few stats not synced for
+ # the workers which don't get this monitor request.
+ access_by_lua '
+ local uls = require ("uls")
+ ngx.log(ngx.DEBUG, "monitor trigger stats syncup")
+
+ -- generate one subrequest to uls to update stats
+ ngx.location.capture(
+ "/vcapuls", {body = uls.generate_stats_request()}
+ )
+ ';
+
more_set_input_headers "Authorization: Basic <%= Base64.encode64("#{properties.router.status.user}:#{properties.router.status.password}").strip %>";
rewrite ^.*$ /healthz break;
proxy_pass http://router_status;
}
<% end %>
- proxy_pass http://router;
+ # We intend to have one "if" block to avoid the above monitor location
+ # to twist with below upstream locator server handling.
+ # ("if" block effectively creates a nested location and will inherit
+ # all the rewrite/access phase handlers of outer location)
+ if ($health_monitor != TT) {
+ # The following variables are used by lua module code.
+ # DO NOT remove or rename any of them!
+ set $backend_addr ''; # Backend server address returned from uls for this request
+ set $uls_req_tags ''; # Request tags returned from uls for this request to catalog statistics
+ set $router_ip '';
+ set $timestamp 0;
+ set $trace '';
+ set $sticky '';
+
+ access_by_lua '
+ local uls = require ("uls")
+ uls.pre_process_subrequest(ngx, "<%= properties.router.trace_key or 22 %>")
+
+ -- generate one subrequest to uls for url query
+ local res = ngx.location.capture(
+ "/vcapuls", {body = uls.generate_uls_request(ngx)}
+ )
+
+ uls.post_process_subrequest(ngx, res)
+ ';
+
+ proxy_pass http://$backend_addr;
+
+ # Handling response from backend servers
+ header_filter_by_lua '
+ local uls = require ("uls")
+
+ uls.post_process_response(ngx)
+ ';
+ }
}
}
}
@@ -16,6 +16,9 @@ case $1 in
echo $$ > $PIDFILE
+ export LUA_PATH="/var/vcap/packages/router/router/ext/nginx/?.lua"
+ export LUA_CPATH="/var/vcap/packages/nginx/lib/?.so"
+
exec /var/vcap/packages/nginx/sbin/nginx \
-c /var/vcap/jobs/router/config/nginx.conf \
>>$LOG_DIR/nginx.stdout.log \
@@ -8,7 +8,7 @@ logging:
<% end %>
file: /var/vcap/sys/log/router/router.log
pid: /var/vcap/sys/run/router/router.pid
-index: <%= spec.index %>
+index: <%= properties.router.offset ? properties.router.offset + spec.index : spec.index %>
<% if properties.router.local_route %>
local_route: <%= properties.router.local_route %>
<% end %>
@@ -18,6 +18,3 @@ status:
user: <%= properties.router.status.user %>
password: <%= properties.router.status.password %>
<% end %>
-<% if properties.router.client_inactivity_timeout %>
-client_inactivity_timeout: <%= properties.router.client_inactivity_timeout %>
-<% end %>
@@ -2,10 +2,11 @@
export PATH=/var/vcap/packages/ruby/bin:$PATH
+CONF_DIR=/var/vcap/jobs/router/config
+
RUN_DIR=/var/vcap/sys/run/router
LOG_DIR=/var/vcap/sys/log/router
PIDFILE=$RUN_DIR/router.pid
-JOB_DIR=/var/vcap/jobs/router
source /var/vcap/packages/common/utils.sh
@@ -45,11 +46,11 @@ case $1 in
echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
<% if properties.syslog_aggregator %>
- /var/vcap/packages/syslog_aggregator/setup_syslog_forwarder.sh $JOB_DIR/config
+ /var/vcap/packages/syslog_aggregator/setup_syslog_forwarder.sh $CONF_DIR
<% end %>
exec /var/vcap/packages/router/bin/router \
- -c $JOB_DIR/config/router.yml \
+ -c /var/vcap/jobs/router/config/router.yml \
>>$LOG_DIR/router.stdout.log \
2>>$LOG_DIR/router.stderr.log
@@ -62,6 +63,7 @@ case $1 in
*)
echo "Usage: router_ctl {start|stop}"
+
;;
esac
View
@@ -0,0 +1,11 @@
+check process nginx
+ with pidfile /var/vcap/sys/run/nginx/nginx.pid
+ start program "/var/vcap/jobs/router_next/bin/nginx_ctl start"
+ stop program "/var/vcap/jobs/router_next/bin/nginx_ctl stop"
+ group vcap
+
+check process router
+ with pidfile /var/vcap/sys/run/router/router.pid
+ start program "/var/vcap/jobs/router_next/bin/router_ctl start"
+ stop program "/var/vcap/jobs/router_next/bin/router_ctl stop"
+ group vcap
@@ -1,5 +1,5 @@
---
-name: routerv2
+name: router_next
templates:
nginx_ctl: bin/nginx_ctl
@@ -8,12 +8,10 @@ templates:
nginx.conf.erb: config/nginx.conf
mime.types: config/mime.types
syslog_forwarder.conf.erb: config/syslog_forwarder.conf
- uls.lua.erb: lib/uls.lua
- tablesave.lua: lib/tablesave.lua
packages:
- common
- - routerv2
- - nginx
+ - router
+ - nginx_next
- ruby
- syslog_aggregator
Oops, something went wrong.

0 comments on commit d57285c

Please sign in to comment.