diff --git a/apisix/plugins/opentelemetry.lua b/apisix/plugins/opentelemetry.lua index 60f05fc17ac6..d98ac44ae69d 100644 --- a/apisix/plugins/opentelemetry.lua +++ b/apisix/plugins/opentelemetry.lua @@ -55,7 +55,7 @@ local lrucache = core.lrucache.new({ local asterisk = string.byte("*", 1) -local attr_schema = { +local metadata_schema = { type = "object", properties = { trace_id_source = { @@ -192,18 +192,26 @@ local _M = { priority = 12009, name = plugin_name, schema = schema, - attr_schema = attr_schema, + metadata_schema = metadata_schema, } -function _M.check_schema(conf) +function _M.check_schema(conf, schema_type) + if schema_type == core.schema.TYPE_METADATA then + local ok, err = core.schema.check(metadata_schema, conf) + if not ok then + return ok, err + end + local check = {"collector.address"} + core.utils.check_https(check, conf, plugin_name) + return true + end return core.schema.check(schema, conf) end local hostname local sampler_factory -local plugin_info function _M.init() if process.type() ~= "worker" then @@ -217,27 +225,16 @@ function _M.init() trace_id_ratio = trace_id_ratio_sampler_new, } hostname = core.utils.gethostname() +end - plugin_info = plugin.plugin_attr(plugin_name) or {} - local check = {"collector.address"} - core.utils.check_https(check, plugin_info, plugin_name) - local ok, err = core.schema.check(attr_schema, plugin_info) - if not ok then - core.log.error("failed to check the plugin_attr[", plugin_name, "]", - ": ", err) - return - end +local function create_tracer_obj(conf, plugin_info) if plugin_info.trace_id_source == "x-request-id" then id_generator.new_ids = function() local trace_id = core.request.headers()["x-request-id"] or ngx_var.request_id return trace_id, id_generator.new_span_id() end end -end - - -local function create_tracer_obj(conf) -- create exporter local exporter = otlp_exporter_new(exporter_client_new(plugin_info.collector.address, plugin_info.collector.request_timeout, @@ -310,9 +307,17 @@ end function _M.rewrite(conf, api_ctx) + local metadata = plugin.plugin_metadata(plugin_name) + if metadata == nil then + core.log.warn("plugin_metadata is required for opentelemetry plugin to working properly") + return + end + core.log.info("metadata: ", core.json.delay_encode(metadata)) + local plugin_info = metadata.value local vars = api_ctx.var - local tracer, err = core.lrucache.plugin_ctx(lrucache, api_ctx, nil, create_tracer_obj, conf) + local tracer, err = core.lrucache.plugin_ctx(lrucache, api_ctx, nil, + create_tracer_obj, conf, plugin_info) if not tracer then core.log.error("failed to fetch tracer object: ", err) return diff --git a/docs/en/latest/plugins/opentelemetry.md b/docs/en/latest/plugins/opentelemetry.md index c5d98ffa3421..3b0c33ca5f23 100644 --- a/docs/en/latest/plugins/opentelemetry.md +++ b/docs/en/latest/plugins/opentelemetry.md @@ -36,36 +36,45 @@ The `opentelemetry` Plugin can be used to report tracing data according to the [ The Plugin only supports binary-encoded [OLTP over HTTP](https://opentelemetry.io/docs/reference/specification/protocol/otlp/#otlphttp). -## Static Configurations +## Configurations By default, configurations of the Service name, tenant ID, collector, and batch span processor are pre-configured in [default configuration](https://github.com/apache/apisix/blob/master/apisix/cli/config.lua). -To customize these values, add the corresponding configurations to `config.yaml`. For example: +You can change this configuration of the Plugin through the endpoint `apisix/admin/plugin_metadata/opentelemetry` For example: -```yaml -plugin_attr: - opentelemetry: - trace_id_source: x-request-id # Specify the source of the trace ID, `x-request-id` or `random`. When set to `x-request-id`, - # the value of the `x-request-id` header will be used as the trace ID. - resource: # Additional resource to append to the trace. - service.name: APISIX # Set the Service name for OpenTelemetry traces. - collector: - address: 127.0.0.1:4318 # Set the address of the OpenTelemetry collector to send traces to. - request_timeout: 3 # Set the timeout for requests to the OpenTelemetry collector in seconds. - request_headers: # Set the headers to include in requests to the OpenTelemetry collector. - Authorization: token # Set the authorization header to include an access token. - batch_span_processor: # Trace span processor. - drop_on_queue_full: false # Drop spans when the export queue is full. - max_queue_size: 1024 # Set the maximum size of the span export queue. - batch_timeout: 2 # Set the timeout for span batches to wait in the export queue before - # being sent. - inactive_timeout: 1 # Set the timeout for spans to wait in the export queue before being sent, - # if the queue is not full. - max_export_batch_size: 16 # Set the maximum number of spans to include in each batch sent to the OpenTelemetry collector. - set_ngx_var: false # Export opentelemetry variables to nginx variables. +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') ``` -Reload APISIX for changes to take effect. +::: + +```shell +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/opentelemetry -H "X-API-KEY: $admin_key" -X PUT -d ' +{ + "trace_id_source": "x-request-id", + "resource": { + "service.name": "APISIX" + }, + "collector": { + "address": "127.0.0.1:4318", + "request_timeout": 3, + "request_headers": { + "Authorization": "token" + }, + "batch_span_processor": { + "drop_on_queue_full": false, + "max_queue_size": 1024, + "batch_timeout": 2, + "inactive_timeout": 1, + "max_export_batch_size": 16 + }, + "set_ngx_var": false + } +}' +``` ## Attributes diff --git a/docs/zh/latest/plugins/opentelemetry.md b/docs/zh/latest/plugins/opentelemetry.md index 85d07b437fde..da0f6bb9064e 100644 --- a/docs/zh/latest/plugins/opentelemetry.md +++ b/docs/zh/latest/plugins/opentelemetry.md @@ -35,35 +35,45 @@ description: opentelemetry 插件可用于根据 OpenTelemetry 协议规范上 `opentelemetry` 插件可用于根据 [OpenTelemetry Specification](https://opentelemetry.io/docs/reference/specification/) 协议规范上报 Traces 数据。该插件仅支持二进制编码的 OLTP over HTTP,即请求类型为 `application/x-protobuf` 的数据上报。 -## 静态配置 +## 配置 默认情况下,服务名称、租户 ID、collector 和 batch span processor 的配置已预配置在[默认配置](https://github.com/apache/apisix/blob/master/apisix/cli/config.lua)中。 -要自定义这些值,请将相应的配置添加到 `config.yaml` 中。例如: +您可以通过端点 `apisix/admin/plugin_metadata/opentelemetry` 更改插件的配置,例如: -```yaml -plugin_attr: - opentelemetry: - trace_id_source: x-request-id # 指定追踪 ID 的来源,`x-request-id` 或 `random`。当设置为 `x-request-id` 时, - # `x-request-id` 头的值将用作追踪 ID。 - resource: # 追加到追踪的额外资源。 - service.name: APISIX # 为 OpenTelemetry 追踪设置服务名称。 - collector: - address: 127.0.0.1:4318 # 设置要发送追踪的 OpenTelemetry 收集器的地址。 - request_timeout: 3 # 设置请求 OpenTelemetry 收集器的超时时间(秒)。 - request_headers: # 设置请求 OpenTelemetry 收集器时要包含的头信息。 - Authorization: token # 设置授权头以包含访问令牌。 - batch_span_processor: # 追踪跨度处理器。 - drop_on_queue_full: false # 当导出队列满时丢弃跨度。 - max_queue_size: 1024 # 设置跨度导出队列的最大大小。 - batch_timeout: 2 # 设置跨度批次在导出队列中等待的超时时间, - # 然后发送。 - inactive_timeout: 1 # 设置跨度在导出队列中等待的超时时间,如果队列不满,则发送。 - max_export_batch_size: 16 # 设置每个批次发送到 OpenTelemetry 收集器的跨度的最大数量。 - set_ngx_var: false # 将 opentelemetry 变量导出到 nginx 变量。 +:::note +您可以从“config.yaml”获取“admin_key”,并使用以下命令保存到环境变量中: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') ``` -重新加载 APISIX 以使更改生效。 +::: + +```shell +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/opentelemetry -H "X-API-KEY: $admin_key" -X PUT -d ' +{ + "trace_id_source": "x-request-id", + "resource": { + "service.name": "APISIX" + }, + "collector": { + "address": "127.0.0.1:4318", + "request_timeout": 3, + "request_headers": { + "Authorization": "token" + }, + "batch_span_processor": { + "drop_on_queue_full": false, + "max_queue_size": 1024, + "batch_timeout": 2, + "inactive_timeout": 1, + "max_export_batch_size": 16 + }, + "set_ngx_var": false + } +}' +``` ## 属性 diff --git a/t/plugin/opentelemetry.t b/t/plugin/opentelemetry.t index f9e64853d93d..daf91e39e8bd 100644 --- a/t/plugin/opentelemetry.t +++ b/t/plugin/opentelemetry.t @@ -23,20 +23,14 @@ add_block_preprocessor(sub { my $extra_yaml_config = <<_EOC_; plugins: - opentelemetry -plugin_attr: - opentelemetry: - trace_id_source: x-request-id - batch_span_processor: - max_export_batch_size: 1 - inactive_timeout: 0.5 - collector: - address: 127.0.0.1:4318 - request_timeout: 3 - request_headers: - foo: bar _EOC_ $block->set_value("extra_yaml_config", $extra_yaml_config); } + + if (!$block->request) { + $block->set_value("request", "GET /t"); + } + if (!defined $block->response_body) { $block->set_value("response_body", "passed\n"); } @@ -51,7 +45,38 @@ run_tests; __DATA__ -=== TEST 1: add plugin +=== TEST 1: add plugin metadata +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/plugin_metadata/opentelemetry', + ngx.HTTP_PUT, + [[{ + "batch_span_processor": { + "max_export_batch_size": 1, + "inactive_timeout": 0.5 + }, + "collector": { + "address": "127.0.0.1:4318", + "request_timeout": 3, + "request_headers": { + "foo": "bar" + } + }, + "trace_id_source": "x-request-id" + }]] + ) + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } + + + +=== TEST 2: add plugin --- config location /t { content_by_lua_block { @@ -87,7 +112,7 @@ GET /t -=== TEST 2: trigger opentelemetry +=== TEST 3: trigger opentelemetry --- request GET /opentracing --- wait: 2 @@ -96,7 +121,7 @@ opentracing -=== TEST 3: check log +=== TEST 4: check log --- exec tail -n 1 ci/pod/otelcol-contrib/data-otlp.json --- response_body eval @@ -104,7 +129,7 @@ qr/.*opentelemetry-lua.*/ -=== TEST 4: use trace_id_ratio sampler, fraction = 1.0 +=== TEST 5: use trace_id_ratio sampler, fraction = 1.0 --- config location /t { content_by_lua_block { @@ -143,7 +168,7 @@ GET /t -=== TEST 5: trigger opentelemetry +=== TEST 6: trigger opentelemetry --- request GET /opentracing --- wait: 2 @@ -152,7 +177,7 @@ opentracing -=== TEST 6: check log +=== TEST 7: check log --- exec tail -n 1 ci/pod/otelcol-contrib/data-otlp.json --- response_body eval @@ -160,7 +185,7 @@ qr/.*opentelemetry-lua.*/ -=== TEST 7: use parent_base sampler, root sampler = trace_id_ratio with default fraction = 0 +=== TEST 8: use parent_base sampler, root sampler = trace_id_ratio with default fraction = 0 --- config location /t { content_by_lua_block { @@ -201,7 +226,7 @@ GET /t -=== TEST 8: trigger opentelemetry, trace_flag = 1 +=== TEST 9: trigger opentelemetry, trace_flag = 1 --- request GET /opentracing --- more_headers @@ -212,7 +237,7 @@ opentracing -=== TEST 9: check log +=== TEST 10: check log --- exec tail -n 1 ci/pod/otelcol-contrib/data-otlp.json --- response_body eval @@ -220,7 +245,7 @@ qr/.*"traceId":"00000000000000000000000000000001",.*/ -=== TEST 10: use parent_base sampler, root sampler = trace_id_ratio with fraction = 1 +=== TEST 11: use parent_base sampler, root sampler = trace_id_ratio with fraction = 1 --- config location /t { content_by_lua_block { @@ -264,7 +289,7 @@ GET /t -=== TEST 11: trigger opentelemetry, trace_flag = 1 +=== TEST 12: trigger opentelemetry, trace_flag = 1 --- request GET /opentracing --- more_headers @@ -275,7 +300,7 @@ opentracing -=== TEST 12: check log +=== TEST 13: check log --- exec tail -n 1 ci/pod/otelcol-contrib/data-otlp.json --- response_body eval @@ -283,7 +308,7 @@ qr/.*"traceId":"00000000000000000000000000000001",.*/ -=== TEST 13: set additional_attributes +=== TEST 14: set additional_attributes --- config location /t { content_by_lua_block { @@ -338,7 +363,7 @@ GET /t -=== TEST 14: trigger opentelemetry +=== TEST 15: trigger opentelemetry --- request GET /opentracing?foo=bar&a=b --- more_headers @@ -351,7 +376,7 @@ opentracing -=== TEST 15: check log +=== TEST 16: check log --- exec tail -n 1 ci/pod/otelcol-contrib/data-otlp.json --- response_body eval @@ -359,7 +384,7 @@ qr/.*\/opentracing\?foo=bar.*/ -=== TEST 16: create route for /specific_status +=== TEST 17: create route for /specific_status --- config location /t { content_by_lua_block { @@ -396,7 +421,7 @@ GET /t -=== TEST 17: test response empty body +=== TEST 18: test response empty body --- request HEAD /specific_status --- response_body @@ -404,7 +429,7 @@ HEAD /specific_status -=== TEST 18: check log +=== TEST 19: check log --- exec tail -n 1 ci/pod/otelcol-contrib/data-otlp.json --- response_body eval diff --git a/t/plugin/opentelemetry2.t b/t/plugin/opentelemetry2.t index 3344ce97bb61..6129f44b2ae6 100644 --- a/t/plugin/opentelemetry2.t +++ b/t/plugin/opentelemetry2.t @@ -26,12 +26,6 @@ plugins: - example-plugin - key-auth - opentelemetry -plugin_attr: - opentelemetry: - trace_id_source: x-request-id - batch_span_processor: - max_export_batch_size: 1 - inactive_timeout: 0.5 _EOC_ $block->set_value("extra_yaml_config", $extra_yaml_config); } @@ -47,7 +41,31 @@ run_tests; __DATA__ -=== TEST 1: trace request rejected by auth +=== TEST 1: add plugin metadata +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/plugin_metadata/opentelemetry', + ngx.HTTP_PUT, + [[{ + "batch_span_processor": { + "max_export_batch_size": 1, + "inactive_timeout": 0.5 + }, + "trace_id_source": "x-request-id" + }]] + ) + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } + + + +=== TEST 2: trace request rejected by auth --- config location /t { content_by_lua_block { @@ -103,7 +121,7 @@ passed -=== TEST 2: trigger opentelemetry +=== TEST 3: trigger opentelemetry --- request GET /hello --- error_code: 401 @@ -111,7 +129,7 @@ GET /hello -=== TEST 3: check log +=== TEST 4: check log --- exec tail -n 1 ci/pod/otelcol-contrib/data-otlp.json --- response_body eval diff --git a/t/plugin/opentelemetry3.t b/t/plugin/opentelemetry3.t index 1398fe89186e..ff7ea14e56e5 100644 --- a/t/plugin/opentelemetry3.t +++ b/t/plugin/opentelemetry3.t @@ -30,12 +30,6 @@ add_block_preprocessor(sub { plugins: - http-logger - opentelemetry -plugin_attr: - opentelemetry: - set_ngx_var: true - batch_span_processor: - max_export_batch_size: 1 - inactive_timeout: 0.5 _EOC_ $block->set_value("extra_yaml_config", $extra_yaml_config); } @@ -100,6 +94,21 @@ __DATA__ return body end + local code, body = t('/apisix/admin/plugin_metadata/opentelemetry', + ngx.HTTP_PUT, + [[{ + "batch_span_processor": { + "max_export_batch_size": 1, + "inactive_timeout": 0.5 + }, + "set_ngx_var": true + }]] + ) + if code >= 300 then + ngx.status = code + return body + end + local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, [[{ @@ -162,12 +171,33 @@ qr/request log: \{.*"opentelemetry_context_traceparent":"00-\w{32}-\w{16}-01".*\ plugins: - http-logger - opentelemetry -plugin_attr: - opentelemetry: - set_ngx_var: false +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + + local code, body = t('/apisix/admin/plugin_metadata/opentelemetry', + ngx.HTTP_PUT, + [[{ + "set_ngx_var": false + }]] + ) + if code >= 300 then + ngx.status = code + return body + end + } + } +--- request +GET /t + + + +=== TEST 4: trigger opentelemetry with open set variables --- request GET /hello --- response_body hello world +--- wait: 1 --- error_log eval qr/request log: \{.*"opentelemetry_context_traceparent":"".*\}/ diff --git a/t/plugin/opentelemetry4-bugfix-pb-state.t b/t/plugin/opentelemetry4-bugfix-pb-state.t index d09e07873465..bc8405df7bac 100644 --- a/t/plugin/opentelemetry4-bugfix-pb-state.t +++ b/t/plugin/opentelemetry4-bugfix-pb-state.t @@ -23,17 +23,6 @@ add_block_preprocessor(sub { my $extra_yaml_config = <<_EOC_; plugins: - opentelemetry -plugin_attr: - opentelemetry: - trace_id_source: x-request-id - batch_span_processor: - max_export_batch_size: 1 - inactive_timeout: 0.5 - collector: - address: 127.0.0.1:4318 - request_timeout: 3 - request_headers: - foo: bar _EOC_ $block->set_value("extra_yaml_config", $extra_yaml_config); } @@ -49,7 +38,42 @@ run_tests; __DATA__ -=== TEST 1: set additional_attributes with match +=== TEST 1: add plugin metadata +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/plugin_metadata/opentelemetry', + ngx.HTTP_PUT, + [[{ + "batch_span_processor": { + "max_export_batch_size": 1, + "inactive_timeout": 0.5 + }, + "trace_id_source": "x-request-id", + "collector": { + "address": "127.0.0.1:4318", + "request_timeout": 3, + "request_headers": { + "foo": "bar" + } + } + }]] + ) + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed + + + +=== TEST 2: set additional_attributes with match --- config location /t { content_by_lua_block { @@ -91,7 +115,7 @@ passed -=== TEST 2: opentelemetry expands headers +=== TEST 3: opentelemetry expands headers --- extra_init_by_lua local otlp = require("opentelemetry.trace.exporter.otlp") local orig_export_spans = otlp.export_spans diff --git a/t/plugin/opentelemetry5.t b/t/plugin/opentelemetry5.t index 2b4749f040eb..4d147dcb09a5 100644 --- a/t/plugin/opentelemetry5.t +++ b/t/plugin/opentelemetry5.t @@ -24,17 +24,6 @@ add_block_preprocessor(sub { plugins: - opentelemetry - proxy-rewrite -plugin_attr: - opentelemetry: - trace_id_source: x-request-id - batch_span_processor: - max_export_batch_size: 1 - inactive_timeout: 0.5 - collector: - address: 127.0.0.1:4318 - request_timeout: 3 - request_headers: - foo: bar _EOC_ $block->set_value("extra_yaml_config", $extra_yaml_config); } @@ -52,7 +41,45 @@ run_tests; __DATA__ -=== TEST 1: add plugin +=== TEST 1: add plugin metadata +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/plugin_metadata/opentelemetry', + ngx.HTTP_PUT, + [[{ + "batch_span_processor": { + "max_export_batch_size": 1, + "inactive_timeout": 0.5 + }, + "trace_id_source": "x-request-id", + "resource": { + "service.name": "APISIX" + }, + "collector": { + "address": "127.0.0.1:4318", + "request_timeout": 3, + "request_headers": { + "foo": "bar" + } + } + }]] + ) + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed + + + +=== TEST 2: add plugin --- config location /t { content_by_lua_block { @@ -92,7 +119,7 @@ passed -=== TEST 2: trigger opentelemetry +=== TEST 3: trigger opentelemetry --- request GET /articles/12345/comments?foo=bar --- more_headers @@ -103,7 +130,7 @@ opentracing -=== TEST 3: (resource) check service.name +=== TEST 4: (resource) check service.name --- exec tail -n 1 ci/pod/otelcol-contrib/data-otlp.json --- response_body eval @@ -111,7 +138,7 @@ qr/\{"key":"service.name","value":\{"stringValue":"APISIX"\}\}/ -=== TEST 4: (span) check name +=== TEST 5: (span) check name --- exec tail -n 1 ci/pod/otelcol-contrib/data-otlp.json --- response_body eval @@ -119,7 +146,7 @@ qr/"name":"GET \/articles\/\*\/comments"/ -=== TEST 5: (span) check http.status_code +=== TEST 6: (span) check http.status_code --- exec tail -n 1 ci/pod/otelcol-contrib/data-otlp.json --- response_body eval @@ -127,7 +154,7 @@ qr/\{"key":"http.status_code","value":\{"intValue":"200"\}\}/ -=== TEST 6: (span) check http.method +=== TEST 7: (span) check http.method --- exec tail -n 1 ci/pod/otelcol-contrib/data-otlp.json --- response_body eval @@ -135,7 +162,7 @@ qr/\{"key":"http.method","value":\{"stringValue":"GET"\}\}/ -=== TEST 7: (span) check http.host +=== TEST 8: (span) check http.host --- exec tail -n 1 ci/pod/otelcol-contrib/data-otlp.json --- response_body eval @@ -143,7 +170,7 @@ qr/\{"key":"net.host.name","value":\{"stringValue":"localhost"\}\}/ -=== TEST 8: (span) check http.user_agent +=== TEST 9: (span) check http.user_agent --- exec tail -n 1 ci/pod/otelcol-contrib/data-otlp.json --- response_body eval @@ -151,7 +178,7 @@ qr/\{"key":"http.user_agent","value":\{"stringValue":"test-client"\}\}/ -=== TEST 9: (span) check http.target +=== TEST 10: (span) check http.target --- exec tail -n 1 ci/pod/otelcol-contrib/data-otlp.json --- response_body eval @@ -159,7 +186,7 @@ qr/\{"key":"http.target","value":\{"stringValue":"\/articles\/12345\/comments\?f -=== TEST 10: (span) check http.route +=== TEST 11: (span) check http.route --- exec tail -n 1 ci/pod/otelcol-contrib/data-otlp.json --- response_body eval @@ -167,7 +194,7 @@ qr/\{"key":"http.route","value":\{"stringValue":"\/articles\/\*\/comments"\}\}/ -=== TEST 11: (span) check apisix.route_id +=== TEST 12: (span) check apisix.route_id --- exec tail -n 1 ci/pod/otelcol-contrib/data-otlp.json --- response_body eval @@ -175,7 +202,7 @@ qr/\{"key":"apisix.route_id","value":\{"stringValue":"1"\}\}/ -=== TEST 12: (span) check apisix.route_name +=== TEST 13: (span) check apisix.route_name --- exec tail -n 1 ci/pod/otelcol-contrib/data-otlp.json --- response_body eval diff --git a/t/plugin/security-warning2.t b/t/plugin/security-warning2.t index acfd4664965a..d7c4e9aedcaa 100644 --- a/t/plugin/security-warning2.t +++ b/t/plugin/security-warning2.t @@ -138,21 +138,30 @@ Using openid-connect proxy_opts.http_proxy with no TLS is a security risk --- extra_yaml_config plugins: - opentelemetry -plugin_attr: - opentelemetry: - trace_id_source: x-request-id - batch_span_processor: - max_export_batch_size: 1 - inactive_timeout: 0.5 - collector: - address: http://127.0.0.1:4318 - request_timeout: 3 - request_headers: - foo: bar --- config location /t { content_by_lua_block { local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/plugin_metadata/opentelemetry', + ngx.HTTP_PUT, + [[{ + "batch_span_processor": { + "max_export_batch_size": 1, + "inactive_timeout": 0.5 + }, + "trace_id_source": "x-request-id", + "collector": { + "address": "http://127.0.0.1:4318", + "request_timeout": 3, + "request_headers": { + "foo": "bar" + } + } + }]] + ) + if code >= 300 then + ngx.status = code + end local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, [[{ @@ -176,6 +185,13 @@ plugin_attr: if code >= 300 then ngx.status = code end + --- deleting this data so this doesn't effect when metadata schema is validated + --- at init in next test. + local code, body = t('/apisix/admin/plugin_metadata/opentelemetry', + ngx.HTTP_DELETE) + if code >= 300 then + ngx.status = code + end ngx.say(body) } } @@ -190,21 +206,30 @@ Using opentelemetry collector.address with no TLS is a security risk --- extra_yaml_config plugins: - opentelemetry -plugin_attr: - opentelemetry: - trace_id_source: x-request-id - batch_span_processor: - max_export_batch_size: 1 - inactive_timeout: 0.5 - collector: - address: https://127.0.0.1:4318 - request_timeout: 3 - request_headers: - foo: bar --- config location /t { content_by_lua_block { local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/plugin_metadata/opentelemetry', + ngx.HTTP_PUT, + [[{ + "batch_span_processor": { + "max_export_batch_size": 1, + "inactive_timeout": 0.5 + }, + "trace_id_source": "x-request-id", + "collector": { + "address": "https://127.0.0.1:4318", + "request_timeout": 3, + "request_headers": { + "foo": "bar" + } + } + }]] + ) + if code >= 300 then + ngx.status = code + end local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, [[{