Skip to content

Commit

Permalink
Revert "Merge pull request Kong#272 from Mashape/feature/plugin/apian…
Browse files Browse the repository at this point in the history
…alytics"

This reverts commit aa08ba9 [formerly 5f9fc30ac9670dc02177b330f2916d5fec56eb1e], reversing
changes made to 06296d1 [formerly 0e5b1b6506abd530b5a3ded139cf82eaae19b4a3].


Former-commit-id: e757ee9542753fb63990204d257768c238cb5bc8
  • Loading branch information
thibaultcha committed Jun 4, 2015
1 parent 8754b9d commit 44bf3e9
Show file tree
Hide file tree
Showing 25 changed files with 78 additions and 684 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ before_install:
- bash .travis/setup_cassandra.sh

install:
- sudo make install
- sudo make dev
- sudo sed -i.bak s@/usr/local/bin/luajit@/usr/bin/lua@g /usr/local/bin/busted

Expand Down
7 changes: 1 addition & 6 deletions kong-0.3.0-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ build = {
["kong.plugins.keyauth.schema"] = "kong/plugins/keyauth/schema.lua",
["kong.plugins.keyauth.api"] = "kong/plugins/keyauth/api.lua",

["kong.plugins.log_serializers.basic"] = "kong/plugins/log_serializers/basic.lua",
["kong.plugins.log_serializers.alf"] = "kong/plugins/log_serializers/alf.lua",

["kong.plugins.tcplog.handler"] = "kong/plugins/tcplog/handler.lua",
["kong.plugins.tcplog.log"] = "kong/plugins/tcplog/log.lua",
["kong.plugins.tcplog.schema"] = "kong/plugins/tcplog/schema.lua",
Expand All @@ -114,12 +111,10 @@ build = {
["kong.plugins.httplog.schema"] = "kong/plugins/httplog/schema.lua",

["kong.plugins.filelog.handler"] = "kong/plugins/filelog/handler.lua",
["kong.plugins.filelog.log"] = "kong/plugins/filelog/log.lua",
["kong.plugins.filelog.schema"] = "kong/plugins/filelog/schema.lua",
["kong.plugins.filelog.fd_util"] = "kong/plugins/filelog/fd_util.lua",

["kong.plugins.analytics.handler"] = "kong/plugins/analytics/handler.lua",
["kong.plugins.analytics.schema"] = "kong/plugins/analytics/schema.lua",

["kong.plugins.ratelimiting.handler"] = "kong/plugins/ratelimiting/handler.lua",
["kong.plugins.ratelimiting.access"] = "kong/plugins/ratelimiting/access.lua",
["kong.plugins.ratelimiting.schema"] = "kong/plugins/ratelimiting/schema.lua",
Expand Down
1 change: 0 additions & 1 deletion kong.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ plugins_available:
- request_transformer
- response_transformer
- requestsizelimiting
- analytics

## The Kong working directory
## (Make sure you have read and write permissions)
Expand Down
56 changes: 40 additions & 16 deletions kong/kong.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ local cache = require "kong.tools.database_cache"
local stringy = require "stringy"
local constants = require "kong.constants"
local responses = require "kong.tools.responses"
local timestamp = require "kong.tools.timestamp"

-- Define the plugins to load here, in the appropriate order
local plugins = {}
Expand Down Expand Up @@ -166,10 +167,10 @@ function _M.exec_plugins_certificate()
return
end

-- Calls plugins' access() on every loaded plugin
-- Calls plugins_access() on every loaded plugin
function _M.exec_plugins_access()
-- Setting a property that will be available for every plugin
ngx.ctx.started_at = ngx.req.start_time()
ngx.ctx.started_at = timestamp.get_utc()
ngx.ctx.plugin_conf = {}

-- Iterate over all the plugins
Expand All @@ -185,9 +186,9 @@ function _M.exec_plugins_access()
end
end

local plugin_conf = ngx.ctx.plugin_conf[plugin.name]
if not ngx.ctx.stop_phases and (plugin.resolver or plugin_conf) then
plugin.handler:access(plugin_conf and plugin_conf.value or nil)
local conf = ngx.ctx.plugin_conf[plugin.name]
if not ngx.ctx.stop_phases and (plugin.resolver or conf) then
plugin.handler:access(conf and conf.value or nil)
end
end

Expand All @@ -199,20 +200,20 @@ function _M.exec_plugins_access()
end
ngx.var.backend_url = final_url

ngx.ctx.proxy_started_at = ngx.now() -- Setting a property that will be available for every plugin
ngx.ctx.proxy_started_at = timestamp.get_utc() -- Setting a property that will be available for every plugin
end

-- Calls header_filter() on every loaded plugin
function _M.exec_plugins_header_filter()
ngx.ctx.proxy_ended_at = ngx.now() -- Setting a property that will be available for every plugin
ngx.ctx.proxy_ended_at = timestamp.get_utc() -- Setting a property that will be available for every plugin

if not ngx.ctx.stop_phases then
ngx.header["Via"] = constants.NAME.."/"..constants.VERSION

for _, plugin in ipairs(plugins) do
local plugin_conf = ngx.ctx.plugin_conf[plugin.name]
if plugin_conf then
plugin.handler:header_filter(plugin_conf.value)
local conf = ngx.ctx.plugin_conf[plugin.name]
if conf then
plugin.handler:header_filter(conf.value)
end
end
end
Expand All @@ -222,9 +223,9 @@ end
function _M.exec_plugins_body_filter()
if not ngx.ctx.stop_phases then
for _, plugin in ipairs(plugins) do
local plugin_conf = ngx.ctx.plugin_conf[plugin.name]
if plugin_conf then
plugin.handler:body_filter(plugin_conf.value)
local conf = ngx.ctx.plugin_conf[plugin.name]
if conf then
plugin.handler:body_filter(conf.value)
end
end
end
Expand All @@ -233,10 +234,33 @@ end
-- Calls log() on every loaded plugin
function _M.exec_plugins_log()
if not ngx.ctx.stop_phases then
-- Creating the log variable that will be serialized
local message = {
request = {
uri = ngx.var.request_uri,
request_uri = ngx.var.scheme.."://"..ngx.var.host..":"..ngx.var.server_port..ngx.var.request_uri,
querystring = ngx.req.get_uri_args(), -- parameters, as a table
method = ngx.req.get_method(), -- http method
headers = ngx.req.get_headers(),
size = ngx.var.request_length
},
response = {
status = ngx.status,
headers = ngx.resp.get_headers(),
size = ngx.var.bytes_sent
},
authenticated_entity = ngx.ctx.authenticated_entity,
api = ngx.ctx.api,
client_ip = ngx.var.remote_addr,
started_at = ngx.req.start_time() * 1000
}

ngx.ctx.log_message = message

for _, plugin in ipairs(plugins) do
local plugin_conf = ngx.ctx.plugin_conf[plugin.name]
if plugin_conf then
plugin.handler:log(plugin_conf.value)
local conf = ngx.ctx.plugin_conf[plugin.name]
if conf then
plugin.handler:log(conf.value)
end
end
end
Expand Down
163 changes: 0 additions & 163 deletions kong/plugins/analytics/handler.lua

This file was deleted.

6 changes: 0 additions & 6 deletions kong/plugins/analytics/schema.lua

This file was deleted.

4 changes: 3 additions & 1 deletion kong/plugins/filelog/handler.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
local log = require "kong.plugins.filelog.log"
-- Copyright (C) Mashape, Inc.

local BasePlugin = require "kong.plugins.base_plugin"
local log = require "kong.plugins.filelog.log"

local FileLogHandler = BasePlugin:extend()

Expand Down
10 changes: 3 additions & 7 deletions kong/plugins/filelog/log.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
-- Copyright (C) Mashape, Inc.

local ffi = require "ffi"
local cjson = require "cjson"
local ffi = require "ffi"
local fd_util = require "kong.plugins.filelog.fd_util"
local basic_serializer = require "kong.plugins.log_serializers.basic"

ffi.cdef[[
typedef struct {
Expand All @@ -26,7 +24,7 @@ int fprintf(FILE *stream, const char *format, ...);
-- @param `conf` Configuration table, holds http endpoint details
-- @param `message` Message to be logged
local function log(premature, conf, message)
message = cjson.encode(message).."\n"
local message = cjson.encode(message).."\n"

local f = fd_util.get_fd()
if not f then
Expand All @@ -41,9 +39,7 @@ end
local _M = {}

function _M.execute(conf)
local message = basic_serializer.serialize(ngx)

local ok, err = ngx.timer.at(0, log, conf, message)
local ok, err = ngx.timer.at(0, log, conf, ngx.ctx.log_message)
if not ok then
ngx.log(ngx.ERR, "[filelog] failed to create timer: ", err)
end
Expand Down
5 changes: 1 addition & 4 deletions kong/plugins/httplog/handler.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local basic_serializer = require "kong.plugins.log_serializers.basic"
local BasePlugin = require "kong.plugins.base_plugin"
local log = require "kong.plugins.httplog.log"

Expand All @@ -10,9 +9,7 @@ end

function HttpLogHandler:log(conf)
HttpLogHandler.super.log(self)

local message = basic_serializer.serialize(ngx)
log.execute(conf, message)
log.execute(conf)
end

return HttpLogHandler
Loading

0 comments on commit 44bf3e9

Please sign in to comment.