Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: etcd sync data checker should work #11457

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions apisix/core/config_etcd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions t/plugin/error-log-logger-clickhouse.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
57 changes: 57 additions & 0 deletions t/plugin/sls-logger.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading