-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tracing): ensure sampling rate applies to whole trace (#11135)
* fix(tracing): ensure sampling rate applies to whole trace This commit fixes a bug where the sampling rate was applied to individual spans, so configuring values of sampling_rate < 1 would sometimes result in split traces being reported. The fix ensures that the sampled flag that is calculated by the sampler for the root span is propagated to all children within the same trace. * fix(tracing): suggestions + propagation test
- Loading branch information
Showing
4 changed files
with
87 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
local helpers = require "spec.helpers" | ||
local cjson = require "cjson" | ||
local join = require "pl.stringx".join | ||
|
||
|
||
local TCP_PORT = helpers.get_available_port() | ||
local tcp_trace_plugin_name = "tcp-trace-exporter" | ||
|
||
|
||
for _, strategy in helpers.each_strategy() do | ||
local proxy_client | ||
|
||
describe("tracer pdk spec #" .. strategy, function() | ||
|
||
local function setup_instrumentations(types, custom_spans, sampling_rate) | ||
local bp, _ = assert(helpers.get_db_utils(strategy, { | ||
"services", | ||
"routes", | ||
"plugins", | ||
}, { tcp_trace_plugin_name })) | ||
|
||
local http_srv = assert(bp.services:insert { | ||
name = "mock-service", | ||
host = helpers.mock_upstream_host, | ||
port = helpers.mock_upstream_port, | ||
}) | ||
|
||
bp.routes:insert({ service = http_srv, | ||
protocols = { "http" }, | ||
paths = { "/" }}) | ||
|
||
bp.plugins:insert({ | ||
name = tcp_trace_plugin_name, | ||
config = { | ||
host = "127.0.0.1", | ||
port = TCP_PORT, | ||
custom_spans = custom_spans or false, | ||
} | ||
}) | ||
|
||
assert(helpers.start_kong { | ||
database = strategy, | ||
nginx_conf = "spec/fixtures/custom_nginx.template", | ||
plugins = "tcp-trace-exporter", | ||
tracing_instrumentations = types, | ||
tracing_sampling_rate = sampling_rate or 1, | ||
}) | ||
|
||
proxy_client = helpers.proxy_client() | ||
end | ||
|
||
describe("sampling rate", function () | ||
local instrumentations = { "request", "router", "balancer" } | ||
lazy_setup(function() | ||
setup_instrumentations(join(",", instrumentations), false, 0.5) | ||
end) | ||
|
||
lazy_teardown(function() | ||
helpers.stop_kong() | ||
end) | ||
|
||
it("results in either all or none of the spans in a trace to be sampled", function () | ||
for _ = 1, 100 do | ||
local thread = helpers.tcp_server(TCP_PORT) | ||
local r = assert(proxy_client:send { | ||
method = "GET", | ||
path = "/", | ||
}) | ||
assert.res_status(200, r) | ||
|
||
local ok, res = thread:join() | ||
assert.True(ok) | ||
assert.is_string(res) | ||
|
||
local spans = cjson.decode(res) | ||
assert.True(#spans == 0 or #spans == #instrumentations) | ||
end | ||
end) | ||
end) | ||
end) | ||
end |
cee8965
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bazel Build
Docker image available
kong/kong:cee8965e3e270e481d390f64a4960dcb5824ff63
Artifacts available https://github.com/Kong/kong/actions/runs/5413039310