coren has submitted this change and it was merged.
Change subject: dynamicproxy: Add URL based router
......................................................................
dynamicproxy: Add URL based router
Change-Id: I8f02a909c21138724924fed44033a42f99b92114
---
R modules/dynamicproxy/files/domainproxy.lua
A modules/dynamicproxy/files/urlproxy.lua
M modules/dynamicproxy/manifests/init.pp
M modules/toollabs/manifests/proxy.pp
4 files changed, 47 insertions(+), 3 deletions(-)
Approvals:
coren: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/dynamicproxy/files/proxy.lua
b/modules/dynamicproxy/files/domainproxy.lua
similarity index 100%
rename from modules/dynamicproxy/files/proxy.lua
rename to modules/dynamicproxy/files/domainproxy.lua
diff --git a/modules/dynamicproxy/files/urlproxy.lua
b/modules/dynamicproxy/files/urlproxy.lua
new file mode 100644
index 0000000..75d43f8
--- /dev/null
+++ b/modules/dynamicproxy/files/urlproxy.lua
@@ -0,0 +1,42 @@
+-- Lua file run by nginx that does appropriate routing
+
+local redis = require 'resty.redis'
+local red = redis:new()
+red:set_timeout(1000)
+
+red:connect('127.0.0.1', 6379)
+
+local captures = ngx.re.match(ngx.var.uri, "^/([^/]*)(/.*)?")
+
+if captures == ngx.null then
+ -- This would actually never happen, I'd think.
+ ngx.exit(404)
+end
+
+local prefix = captures[1]
+local rest = captures[2]
+
+if rest == nil then
+ -- Handle cases when there is nothing at all after the prefix
+ -- if we get /example, we will treat it as /example/
+ -- Ideally wer redirect here, to prevent fragmentation
+ rest = '/'
+end
+
+local routes_arr = red:hgetall('prefix:' .. prefix)
+
+if routes_arr == ngx.null then
+ -- No routes defined for this
+ ngx.exit(404)
+end
+
+local routes = red:array_to_hash(routes_arr)
+
+for pattern, backend in pairs(routes) do
+ if ngx.re.match(rest, pattern) ~= nil then
+ ngx.var.backend = backend
+ ngx.exit(ngx.OK)
+ end
+end
+
+ngx.exit(404) -- We didn't find any matches!
diff --git a/modules/dynamicproxy/manifests/init.pp
b/modules/dynamicproxy/manifests/init.pp
index 1056f34..0ec8b6e 100644
--- a/modules/dynamicproxy/manifests/init.pp
+++ b/modules/dynamicproxy/manifests/init.pp
@@ -1,7 +1,8 @@
class dynamicproxy (
$redis_maxmemory="512MB",
$ssl_certificate_name=false,
- $notfound_servers=[]
+ $notfound_servers=[],
+ $luahandler="domainproxy.lua"
) {
class { '::redis':
persist => "aof",
@@ -35,7 +36,7 @@
file { '/etc/nginx/lua/proxy.lua':
ensure => 'file',
- source => 'puppet:///modules/dynamicproxy/proxy.lua',
+ source => "puppet:///modules/dynamicproxy/$luahandler",
require => File['/etc/nginx/lua'],
notify => Service['nginx']
}
diff --git a/modules/toollabs/manifests/proxy.pp
b/modules/toollabs/manifests/proxy.pp
index 6d68608..f6b4c4b 100644
--- a/modules/toollabs/manifests/proxy.pp
+++ b/modules/toollabs/manifests/proxy.pp
@@ -9,6 +9,7 @@
]
class { '::dynamicproxy':
- notfound_servers => $apaches
+ notfound_servers => $apaches,
+ luahandler => 'urlproxy.lua'
}
}
--
To view, visit https://gerrit.wikimedia.org/r/97690
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8f02a909c21138724924fed44033a42f99b92114
Gerrit-PatchSet: 7
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Yuvipanda <[email protected]>
Gerrit-Reviewer: coren <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits