Skip to content

Commit

Permalink
Adding database stats into status endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco committed Oct 16, 2015
1 parent 92a37c8 commit 21d77a5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
## [Unreleased][unreleased]

### Added

- Added a `total` field in API responses, that counts the total number of entities in the table. [#635](https://github.com/Mashape/kong/pull/635)

### Changed

- The `/status` endpoint now includes `database` statistics, while the previous stats have been moved to a `server` field. [#635](https://github.com/Mashape/kong/pull/635)

### Fixed

- In the API, the `next` link is not being displayed anymore if there are no more entities to return. [#635](https://github.com/Mashape/kong/pull/635)

## [0.5.1] - 2015/10/13

Fixing a few glitches we let out with 0.5.0!
Expand Down
16 changes: 15 additions & 1 deletion kong/api/routes/kong.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,21 @@ return {
GET = function(self, dao, helpers)
local res = ngx.location.capture("/nginx_status")
if res.status == 200 then
return helpers.responses.send_HTTP_OK(route_helpers.parse_status(res.body))

local status_response = {
server = route_helpers.parse_status(res.body),
database = {}
}

for k, v in pairs(dao.daos) do
local count, err = v:count_by_keys()
if err then
return helpers.responses.send_HTTP_INTERNAL_SERVER_ERROR(err)
end
status_response.database[k] = count
end

return helpers.responses.send_HTTP_OK(status_response)
else
return helpers.responses.send_HTTP_INTERNAL_SERVER_ERROR(res.body)
end
Expand Down
28 changes: 20 additions & 8 deletions spec/integration/admin_api/kong_routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ local json = require "cjson"
local http_client = require "kong.tools.http_client"
local spec_helper = require "spec.spec_helpers"
local utils = require "kong.tools.utils"
local env = spec_helper.get_env() -- test environment
local dao_factory = env.dao_factory

describe("Admin API", function()

Expand Down Expand Up @@ -60,15 +62,25 @@ describe("Admin API", function()
assert.are.equal(200, status)
local body = json.decode(response)
assert.truthy(body)
assert.are.equal(2, utils.table_size(body))

assert.are.equal(7, utils.table_size(body))
assert.truthy(body.connections_accepted)
assert.truthy(body.connections_active)
assert.truthy(body.connections_handled)
assert.truthy(body.connections_reading)
assert.truthy(body.connections_writing)
assert.truthy(body.connections_waiting)
assert.truthy(body.total_requests)
-- Database stats
-- Removing migrations DAO
dao_factory.daos.migrations = nil
assert.are.equal(utils.table_size(dao_factory.daos), utils.table_size(body.database))
for k, _ in pairs(dao_factory.daos) do
assert.truthy(body.database[k])
end

-- Server stats
assert.are.equal(7, utils.table_size(body.server))
assert.truthy(body.server.connections_accepted)
assert.truthy(body.server.connections_active)
assert.truthy(body.server.connections_handled)
assert.truthy(body.server.connections_reading)
assert.truthy(body.server.connections_writing)
assert.truthy(body.server.connections_waiting)
assert.truthy(body.server.total_requests)
end)
end)
end)

0 comments on commit 21d77a5

Please sign in to comment.