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(schema): deprecated shorthand fields precedence #13486

Merged
merged 2 commits into from
Aug 12, 2024

Conversation

bungle
Copy link
Member

@bungle bungle commented Aug 9, 2024

Summary

The shorthand fields e.g. as used in (the url is a shorthand) take precedence:

http PUT :8001/services/test url=http://test.org/ port=2345

That means that port=2345 will be overwritten by http default port of 80 that is implicit in shorthand field url.

This is how it has been for a long long time.

In PR #12686 we added deprecation field to shorthand fields definition.

Some of our automatic migrations without database migrations magic use this functionality, but the precedence there does not good:

http -f PUT :8001/plugins/x name=x config.new=test config.old=should_be_ignored

In above the config.old is a shorthand field with a deprecation property. Thus it should not overwrite the config.new, but in current code base it does. This PR changes it so that it doesn't do it anymore.

KAG-5134 and https://kongstrong.slack.com/archives/C07AQH7SAF8/p1722589141558609

Checklist

@github-actions github-actions bot added core/db schema-change-noteworthy cherry-pick kong-ee schedule this PR for cherry-picking to kong/kong-ee labels Aug 9, 2024
@bungle bungle force-pushed the fix/deprecation-merge-order branch from 8efd700 to 8275080 Compare August 9, 2024 13:17
@bungle bungle marked this pull request as ready for review August 9, 2024 13:18
@bungle bungle requested review from nowNick and samugi August 9, 2024 13:18
@bungle
Copy link
Member Author

bungle commented Aug 9, 2024

The actual fix is in this commit:
d77324a

@bungle bungle force-pushed the fix/deprecation-merge-order branch from 8275080 to a123edc Compare August 9, 2024 15:26
@bungle bungle force-pushed the fix/deprecation-merge-order branch 2 times, most recently from 711b888 to b077ce0 Compare August 9, 2024 16:18
@pull-request-size pull-request-size bot added size/L and removed size/M labels Aug 9, 2024
@bungle bungle force-pushed the fix/deprecation-merge-order branch 4 times, most recently from 60ffb5e to d77324a Compare August 9, 2024 21:15
@bungle bungle changed the title fix(scheme): deprecated shorthand fields precedence fix(schema): deprecated shorthand fields precedence Aug 9, 2024
@bungle bungle added this to the 3.8.0 milestone Aug 10, 2024
Comment on lines +93 to +95
if (entity.protocols and not entity.route)
or (entity.service and not entity.protocols)
or (entity.route and not entity.protocols)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the idea behind this logic? 🤔 Why protocols and routes are XORed etc.?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question: shouldn't we check for "protocol match" even when both e.g. protocols and route were updated?

Copy link
Member Author

@bungle bungle Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nowNick, @samugi, yes we are checking, but in that case we are skipping RBW because we have information already to do the check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right I misinterpreted the scope of that if block, my bad.

for k, v in pairs(new_values) do
if type(v) == "table" then
data[k] = tablex.merge(data[k] or {}, v, true)
else
data[k] = deprecation and table_merge(v, data[k])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe let's add a comment here to explain why deprecation is tied to shorthands?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with asks like these. It is just that simple ask like this can create considerable amounts of work. Like restarting EE tests 10 times.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment was added.

Comment on lines +93 to +95
if (entity.protocols and not entity.route)
or (entity.service and not entity.protocols)
or (entity.route and not entity.protocols)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question: shouldn't we check for "protocol match" even when both e.g. protocols and route were updated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are the changes in this file related to the fix? I am not sure I understand what changed here.

Copy link
Member Author

@bungle bungle Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samugi again, they are checking, just that we can skip additional RBW (read-before-write) -> we don't need to read database as the information that is needed for the check is already there.

The changes in this file are related to fix. But it also contains optimization (aka no rbw when not needed) - the generic DAO will do RBW on updates always (too). Actually on updates on admin API the admin api does RBW to read plugin name to get correct schema, the DAO does for protocols check and generic dao does it too. The middle one is optimized here to only happen when needed.

kong/db/schema/init.lua Show resolved Hide resolved
@bungle bungle force-pushed the fix/deprecation-merge-order branch 3 times, most recently from 9b66421 to df32e55 Compare August 12, 2024 13:18
### Summary

The shorthand fields e.g. as used in (the url is a shorthand) take
precedence:
```
http PUT :8001/services/test url=http://test.org/ port=2345
```

That means that `port=2345` will be overwritten by http default
port of `80` that is implicit in shorthand field `url`.

This is how it has been for a long long time.

In PR #12686 we added `deprecation` field to shorthand fields definition.

Some of our automatic migrations without database migrations magic use
this functionality, but the precedence there does not good:

```
http -f PUT :8001/plugins/x name=x config.new=test config.old=should_be_ignored
```

In above the `config.old` is a shorthand field with a deprecation property.
Thus it should not overwrite the `config.new`, but in current code base it
does. This PR changes it so that it doesn't do it anymore.

KAG-5134 and https://kongstrong.slack.com/archives/C07AQH7SAF8/p1722589141558609

Signed-off-by: Aapo Talvensaari <[email protected]>
@bungle bungle force-pushed the fix/deprecation-merge-order branch from df32e55 to c8b1604 Compare August 12, 2024 13:21
@bungle bungle merged commit c2e9f99 into master Aug 12, 2024
27 checks passed
@bungle bungle deleted the fix/deprecation-merge-order branch August 12, 2024 14:52
@bungle bungle removed the cherry-pick kong-ee schedule this PR for cherry-picking to kong/kong-ee label Aug 12, 2024
@team-gateway-bot
Copy link
Collaborator

Cherry-pick failed for master, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally.

git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-13486-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-13486-to-master-to-upstream
git checkout -b cherry-pick-13486-to-master-to-upstream
ancref=$(git merge-base 0960f882a944447df02f32390142447d95192d3e c8b1604fb71fdab969bea6f261c12b7a249d058f)
git cherry-pick -x $ancref..c8b1604fb71fdab969bea6f261c12b7a249d058f

@github-actions github-actions bot added the incomplete-cherry-pick A cherry-pick was incomplete and needs manual intervention label Aug 12, 2024
@bungle bungle removed the incomplete-cherry-pick A cherry-pick was incomplete and needs manual intervention label Aug 12, 2024
@bungle
Copy link
Member Author

bungle commented Aug 12, 2024

The EE PR is here:
https://github.com/Kong/kong-ee/pull/9932

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants