Merge pull request #40 from apimesh/rate-limit-group

Implement API rate limit policy
diff --git a/Makefile b/Makefile
index 5755790..c1940d6 100644
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@
 
 .PHONY: docker-run-mgmt
 docker-run-mgmt:
-	docker run --rm --name="apigateway" -p 80:80 -p 5000:5000 -p 9000:9000 \
+	docker run --rm --name="apigateway" -p 80:80 -p 8080:8080 -p 9000:9000 \
 		-e REDIS_HOST=${REDIS_HOST} -e REDIS_PORT=${REDIS_PORT} -e REDIS_PASS=${REDIS_PASS} \
 		apicgw/apigateway:latest
 
diff --git a/README.md b/README.md
index 7422d19..6cf26b5 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@
 ===========
 
 ```
-docker run -p 80:80 -p 9000:9000 \
+docker run -p 80:80 -p 8080:8080 -p 9000:9000 \
             -e REDIS_HOST=<redis_host> \
             -e REDIS_PORT=<redis_port> \
             -e REDIS_PASS=<redis_pass> \
diff --git a/api-gateway-config/conf.d/default.conf b/api-gateway-config/conf.d/default.conf
index f9f9557..0a1a045 100644
--- a/api-gateway-config/conf.d/default.conf
+++ b/api-gateway-config/conf.d/default.conf
@@ -51,7 +51,4 @@
 
     # default locations exposed on the default VHost and port
     include /etc/api-gateway/conf.d/includes/*.conf;
-
-    # include managed locations
-    include /etc/api-gateway/managed_confs/*/*.conf;
 }
diff --git a/api-gateway-config/conf.d/management_apis.conf b/api-gateway-config/conf.d/management_apis.conf
index 1c13849..67fa490 100644
--- a/api-gateway-config/conf.d/management_apis.conf
+++ b/api-gateway-config/conf.d/management_apis.conf
@@ -25,9 +25,10 @@
     listen 9000;
     server_name management_gw;
 
-     # Log locations with service name
-     access_log /var/log/api-gateway/access.log platform;
-     error_log /var/log/api-gateway/mgmt_error.log debug;
+    # Log locations with service name
+    lua_socket_log_errors off;
+    access_log /var/log/api-gateway/access.log platform;
+    error_log /var/log/api-gateway/mgmt_error.log debug;
 
     location /resources {
         access_by_lua_block {
diff --git a/api-gateway-config/scripts/lua/lib/redis.lua b/api-gateway-config/scripts/lua/lib/redis.lua
index 8754aef..cec8d59 100644
--- a/api-gateway-config/scripts/lua/lib/redis.lua
+++ b/api-gateway-config/scripts/lua/lib/redis.lua
@@ -43,7 +43,17 @@
   red:set_timeout(timeout)
 
   -- Connect to Redis server
+  local retryCount = 4
   local connect, err = red:connect(host, port)
+  while not connect and retryCount > 0 do
+    local msg = utils.concatStrings({"Failed to conect to redis. Retrying ", retryCount, " more times."})
+    if retryCount == 1 then
+      msg = utils.concatStrings({msg:sub(1, -3), "."})
+    end
+    logger.info(msg)
+    retryCount = retryCount - 1
+    connect, err = red:connect(host, port)
+  end
   if not connect then
     ngx.status = 500
     ngx.say(utils.concatStrings({"Failed to connect to redis: ", err}))
diff --git a/api-gateway-config/scripts/lua/management.lua b/api-gateway-config/scripts/lua/management.lua
index 2c7c785..654b1d8 100644
--- a/api-gateway-config/scripts/lua/management.lua
+++ b/api-gateway-config/scripts/lua/management.lua
@@ -189,8 +189,8 @@
 --
 function _M.subscribe()
   -- Initialize and connect to redis
-  local redisSubClient = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 600000)
   local redisGetClient = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
+  local redisSubClient = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 60000) -- read_reply will timeout every minute
 
   logger.info(utils.concatStrings({"\nConnected to redis at ", REDIS_HOST, ":", REDIS_PORT}))
   redis.subscribe(redisSubClient, redisGetClient)