Skip to content

Commit

Permalink
fix(tracing): error when DNS query fails
Browse files Browse the repository at this point in the history
It assumes the query never fails

Fix FTI-5544
  • Loading branch information
StarlightIbuki committed Nov 7, 2023
1 parent 5d2c511 commit 79c7381
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "**tracing:** Fixed an issue where the DNS query failure would cause tracing failure."
type: bugfix
scope: Core
7 changes: 6 additions & 1 deletion kong/tracing/instrumentation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,12 @@ do
if span then
span:set_attribute("dns.record.domain", host)
span:set_attribute("dns.record.port", port)
span:set_attribute("dns.record.ip", ip_addr)
if ip_addr then
span:set_attribute("dns.record.ip", ip_addr)
else
span:record_error(res_port)
span:set_status(2)
end
span:finish()
end

Expand Down
52 changes: 51 additions & 1 deletion spec/02-integration/14-tracing/01-instrumentations_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ for _, strategy in helpers.each_strategy() do

describe("tracing instrumentations spec #" .. strategy, function()

local function setup_instrumentations(types, custom_spans)
local function setup_instrumentations(types, custom_spans, post_func)
local bp, _ = assert(helpers.get_db_utils(strategy, {
"services",
"routes",
Expand Down Expand Up @@ -90,6 +90,10 @@ for _, strategy in helpers.each_strategy() do
}
})

if post_func then
post_func(bp)
end

assert(helpers.start_kong {
database = strategy,
nginx_conf = "spec/fixtures/custom_nginx.template",
Expand Down Expand Up @@ -502,5 +506,51 @@ for _, strategy in helpers.each_strategy() do
assert_has_span("kong", spans)
end)
end)

describe("#regression", function ()
describe("nil attribute for dns_query when fail to query", function ()
lazy_setup(function()
setup_instrumentations("dns_query", true, function(bp)
-- intentionally trigger a DNS query error
-- TODO: find a way to trigger a DNS query error
-- There's a bug that the balancer's DNS query is not instrumented
local service = bp.services:insert({
name = "inexist-host-service",
host = "really-inexist-host",
port = 80,
})

bp.routes:insert({
service = service,
protocols = { "http" },
paths = { "/test" },
})
end)
end)

lazy_teardown(function()
helpers.stop_kong()
end)

it("contains the expected kong.dns span", function ()
local thread = helpers.tcp_server(TCP_PORT)
local r = assert(proxy_client:send {
method = "GET",
path = "/test",
})
assert.res_status(503, r)

-- Getting back the TCP server input
local ok, res = thread:join()
assert.True(ok)
assert.is_string(res)

local spans = cjson.decode(res)
assert_has_span("kong", spans)
assert_has_span("kong.dns", spans)
print(require"inspect"(spans))
end)
end)
end)
end)
end

0 comments on commit 79c7381

Please sign in to comment.