Refactor controller metrics interface

This commit is contained in:
Manuel de Brito Fontes 2018-07-07 13:46:18 -04:00 committed by Manuel Alejandro de Brito Fontes
parent bdd2c5e3be
commit 1542a12764
No known key found for this signature in database
GPG key ID: 786136016A8BA02A
30 changed files with 1896 additions and 630 deletions

View file

@ -15,17 +15,24 @@ end
function _M.encode_nginx_stats()
return cjson.encode({
host = ngx.var.host or "-",
status = ngx.var.status or "-",
bytesSent = tonumber(ngx.var.bytes_sent) or -1,
protocol = ngx.var.server_protocol or "-",
method = ngx.var.request_method or "-",
path = ngx.var.location_path or "-",
status = ngx.var.status or "-",
requestLength = tonumber(ngx.var.request_length) or -1,
requestTime = tonumber(ngx.var.request_time) or -1,
upstreamName = ngx.var.proxy_upstream_name or "-",
upstreamIP = ngx.var.upstream_addr or "-",
responseLength = tonumber(ngx.var.bytes_sent) or -1,
endpoint = ngx.var.upstream_addr or "-",
upstreamLatency = tonumber(ngx.var.upstream_connect_time) or -1,
upstreamResponseTime = tonumber(ngx.var.upstream_response_time) or -1,
upstreamResponseLength = tonumber(ngx.var.upstream_response_length) or -1,
upstreamStatus = ngx.var.upstream_status or "-",
namespace = ngx.var.namespace or "-",
ingress = ngx.var.ingress_name or "-",
service = ngx.var.service_name or "-",

View file

@ -33,10 +33,12 @@ describe("Monitor", function()
request_method = "GET",
location_path = "/admin",
request_length = "300",
request_time = "60",
request_time = "210",
proxy_upstream_name = "test-upstream",
upstream_addr = "2.2.2.2",
upstream_response_time = "200",
upstream_response_length = "150",
upstream_connect_time = "1",
upstream_status = "220",
namespace = "test-app-production",
ingress_name = "web-yml",
@ -51,16 +53,16 @@ describe("Monitor", function()
local expected_json_stats = {
host = "testshop.com",
status = "200",
bytesSent = 150.0,
protocol = "HTTP",
responseLength = 150.0,
method = "GET",
path = "/admin",
requestLength = 300.0,
requestTime = 60.0,
upstreamName = "test-upstream",
upstreamIP = "2.2.2.2",
requestTime = 210.0,
endpoint = "2.2.2.2",
upstreamResponseTime = 200,
upstreamStatus = "220",
upstreamLatency = 1.0,
upstreamResponseLength = 150.0,
namespace = "test-app-production",
ingress = "web-yml",
service = "test-app",
@ -77,10 +79,10 @@ describe("Monitor", function()
server_protocol = "HTTP",
request_method = "GET",
location_path = "/admin",
request_time = "60",
request_time = "202",
proxy_upstream_name = "test-upstream",
upstream_addr = "2.2.2.2",
upstream_response_time = "200",
upstream_response_time = "201",
upstream_status = "220",
ingress_name = "web-yml",
}
@ -93,18 +95,19 @@ describe("Monitor", function()
local expected_json_stats = {
host = "-",
status = "-",
bytesSent = -1,
protocol = "HTTP",
responseLength = -1,
method = "GET",
path = "/admin",
requestLength = -1,
requestTime = 60.0,
upstreamName = "test-upstream",
upstreamIP = "2.2.2.2",
upstreamResponseTime = 200,
requestTime = 202.0,
endpoint = "2.2.2.2",
upstreamStatus = "220",
namespace = "-",
ingress = "web-yml",
upstreamLatency = -1,
upstreamResponseTime = 201,
upstreamResponseLength = -1,
responseLength = -1,
service = "-",
}
assert.are.same(decoded_json_stats,expected_json_stats)