Skip to content
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
6 changes: 4 additions & 2 deletions apisix/plugins/opentelemetry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ local metadata_schema = {
resource = {
type = "object",
description = "additional resource",
additionalProperties = {{type = "boolean"}, {type = "number"}, {type = "string"}},
additionalProperties = {
oneOf = {{type = "boolean"}, {type = "number"}, {type = "string"}},
},
},
collector = {
type = "object",
Expand All @@ -105,7 +107,7 @@ local metadata_schema = {
type = "object",
description = "http headers",
additionalProperties = {
one_of = {{type = "boolean"},{type = "number"}, {type = "string"}},
oneOf = {{type = "boolean"}, {type = "number"}, {type = "string"}},
},
}
},
Expand Down
36 changes: 36 additions & 0 deletions t/plugin/opentelemetry.t
Original file line number Diff line number Diff line change
Expand Up @@ -979,3 +979,39 @@ opentracing
tail -n 1 ci/pod/otelcol-contrib/data-otlp.json
--- response_body eval
qr/"traceId"\s*:\s*"(?!550e8400e29b41d4a716446655440000)[0-9a-f]{32}"/



=== TEST 49: metadata_schema rejects non-scalar resource and collector.request_headers values
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local cases = {
{name = "object resource value",
body = [[{"resource":{"service.name":{"nested":"table"}}}]]},
{name = "array resource value",
body = [[{"resource":{"service.name":["a","b"]}}]]},
{name = "object request_headers value",
body = [[{"collector":{"address":"127.0.0.1:4318","request_headers":{"Authorization":{"a":1}}}}]]},
}
for _, case in ipairs(cases) do
local code = t('/apisix/admin/plugin_metadata/opentelemetry',
ngx.HTTP_PUT, case.body)
if code ~= 400 then
ngx.say(case.name, ": expected 400, got ", code)
return
end
end

-- scalars stay valid
local code = t('/apisix/admin/plugin_metadata/opentelemetry', ngx.HTTP_PUT,
[[{"resource":{"service.name":"APISIX","weight":1.5,"debug":true},]] ..
[["collector":{"address":"127.0.0.1:4318","request_headers":{"Authorization":"token"}}}]])
if code >= 300 then
ngx.say("valid metadata rejected, got ", code)
return
end
ngx.say("passed")
}
}
Loading