Skip to content

Commit 8728863

Browse files
authored
fix: etcd sync data checker should work (#11457)
Signed-off-by: ashing <axingfly@gmail.com>
1 parent d0af27b commit 8728863

File tree

3 files changed

+65
-8
lines changed

3 files changed

+65
-8
lines changed

apisix/core/config_etcd.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -671,13 +671,13 @@ local function sync_data(self)
671671
log.error("failed to check item data of [", self.key,
672672
"] err:", err, " ,val: ", json.encode(res.value))
673673
end
674+
end
674675

675-
if data_valid and self.checker then
676-
data_valid, err = self.checker(res.value)
677-
if not data_valid then
678-
log.error("failed to check item data of [", self.key,
679-
"] err:", err, " ,val: ", json.delay_encode(res.value))
680-
end
676+
if data_valid and res.value and self.checker then
677+
data_valid, err = self.checker(res.value)
678+
if not data_valid then
679+
log.error("failed to check item data of [", self.key,
680+
"] err:", err, " ,val: ", json.delay_encode(res.value))
681681
end
682682
end
683683

t/plugin/error-log-logger-clickhouse.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ done
9898
--- error_log
9999
this is a warning message for test2
100100
clickhouse body: INSERT INTO t FORMAT JSONEachRow
101-
clickhouse headers: x-clickhouse-key:dpwomMlEsHH2L7wSUi6YiQ==
101+
clickhouse headers: x-clickhouse-key:a
102102
clickhouse headers: x-clickhouse-user:default
103103
clickhouse headers: x-clickhouse-database:default
104104
--- wait: 3
@@ -133,7 +133,7 @@ clickhouse headers: x-clickhouse-database:default
133133
--- error_log
134134
this is a warning message for test3
135135
clickhouse body: INSERT INTO t FORMAT JSONEachRow
136-
clickhouse headers: x-clickhouse-key:dpwomMlEsHH2L7wSUi6YiQ==
136+
clickhouse headers: x-clickhouse-key:a
137137
clickhouse headers: x-clickhouse-user:default
138138
clickhouse headers: x-clickhouse-database:default
139139
--- wait: 5

t/plugin/sls-logger.t

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,3 +472,60 @@ hello world
472472
}
473473
--- error_log
474474
"body":"hello world\n"
475+
476+
477+
478+
=== TEST 16: set incorrect plugin metadata, should have error log
479+
--- config
480+
location /t {
481+
content_by_lua_block {
482+
local core = require("apisix.core")
483+
local key = "/plugin_metadata/sls-logger"
484+
local val = {
485+
id = "sls-logger",
486+
log_format = "bad plugin metadata"
487+
}
488+
local _, err = core.etcd.set(key, val)
489+
if err then
490+
ngx.say(err)
491+
return
492+
end
493+
ngx.say("done")
494+
}
495+
}
496+
--- request
497+
GET /t
498+
--- response_body
499+
done
500+
--- error_log
501+
sync_data(): failed to check item data of [/apisix/plugin_metadata]
502+
failed to check the configuration of plugin sls-logger
503+
504+
505+
506+
=== TEST 17: set correct plugin metadata, should no error log
507+
--- config
508+
location /t {
509+
content_by_lua_block {
510+
local core = require("apisix.core")
511+
local key = "/plugin_metadata/sls-logger"
512+
local val = {
513+
id = "sls-logger",
514+
log_format = {
515+
host = "$host",
516+
client_ip = "$remote_addr"
517+
}
518+
}
519+
local _, err = core.etcd.set(key, val)
520+
if err then
521+
ngx.say(err)
522+
return
523+
end
524+
ngx.say("done")
525+
}
526+
}
527+
--- request
528+
GET /t
529+
--- response_body
530+
done
531+
--- no_error_log

0 commit comments

Comments
 (0)