This is an automated email from the ASF dual-hosted git repository.
shreemaanabhishek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new f609ea332 feat: make scheme configurable with default set to https
(#13009)
f609ea332 is described below
commit f609ea332af7333acebc04bd20c2878233285129
Author: Shreemaan Abhishek <[email protected]>
AuthorDate: Fri Feb 27 11:30:18 2026 +0545
feat: make scheme configurable with default set to https (#13009)
---
apisix/plugins/tencent-cloud-cls.lua | 6 ++-
apisix/plugins/tencent-cloud-cls/cls-sdk.lua | 5 +-
docs/en/latest/plugins/tencent-cloud-cls.md | 1 +
docs/zh/latest/plugins/tencent-cloud-cls.md | 1 +
t/plugin/tencent-cloud-cls.t | 78 ++++++++++++++++++++++++++++
5 files changed, 88 insertions(+), 3 deletions(-)
diff --git a/apisix/plugins/tencent-cloud-cls.lua
b/apisix/plugins/tencent-cloud-cls.lua
index f8dac160e..f130129e6 100644
--- a/apisix/plugins/tencent-cloud-cls.lua
+++ b/apisix/plugins/tencent-cloud-cls.lua
@@ -31,6 +31,7 @@ local schema = {
properties = {
cls_host = { type = "string" },
cls_topic = { type = "string" },
+ scheme = { type = "string", default = "https"},
secret_id = { type = "string" },
secret_key = { type = "string" },
sample_ratio = {
@@ -140,7 +141,10 @@ function _M.log(conf, ctx)
end
local process = function(entries)
- local sdk, err = cls_sdk.new(conf.cls_host, conf.cls_topic,
conf.secret_id, conf.secret_key)
+ local sdk, err = cls_sdk.new(
+ conf.scheme, conf.cls_host,
+ conf.cls_topic, conf.secret_id,
+ conf.secret_key)
if err then
core.log.error("init sdk failed err:", err)
return false, err
diff --git a/apisix/plugins/tencent-cloud-cls/cls-sdk.lua
b/apisix/plugins/tencent-cloud-cls/cls-sdk.lua
index 650d4ab0e..1ff4e468a 100644
--- a/apisix/plugins/tencent-cloud-cls/cls-sdk.lua
+++ b/apisix/plugins/tencent-cloud-cls/cls-sdk.lua
@@ -202,7 +202,7 @@ message LogGroupList
end
-function _M.new(host, topic, secret_id, secret_key)
+function _M.new(scheme, host, topic, secret_id, secret_key)
if not pb_state then
local err = init_pb_state()
if err then
@@ -210,6 +210,7 @@ function _M.new(host, topic, secret_id, secret_key)
end
end
local self = {
+ scheme = scheme,
host = host,
topic = topic,
secret_id = secret_id,
@@ -247,7 +248,7 @@ function _M.send_cls_request(self, pb_obj)
params_cache.method = "POST"
params_cache.body = pb_data
- local cls_url = "http://" .. self.host .. cls_api_path .. "?topic_id=" ..
self.topic
+ local cls_url = self.scheme .. "://" .. self.host .. cls_api_path ..
"?topic_id=" .. self.topic
core.log.debug("CLS request URL: ", cls_url)
local res, err = do_request_uri(cls_url, params_cache)
diff --git a/docs/en/latest/plugins/tencent-cloud-cls.md
b/docs/en/latest/plugins/tencent-cloud-cls.md
index e9d633ef1..25dce60c9 100644
--- a/docs/en/latest/plugins/tencent-cloud-cls.md
+++ b/docs/en/latest/plugins/tencent-cloud-cls.md
@@ -38,6 +38,7 @@ The `tencent-cloud-cls` Plugin uses [TencentCloud
CLS](https://cloud.tencent.com
| ----------------- | -------
|----------|---------|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| cls_host | string | Yes | | | CLS API
host,please refer [Uploading Structured
Logs](https://www.tencentcloud.com/document/api/614/16873).
|
| cls_topic | string | Yes | | | topic id
of CLS.
|
+| scheme | string | No | https | ["http", "https"] | The
protocol scheme to use when connecting to CLS. Defaults to `https` for secure
connections. |
| secret_id | string | Yes | | | SecretId
of your API key.
|
| secret_key | string | Yes | | | SecretKey
of your API key.
|
| sample_ratio | number | No | 1 | [0.00001, 1] | How often
to sample the requests. Setting to `1` will sample all requests.
|
diff --git a/docs/zh/latest/plugins/tencent-cloud-cls.md
b/docs/zh/latest/plugins/tencent-cloud-cls.md
index bcaa42834..b35b764c7 100644
--- a/docs/zh/latest/plugins/tencent-cloud-cls.md
+++ b/docs/zh/latest/plugins/tencent-cloud-cls.md
@@ -38,6 +38,7 @@ description: API 网关 Apache APISIX tencent-cloud-cls 插件可用于将日志
| ----------------- | ------- | ------ |-------| ------------
|------------------------------------------------------------------------------|
| cls_host | string | 是 | | | CLS API
域名,参考[使用 API 上传日志](https://cloud.tencent.com/document/api/614/16873)。|
| cls_topic | string | 是 | | | CLS 日志主题 id。
|
+| scheme | string | 否 | https | ["http", "https"] | 连接 CLS
时使用的协议方案。默认为 `https` 以实现安全连接。 |
| secret_id | string | 是 | | | 云 API 密钥的 id。
|
| secret_key | string | 是 | | | 云 API 密钥的 key。
|
| sample_ratio | number | 否 | 1 | [0.00001, 1] | 采样的比例。设置为 `1`
时,将对所有请求进行采样。 |
diff --git a/t/plugin/tencent-cloud-cls.t b/t/plugin/tencent-cloud-cls.t
index 92b78f29d..7150a2b36 100644
--- a/t/plugin/tencent-cloud-cls.t
+++ b/t/plugin/tencent-cloud-cls.t
@@ -52,6 +52,23 @@ add_block_preprocessor(sub {
}
}
}
+ server {
+ listen 10422 ssl;
+ ssl_certificate cert/apisix.crt;
+ ssl_certificate_key cert/apisix.key;
+ location /structuredlog {
+ content_by_lua_block {
+ ngx.req.read_body()
+ local data = ngx.req.get_body_data()
+ local headers = ngx.req.get_headers()
+ ngx.log(ngx.WARN, "tencent-cloud-cls https body: ", data)
+ for k, v in pairs(headers) do
+ ngx.log(ngx.WARN, "tencent-cloud-cls https headers: " .. k
.. ":" .. v)
+ end
+ ngx.say("ok")
+ }
+ }
+ }
_EOC_
$block->set_value("http_config", $http_config);
@@ -117,6 +134,7 @@ done
[[{
"plugins": {
"tencent-cloud-cls": {
+ "scheme": "http",
"cls_host": "127.0.0.1:10421",
"cls_topic":
"143b5d70-139b-4aec-b54e-bb97756916de",
"secret_id": "secret_id",
@@ -170,6 +188,7 @@ Batch Processor[tencent-cloud-cls] failed to process
entries [1/1]: got wrong st
[[{
"plugins": {
"tencent-cloud-cls": {
+ "scheme": "http",
"cls_host": "127.0.0.1:10420",
"cls_topic":
"143b5d70-139b-4aec-b54e-bb97756916de",
"secret_id": "secret_id",
@@ -359,6 +378,7 @@ apisix:
[[{
"plugins": {
"tencent-cloud-cls": {
+ "scheme": "http",
"cls_host": "127.0.0.1:10421",
"cls_topic":
"143b5d70-139b-4aec-b54e-bb97756916de",
"secret_id": "secret_id",
@@ -423,6 +443,7 @@ oshn8tcqE8cJArmEILVNPQ==
[[{
"plugins": {
"tencent-cloud-cls": {
+ "scheme": "http",
"cls_host": "127.0.0.1:10421",
"cls_topic":
"143b5d70-139b-4aec-b54e-bb97756916de",
"secret_id": "secret_id",
@@ -513,6 +534,7 @@ opentracing
[[{
"plugins": {
"tencent-cloud-cls": {
+ "scheme": "http",
"cls_host": "127.0.0.1:10420",
"cls_topic":
"143b5d70-139b-4aec-b54e-bb97756916de",
"secret_id": "secret_id",
@@ -573,6 +595,7 @@ qr/resolve ip failed, hostname: .*, error: address can't be
resolved/
[[{
"plugins": {
"tencent-cloud-cls": {
+ "scheme": "http",
"cls_host": "127.0.0.1:10420",
"cls_topic":
"143b5d70-139b-4aec-b54e-bb97756916de",
"secret_id": "secret_id",
@@ -639,6 +662,7 @@ qr/resolve ip failed, hostname: .*, error: address can't be
resolved/
[[{
"plugins": {
"tencent-cloud-cls": {
+ "scheme": "http",
"cls_host": "127.0.0.1:10420",
"cls_topic":
"143b5d70-139b-4aec-b54e-bb97756916de",
"secret_id": "secret_id",
@@ -691,3 +715,57 @@ qr/resolve ip failed, hostname: .*, error: address can't
be resolved/
}
--- no_error_log
"body":"opentracing\n"
+
+
+
+=== TEST 21: add plugin with https scheme
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "plugins": {
+ "tencent-cloud-cls": {
+ "scheme": "https",
+ "cls_host": "127.0.0.1:10422",
+ "cls_topic":
"143b5d70-139b-4aec-b54e-bb97756916de",
+ "secret_id": "secret_id",
+ "secret_key": "secret_key",
+ "batch_max_size": 1,
+ "max_retry_count": 1,
+ "retry_delay": 2,
+ "buffer_duration": 2,
+ "inactive_timeout": 2
+ }
+ },
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1982": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/opentracing"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- response_body
+passed
+
+
+
+=== TEST 22: access https endpoint
+--- request
+GET /opentracing
+--- response_body
+opentracing
+--- error_log
+Batch Processor[tencent-cloud-cls] successfully processed the entries
+--- wait: 0.5