Yuvipanda has submitted this change and it was merged.
Change subject: dynamicproxy: Provide list of active proxy entries for urlproxy
......................................................................
dynamicproxy: Provide list of active proxy entries for urlproxy
This requires 1.3.2 of lua-json at least because 1.3.1 is broken.
Bug: T88216
Bug: T91484
Change-Id: If802aa35679ef07153288c9cfb140974b4d79bf7
---
A modules/dynamicproxy/files/list-proxy-entries.lua
M modules/dynamicproxy/manifests/init.pp
A modules/dynamicproxy/templates/proxymanager.conf.erb
M modules/dynamicproxy/templates/urlproxy.conf
4 files changed, 59 insertions(+), 1 deletion(-)
Approvals:
Yuvipanda: Verified; Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/dynamicproxy/files/list-proxy-entries.lua
b/modules/dynamicproxy/files/list-proxy-entries.lua
new file mode 100644
index 0000000..6890d22
--- /dev/null
+++ b/modules/dynamicproxy/files/list-proxy-entries.lua
@@ -0,0 +1,20 @@
+-- Connect to Redis database.
+local redis = require('resty.redis')
+local red = redis:new()
+red:set_timeout(1000)
+red:connect('127.0.0.1', 6379)
+
+-- Return list of proxy entries.
+local json = require('json')
+ngx.header['Content-Type'] = 'application/json'
+local proxy_entries = red:keys('prefix:*')
+local result = {}
+for k, v in pairs(proxy_entries) do
+ result[string.sub(v, string.len('prefix:') + 1)] = {['status']='active'}
+end
+
+-- Use a connection pool of 256 connections with a 32s idle timeout
+-- This also closes the current redis connection.
+red:set_keepalive(1000 * 32, 256)
+
+ngx.say(json.encode(result))
diff --git a/modules/dynamicproxy/manifests/init.pp
b/modules/dynamicproxy/manifests/init.pp
index 9fcffac..2f09f9a 100644
--- a/modules/dynamicproxy/manifests/init.pp
+++ b/modules/dynamicproxy/manifests/init.pp
@@ -78,6 +78,24 @@
notify => Service['nginx'],
}
+ if $luahandler == 'urlproxy' {
+ file { '/etc/nginx/lua/list-proxy-entries.lua':
+ ensure => 'file',
+ source => 'puppet:///modules/dynamicproxy/list-proxy-entries.lua',
+ require => [File['/etc/nginx/lua'], Package['liblua5.1-json']],
+ notify => Service['nginx'],
+ }
+
+ package { 'liblua5.1-json':
+ ensure => installed,
+ }
+
+ nginx::site { 'proxymanager':
+ content => template("dynamicproxy/proxymanager.conf.erb"),
+ require => File['/etc/nginx/lua/list-proxy-entries.lua'],
+ }
+ }
+
file { '/etc/nginx/lua/resty':
ensure => directory,
require => File['/etc/nginx/lua'],
diff --git a/modules/dynamicproxy/templates/proxymanager.conf.erb
b/modules/dynamicproxy/templates/proxymanager.conf.erb
new file mode 100644
index 0000000..5723295
--- /dev/null
+++ b/modules/dynamicproxy/templates/proxymanager.conf.erb
@@ -0,0 +1,20 @@
+server {
+ resolver <%= resolver %>;
+
+ listen 8081;
+
+ # The proxy services should only be available to Labs clients.
+ allow 10.0.0.0/8;
+ allow 127.0.0.0/0;
+ deny all;
+
+ # Provide a list of active proxy entries.
+ location = /list {
+ content_by_lua_file /etc/nginx/lua/list-proxy-entries.lua;
+ }
+
+ # Suppress default nginx page
+ location / {
+ return 404 "Page not found\n";
+ }
+}
diff --git a/modules/dynamicproxy/templates/urlproxy.conf
b/modules/dynamicproxy/templates/urlproxy.conf
index 9f334ca..e8615cd 100644
--- a/modules/dynamicproxy/templates/urlproxy.conf
+++ b/modules/dynamicproxy/templates/urlproxy.conf
@@ -12,7 +12,7 @@
#See the License for the specific language governing permissions and
#limitations under the License.
-lua_package_path "/etc/nginx/lua/?.lua";
+lua_package_path "/etc/nginx/lua/?.lua;;";
map $http_upgrade $connection_upgrade {
default upgrade;
--
To view, visit https://gerrit.wikimedia.org/r/203313
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If802aa35679ef07153288c9cfb140974b4d79bf7
Gerrit-PatchSet: 4
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Tim Landscheidt <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: Tim Landscheidt <[email protected]>
Gerrit-Reviewer: Yuvipanda <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits