diff --git a/apisix/plugins/opentelemetry.lua b/apisix/plugins/opentelemetry.lua index cecf8ba84988..f1ebeea5bf17 100644 --- a/apisix/plugins/opentelemetry.lua +++ b/apisix/plugins/opentelemetry.lua @@ -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", @@ -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"}}, }, } }, diff --git a/t/plugin/opentelemetry.t b/t/plugin/opentelemetry.t index 0e2687392d5f..8d8bd049dd48 100644 --- a/t/plugin/opentelemetry.t +++ b/t/plugin/opentelemetry.t @@ -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") + } + }