-
Notifications
You must be signed in to change notification settings - Fork 4.9k
feat(clustering/sync): validate deltas when syncing #14127
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
Merged
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
cfb6a92
feat(sync): validate deltas
chobits f190970
add test case
chobits 7aafdd9
localize table.insert
chobits 5a4aa84
localize kong.db
chobits 1b5011b
ngx.null -> null
chobits 1a63d10
fix lint error of test case
chobits d31a2b6
fix typo: generate
chobits a19f5bc
coding style
chobits bf13811
add comment
chobits 980029c
add comment for expand_foreigns
chobits 089d82e
Update kong/db/schema/others/declarative_config.lua
chobits 4526fd9
Update kong/db/schema/others/declarative_config.lua
chobits 8f8de42
fix comments
chobits bdb40b8
select return fix
chobits 36e4701
fixed tests: assert -> assert.is_true
chobits ab513d0
improve loop logic
chobits e0db810
improve perf of test cases
chobits e3494c0
generaete full schema of declarative config for sync
chobits 1bca8c8
add blank to fix coding style
chobits f77ca9b
simplify logic: we dont validate full sync, all run vallidate sync
chobits 9fec3e6
Revert "generaete full schema of declarative config for sync"
chobits 134e2c6
1
chobits 88992ff
fix 09-node-id-persistence_spec.lua
chobits bf38ec1
rename: declarative_config.validate -> declarative_config.validate_sc…
chobits c2c58d5
remove DeclarativeConfig.validate_references_full
chobits ec2e241
fix title of 09-node-id-persistence_spec.lua
chobits 6159464
fix test case 30
chobits f9de4eb
add wait time
chobits f05309d
delcarative_config.load() supports sync.v2
chobits 4d76b7c
delcarative_config.load() supports sync.v2 (part 2)
chobits d3c619b
delcarative_config.load() supports sync.v2 (full schema preload)
chobits 5d56bb0
fix comment
chobits 8d3ed7d
add comment for wrap_db() expand_foreigns param
chobits d71d10c
Update kong/db/schema/others/declarative_config.lua
chobits ed677e2
comment
chobits 64015e8
coding style: not not sync -> sync ~= nil
chobits de9f3a5
coding style
chobits bfc35c3
fix 06-validate_deltas_spec.lua
chobits d20ebeb
validate schema with kong.db.schema.validate()
chobits ab9f6dd
remove unncessary logic
chobits d51e1a0
remove unncessary logic
chobits d619ef1
add comment and remove unnecessary fake sync in test case
chobits File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
local declarative = require("kong.db.declarative") | ||
local declarative_config = require("kong.db.schema.others.declarative_config") | ||
|
||
|
||
local null = ngx.null | ||
local pk_string = declarative_config.pk_string | ||
local validate_references_sync = declarative_config.validate_references_sync | ||
local pretty_print_error = declarative.pretty_print_error | ||
|
||
|
||
local function validate_deltas(deltas, is_full_sync) | ||
|
||
local errs = {} | ||
|
||
-- generate deltas table mapping primary key string to entity item | ||
local deltas_map = {} | ||
|
||
local db = kong.db | ||
|
||
for _, delta in ipairs(deltas) do | ||
local delta_type = delta.type | ||
local delta_entity = delta.entity | ||
|
||
if delta_entity ~= nil and delta_entity ~= null then | ||
-- table: primary key string -> entity | ||
local schema = db[delta_type].schema | ||
local pk = schema:extract_pk_values(delta_entity) | ||
local pks = pk_string(schema, pk) | ||
|
||
deltas_map[pks] = delta_entity | ||
|
||
-- validate entity | ||
local dao = kong.db[delta_type] | ||
if dao then | ||
-- CP will insert ws_id into the entity, which will be validated as an | ||
-- unknown field. | ||
-- TODO: On the CP side, remove ws_id from the entity and set it only | ||
-- in the delta. | ||
local ws_id = delta_entity.ws_id | ||
delta_entity.ws_id = nil -- clear ws_id | ||
|
||
local ok, err_t = dao.schema:validate(delta_entity) | ||
|
||
delta_entity.ws_id = ws_id -- restore ws_id | ||
|
||
if not ok then | ||
errs[#errs + 1] = { [delta_type] = err_t } | ||
end | ||
end | ||
end | ||
end | ||
|
||
if next(errs) then | ||
return nil, pretty_print_error(errs, "deltas") | ||
end | ||
|
||
-- validate references | ||
local ok, err_t = validate_references_sync(deltas, deltas_map, is_full_sync) | ||
if not ok then | ||
return nil, pretty_print_error(err_t) | ||
end | ||
|
||
return true | ||
end | ||
|
||
|
||
return { | ||
validate_deltas = validate_deltas, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.