Skip to content

Commit

Permalink
fix(zipkin) include connect time in balancer span
Browse files Browse the repository at this point in the history
  • Loading branch information
mayocream committed Jun 15, 2022
1 parent ef58cdd commit c7391bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
17 changes: 9 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@

## Unreleased

### Fixes

### Breaking Changes

- Blue-green deployment from Kong earlier than `2.1.0` is not supported, upgrade to
Expand Down Expand Up @@ -278,17 +276,20 @@ a restart (e.g., upon a plugin server crash).
#### Plugins

- **ACME**: `auth_method` default value is set to `token`
[#8565](https://github.com/Kong/kong/pull/8565)
[#8565](https://github.com/Kong/kong/pull/8565)
- **serverless-functions**: Removed deprecated `config.functions` from schema
[#8559](https://github.com/Kong/kong/pull/8559)
[#8559](https://github.com/Kong/kong/pull/8559)
- **syslog**: `conf.facility` default value is now set to `user`
[#8564](https://github.com/Kong/kong/pull/8564)
[#8564](https://github.com/Kong/kong/pull/8564)
- **AWS-Lambda**: Removed `proxy_scheme` field from schema
[#8566](https://github.com/Kong/kong/pull/8566)
[#8566](https://github.com/Kong/kong/pull/8566)
- **hmac-auth**: Removed deprecated signature format using `ngx.var.uri`
[#8558](https://github.com/Kong/kong/pull/8558)
[#8558](https://github.com/Kong/kong/pull/8558)
- Remove deprecated `blacklist`/`whitelist` config fields from bot-detection, ip-restriction and ACL plugins.
[#8560](https://github.com/Kong/kong/pull/8560)
[#8560](https://github.com/Kong/kong/pull/8560)
- **Zipkin**: Correct the balancer spans' duration to include the connection time
from Nginx to the upstream.
[#8848](https://github.com/Kong/kong/pull/8848)

#### Clustering

Expand Down
8 changes: 7 additions & 1 deletion kong/plugins/zipkin/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ local utils = require "kong.tools.utils"
local propagation = require "kong.tracing.propagation"
local request_tags = require "kong.plugins.zipkin.request_tags"
local kong_meta = require "kong.meta"
local ngx_re = require "ngx.re"


local ngx = ngx
local ngx_var = ngx.var
local split = ngx_re.split
local subsystem = ngx.config.subsystem
local fmt = string.format
local rand_bytes = utils.get_rand_bytes
Expand Down Expand Up @@ -331,6 +335,7 @@ function ZipkinLogHandler:log(conf) -- luacheck: ignore 212
local balancer_data = ngx_ctx.balancer_data
if balancer_data then
local balancer_tries = balancer_data.tries
local upstream_connect_time = split(ngx_var.upstream_connect_time, ", ", "jo")
for i = 1, balancer_data.try_count do
local try = balancer_tries[i]
local name = fmt("%s (balancer try %d)", request_span.name, i)
Expand All @@ -348,7 +353,8 @@ function ZipkinLogHandler:log(conf) -- luacheck: ignore 212
tag_with_service_and_route(span)

if try.balancer_latency ~= nil then
span:finish((try.balancer_start + try.balancer_latency) * 1000)
local try_connect_time = (tonumber(upstream_connect_time[i]) or 0) * 1000 -- ms
span:finish((try.balancer_start + try.balancer_latency + try_connect_time) * 1000)
else
span:finish(now_mu)
end
Expand Down

0 comments on commit c7391bc

Please sign in to comment.