This is an automated email from the ASF dual-hosted git repository.

wenming 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 8728863c8 fix: etcd sync data checker should work (#11457)
8728863c8 is described below

commit 8728863c84ec297aacdec95062a6bbd0c913841b
Author: Ashing Zheng <axing...@gmail.com>
AuthorDate: Fri Aug 2 10:29:12 2024 +0800

    fix: etcd sync data checker should work (#11457)
    
    Signed-off-by: ashing <axing...@gmail.com>
---
 apisix/core/config_etcd.lua            | 12 +++----
 t/plugin/error-log-logger-clickhouse.t |  4 +--
 t/plugin/sls-logger.t                  | 57 ++++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+), 8 deletions(-)

diff --git a/apisix/core/config_etcd.lua b/apisix/core/config_etcd.lua
index 90f9b6f16..6e06a368f 100644
--- a/apisix/core/config_etcd.lua
+++ b/apisix/core/config_etcd.lua
@@ -671,13 +671,13 @@ local function sync_data(self)
                 log.error("failed to check item data of [", self.key,
                           "] err:", err, " ,val: ", json.encode(res.value))
             end
+        end
 
-            if data_valid and self.checker then
-                data_valid, err = self.checker(res.value)
-                if not data_valid then
-                    log.error("failed to check item data of [", self.key,
-                              "] err:", err, " ,val: ", 
json.delay_encode(res.value))
-                end
+        if data_valid and res.value and self.checker then
+            data_valid, err = self.checker(res.value)
+            if not data_valid then
+                log.error("failed to check item data of [", self.key,
+                          "] err:", err, " ,val: ", 
json.delay_encode(res.value))
             end
         end
 
diff --git a/t/plugin/error-log-logger-clickhouse.t 
b/t/plugin/error-log-logger-clickhouse.t
index 6846f6ef1..91ef60b18 100644
--- a/t/plugin/error-log-logger-clickhouse.t
+++ b/t/plugin/error-log-logger-clickhouse.t
@@ -98,7 +98,7 @@ done
 --- error_log
 this is a warning message for test2
 clickhouse body: INSERT INTO t FORMAT JSONEachRow
-clickhouse headers: x-clickhouse-key:dpwomMlEsHH2L7wSUi6YiQ==
+clickhouse headers: x-clickhouse-key:a
 clickhouse headers: x-clickhouse-user:default
 clickhouse headers: x-clickhouse-database:default
 --- wait: 3
@@ -133,7 +133,7 @@ clickhouse headers: x-clickhouse-database:default
 --- error_log
 this is a warning message for test3
 clickhouse body: INSERT INTO t FORMAT JSONEachRow
-clickhouse headers: x-clickhouse-key:dpwomMlEsHH2L7wSUi6YiQ==
+clickhouse headers: x-clickhouse-key:a
 clickhouse headers: x-clickhouse-user:default
 clickhouse headers: x-clickhouse-database:default
 --- wait: 5
diff --git a/t/plugin/sls-logger.t b/t/plugin/sls-logger.t
index af6ae667c..45dd3f896 100644
--- a/t/plugin/sls-logger.t
+++ b/t/plugin/sls-logger.t
@@ -472,3 +472,60 @@ hello world
     }
 --- error_log
 "body":"hello world\n"
+
+
+
+=== TEST 16: set incorrect plugin metadata, should have error log
+--- config
+    location /t {
+        content_by_lua_block {
+            local core = require("apisix.core")
+            local key = "/plugin_metadata/sls-logger"
+            local val = {
+                id = "sls-logger",
+                log_format = "bad plugin metadata"
+            }
+            local _, err = core.etcd.set(key, val)
+            if err then
+                ngx.say(err)
+                return
+            end
+            ngx.say("done")
+        }
+    }
+--- request
+GET /t
+--- response_body
+done
+--- error_log
+sync_data(): failed to check item data of [/apisix/plugin_metadata]
+failed to check the configuration of plugin sls-logger
+
+
+
+=== TEST 17: set correct plugin metadata, should no error log
+--- config
+    location /t {
+        content_by_lua_block {
+            local core = require("apisix.core")
+            local key = "/plugin_metadata/sls-logger"
+            local val = {
+                id = "sls-logger",
+                log_format = {
+                    host = "$host",
+                    client_ip = "$remote_addr"
+                }
+            }
+            local _, err = core.etcd.set(key, val)
+            if err then
+                ngx.say(err)
+                return
+            end
+            ngx.say("done")
+        }
+    }
+--- request
+GET /t
+--- response_body
+done
+--- no_error_log

Reply via email to