Yuvipanda has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/97690


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
3 files changed, 36 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/90/97690/1

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..ca55b1f
--- /dev/null
+++ b/modules/dynamicproxy/files/urlproxy.lua
@@ -0,0 +1,33 @@
+-- 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
+   ngx.exit(404)
+end
+
+local prefix = captures[1]
+local rest = captures[2]
+
+local routes_arr = red:hgetall('prefix:' .. prefix)
+
+if routes_arr == ngx.null then
+    ngx.exit(404)
+end
+
+local routes = red:array_to_hash(routes_arr)
+
+for pattern, backend in pairs(routes) do
+   if ngx.re.find(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']
     }

-- 
To view, visit https://gerrit.wikimedia.org/r/97690
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8f02a909c21138724924fed44033a42f99b92114
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Yuvipanda <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to