Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(conf_loader): deprecate and alias otel properties #10220

Merged
merged 2 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions kong.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
# such in the Lua namespace:
# `kong.vaults.{name}.*`.

#opentelemetry_tracing = off # Deprecated: use tracing_instrumentatios instead
#opentelemetry_tracing = off # Deprecated: use tracing_instrumentations instead

#tracing_instrumentations = off # Comma-separated list of tracing instrumentations
# this node should load. By default, no instrumentations
Expand Down Expand Up @@ -939,10 +939,10 @@
# connection may be kept open
# indefinitely.

#allow_debug_header = off # Enable the `Kong-Debug` header function.
# if it is `on`, kong will add
# `Kong-Route-Id` `Kong-Route-Name` `Kong-Service-Id`
# `Kong-Service-Name` debug headers to response when
#allow_debug_header = off # Enable the `Kong-Debug` header function.
# if it is `on`, kong will add
# `Kong-Route-Id` `Kong-Route-Name` `Kong-Service-Id`
# `Kong-Service-Name` debug headers to response when
# the client request header `Kong-Debug: 1` is present.

#------------------------------------------------------------------------------
Expand Down
27 changes: 21 additions & 6 deletions kong/conf_loader/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -547,17 +547,32 @@ local CONF_PARSERS = {
lmdb_environment_path = { typ = "string" },
lmdb_map_size = { typ = "string" },

tracing_instrumentations= {
opentelemetry_tracing = {
typ = "array",
alias = {
replacement = "tracing_instrumentations",
},
deprecated = {
replacement = "opentelemetry_tracing",
replacement = "tracing_instrumentations",
},
},
tracing_sampling_rate = {

tracing_instrumentations = {
typ = "array",
},

opentelemetry_tracing_sampling_rate = {
typ = "number",
deprecated = {
replacement = "opentelemetry_tracing_sampling_rate",
replacement = "tracing_sampling_rate",
},
alias = {
replacement = "tracing_sampling_rate",
},
},

tracing_sampling_rate = {
typ = "number",
},

proxy_server = { typ = "string" },
Expand Down Expand Up @@ -1193,14 +1208,14 @@ local function check_and_parse(conf, opts)

for _, trace_type in ipairs(conf.tracing_instrumentations) do
if not available_types_map[trace_type] then
errors[#errors + 1] = "invalid opentelemetry tracing type: " .. trace_type
errors[#errors + 1] = "invalid tracing type: " .. trace_type
end
end

if #conf.tracing_instrumentations > 1
and tablex.find(conf.tracing_instrumentations, "off")
then
errors[#errors + 1] = "invalid opentelemetry tracing types: off, other types are mutually exclusive"
errors[#errors + 1] = "invalid tracing types: off, other types are mutually exclusive"
end

if conf.tracing_sampling_rate < 0 or conf.tracing_sampling_rate > 1 then
Expand Down
32 changes: 32 additions & 0 deletions spec/01-unit/03-conf_loader_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1764,6 +1764,38 @@ describe("Configuration loader", function()
assert.equal("strict", conf.worker_consistency)
assert.equal(nil, err)
end)

it("opentelemetry_tracing", function()
local conf, err = assert(conf_loader(nil, {
opentelemetry_tracing = "request,router",
}))
assert.same({"request", "router"}, conf.tracing_instrumentations)
assert.equal(nil, err)

-- no clobber
conf, err = assert(conf_loader(nil, {
opentelemetry_tracing = "request,router",
tracing_instrumentations = "balancer",
}))
assert.same({ "balancer" }, conf.tracing_instrumentations)
assert.equal(nil, err)
end)

it("opentelemetry_tracing_sampling_rate", function()
local conf, err = assert(conf_loader(nil, {
opentelemetry_tracing_sampling_rate = 0.5,
}))
assert.same(0.5, conf.tracing_sampling_rate)
assert.equal(nil, err)

-- no clobber
conf, err = assert(conf_loader(nil, {
opentelemetry_tracing_sampling_rate = 0.5,
tracing_sampling_rate = 0.75,
}))
assert.same(0.75, conf.tracing_sampling_rate)
assert.equal(nil, err)
end)
end)

describe("vault references", function()
Expand Down