Merge pull request #37 from openwhisk/develop
Health checks and debug info
diff --git a/Makefile b/Makefile
index 8f8f827..5fadbc8 100644
--- a/Makefile
+++ b/Makefile
@@ -2,11 +2,11 @@
DOCKER_REGISTRY ?= ''
docker:
- docker build -t apicgw/apigateway .
+ docker build -t openwhisk/apigateway .
.PHONY: docker-ssh
docker-ssh:
- docker run -ti --entrypoint='bash' apicgw/apigateway:latest
+ docker run -ti --entrypoint='bash' openwhisk/apigateway:latest
.PHONY: test-build
test-build:
@@ -21,7 +21,7 @@
docker run --rm --name="apigateway" -p 80:80 -p ${PUBLIC_MANAGEDURL_PORT}:8080 -p 9000:9000 \
-e PUBLIC_MANAGEDURL_HOST=${PUBLIC_MANAGEDURL_HOST} -e PUBLIC_MANAGEDURL_PORT=${PUBLIC_MANAGEDURL_PORT} \
-e REDIS_HOST=${REDIS_HOST} -e REDIS_PORT=${REDIS_PORT} -e REDIS_PASS=${REDIS_PASS} \
- apicgw/apigateway:latest
+ openwhisk/apigateway:latest
.PHONY: docker-debug
docker-debug:
@@ -33,7 +33,7 @@
-p 80:80 -p 5000:5000 \
-e "LOG_LEVEL=info" -e "DEBUG=true" \
-v ${HOME}/tmp/apiplatform/apigateway/api-gateway-config/:/etc/api-gateway \
- apicgw/apigateway:latest ${DOCKER_ARGS}
+ openwhisk/apigateway:latest ${DOCKER_ARGS}
.PHONY: docker-reload
docker-reload:
@@ -50,8 +50,3 @@
docker stop apigateway
docker rm apigateway
-.PHONY: docker-push
-docker-push:
- docker tag -f apicgw/apigateway $(DOCKER_REGISTRY)/apicgw/apigateway:$(DOCKER_TAG)
- docker push $(DOCKER_REGISTRY)/apicgw/apigateway:$(DOCKER_TAG)
-
diff --git a/api-gateway-config/api-gateway.conf b/api-gateway-config/api-gateway.conf
index 42a4391..6fa29a9 100644
--- a/api-gateway-config/api-gateway.conf
+++ b/api-gateway-config/api-gateway.conf
@@ -30,6 +30,8 @@
env REDIS_PASS;
env PUBLIC_MANAGEDURL_HOST;
env PUBLIC_MANAGEDURL_PORT;
+env HOST;
+env PORT;
events {
use epoll;
diff --git a/api-gateway-config/conf.d/commons/common-headers.conf b/api-gateway-config/conf.d/commons/common-headers.conf
index 03eb963..a0b6706 100644
--- a/api-gateway-config/conf.d/commons/common-headers.conf
+++ b/api-gateway-config/conf.d/commons/common-headers.conf
@@ -55,4 +55,16 @@
# ------------------
set $proxy_forwarded_proto $http_x_forwarded_proto;
set_if_empty $proxy_forwarded_proto $scheme;
-proxy_set_header X-forwarded-Proto $proxy_forwarded_proto;
\ No newline at end of file
+proxy_set_header X-forwarded-Proto $proxy_forwarded_proto;
+
+# ---------------
+# X-Gateway-Host
+# ---------------
+set_by_lua_block $gateway_host {
+ local host = os.getenv("HOST")
+ local port = os.getenv("PORT")
+ if host ~= nil and port ~= nil then
+ return host .. ":" .. port
+ end
+}
+add_header X-Gateway-Host $gateway_host;
\ No newline at end of file
diff --git a/api-gateway-config/conf.d/managed_endpoints.conf b/api-gateway-config/conf.d/managed_endpoints.conf
index 3aee3c4..948d8b0 100644
--- a/api-gateway-config/conf.d/managed_endpoints.conf
+++ b/api-gateway-config/conf.d/managed_endpoints.conf
@@ -51,12 +51,16 @@
return 500 '{"code":$status, "message":"Oops. Something went wrong. Check your URI and try again."}\n';
}
- location /api {
+ location = /api {
content_by_lua '
ngx.say("You have hit the api gateway managed endpoints.")
';
}
+ location = /health {
+ proxy_pass http://0.0.0.0:9000/v1/health-check;
+ }
+
include /etc/api-gateway/managed_confs/*/*.conf;
}
@@ -149,4 +153,4 @@
# end
# ';
# }
-#}
\ No newline at end of file
+#}
diff --git a/api-gateway-config/scripts/lua/management.lua b/api-gateway-config/scripts/lua/management.lua
index 1024330..6859436 100644
--- a/api-gateway-config/scripts/lua/management.lua
+++ b/api-gateway-config/scripts/lua/management.lua
@@ -54,7 +54,7 @@
-- }
function _M.addAPI()
-- Open connection to redis or use one from connection pool
- local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
+ local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 10000)
-- Check for api id from uri and use existingAPI if it already exists in redis
local uri = string.gsub(ngx.var.request_uri, "?.*", "")
local existingAPI = checkURIForExisting(red, uri, "api")
@@ -232,7 +232,7 @@
--- Get all APIs in redis
function getAllAPIs()
- local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
+ local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 10000)
local res = redis.getAllAPIs(red)
redis.close(red)
local apiList = {}
@@ -249,7 +249,7 @@
--- Get API by its id
-- @param id of API
function getAPI(id)
- local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
+ local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 10000)
local api = redis.getAPI(red, id)
if api == nil then
request.err(404, utils.concatStrings({"Unknown api id ", id}))
@@ -262,7 +262,7 @@
--- Get belongsTo relation tenant
-- @param id id of API
function getAPITenant(id)
- local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
+ local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 10000)
local api = redis.getAPI(red, id)
if api == nil then
request.err(404, utils.concatStrings({"Unknown api id ", id}))
@@ -292,7 +292,7 @@
if id == nil then
request.err(400, "No id specified.")
end
- local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
+ local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 10000)
local api = redis.getAPI(red, id)
if api == nil then
request.err(404, utils.concatStrings({"Unknown API id ", id}))
@@ -331,7 +331,7 @@
-- }
function _M.addTenant()
-- Open connection to redis or use one from connection pool
- local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
+ local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 10000)
-- Check for tenant id and use existingTenant if it already exists in redis
local uri = string.gsub(ngx.var.request_uri, "?.*", "")
local existingTenant = checkURIForExisting(red, uri, "tenant")
@@ -402,7 +402,7 @@
--- Get all tenants in redis
function getAllTenants()
- local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
+ local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 10000)
local res = redis.getAllTenants(red)
redis.close(red)
local tenantList = {}
@@ -419,7 +419,7 @@
--- Get tenant by its id
-- @param id tenant id
function getTenant(id)
- local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
+ local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 10000)
local tenant = redis.getTenant(red, id)
if tenant == nil then
request.err(404, utils.concatStrings({"Unknown tenant id ", id }))
@@ -432,7 +432,7 @@
--- Get APIs associated with tenant
-- @param id tenant id
function getTenantAPIs(id)
- local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
+ local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 10000)
local res = redis.getAllAPIs(red)
redis.close(red)
local apiList = {}
@@ -486,7 +486,7 @@
--- Subscribe to redis
-- GET /v1/subscribe
function _M.subscribe()
- local redisGetClient = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
+ local redisGetClient = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 10000)
local redisSubClient = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
redis.subscribe(redisSubClient, redisGetClient)
ngx.exit(200)
@@ -515,7 +515,7 @@
-- Validate body and create redisKey
local redisKey = validateSubscriptionBody()
-- Open connection to redis or use one from connection pool
- local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
+ local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 10000)
redis.createSubscription(red, redisKey)
-- Add current redis connection in the ngx_lua cosocket connection pool
redis.close(red)
@@ -536,7 +536,7 @@
-- Validate body and create redisKey
local redisKey = validateSubscriptionBody()
-- Initialize and connect to redis
- local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
+ local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 10000)
-- Return if subscription doesn't exist
redis.deleteSubscription(red, redisKey)
-- Add current redis connection in the ngx_lua cosocket connection pool