In this guide, we will install to mirror traffic via to HyperTest.
Brief Steps
Install kong-plugin-http-mirror via luarocks (or clone plugin repository from and get the .lua files)
Migrate plugin from base plugin module (few changes in handler.lua)
Add kong-plugin-http-mirror plugin in kong configuration file
Restart Kong
Add kong-plugin-http-mirror plugin to your service
Getting Started:
Get Plugin
1. Install kong-plugin-http-mirror plugin via luarocks
luarocks install kong-plugin-http-mirror
2. Migrate from BasePlugin module
Go to the folder where the plugin's lua files are created.
It should be something like /usr/local/share/lua/<version>/kong/plugins/kong-plugin-http-mirror/
cd /usr/local/share/lua/5.1/kong/plugins/kong-plugin-http-mirror/
vi handler.lua
Do the following changes to migrate plugin from base plugin module as it is now deprecated and removed in Kong Gateway
Migrating from BasePlugin module
The BasePlugin module is deprecated and has been removed from Kong Gateway. Since kong-plugin-http-mirror uses this module, replace the following section:
-- DEPRECATED --
local BasePlugin = require "kong.plugins.base_plugin"
local HttpMirrorHandler = BasePlugin:extend()
HttpMirrorHandler.VERSION = "1.0.0"
HttpMirrorHandler.PRIORITY = 10
with the current equivalent:
local HttpMirrorHandler = {
VERSION = "1.0.0",
PRIORITY = 10,
}
You don’t need to add a :new() method or call any of the HttpMirrorHandler.super.XXX:(self) methods.
Or Just replace the content of handler.lua with below content
handler.lua
---
--- Created by liuxiaodong
--- Modified by lgazo (v1), nhp0712 (v2)
--- DateTime: 2019/4/3 19:10
---
local mirror = require "kong.plugins.kong-plugin-http-mirror.mirror"
--- local BasePlugin = require "kong.plugins.base_plugin"
--- local HttpMirrorHandler = BasePlugin:extend()
--- HttpMirrorHandler.PRIORITY = 1
local HttpMirrorHandler = {
VERSION = "1.0.0",
PRIORITY = 1
}
-- function HttpMirrorHandler:new()
-- HttpMirrorHandler.super.new(self, "http-mirror")
-- end
function HttpMirrorHandler:access(conf)
-- HttpMirrorHandler.super.log(self)
if conf.mirror_request_body then
ngx.req.read_body()
end
end
function HttpMirrorHandler:log(conf)
-- HttpMirrorHandler.super.log(self)
local request = mirror.serialize(conf)
local ok, err = ngx.timer.at(0, mirror.do_mirror, conf, request)
if not ok then
ngx.log(ngx.ERR, "mirror plugin failed to create timer: ", err)
end
end
return HttpMirrorHandler
Install Plugin in Kong
Add the kong-plugin-http-mirror plugin in kong.conf configuration for each kong node.
The file is by default located in /etc/kong/kong.conf.default or /etc/kong/kong.conf.
If you are working on default file. Make a copy via below and edit it and use that to start kong
cp /etc/kong/kong.conf.default /etc/kong/kong.conf
vi /etc/kong/kong.conf
kong.conf
# uncomment/add in your plugins line
plugins = bundled,kong-plugin-http-mirror
If you are manually adding the plugin with lua files, then also give the path to kong plugin directory in lua_package_path variable
If the plugin kong-plugin-http-mirror is located on the file system and the handler file is in the following directory: