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(*): reject config if both deprecated and new field defined and their values mismatch #13565

Merged

Conversation

nowNick
Copy link
Contributor

@nowNick nowNick commented Aug 23, 2024

Summary

This PR adds a validation to deprecated fields that checks the case in which both new field and old field were defined; when that happens their values must match.

It introduces a new structure to deprecation definition by adding replaced_with information. This way field validation can verify if the replaced_with field has the same value as the old deprecated field. By default the comparison is done via translation through simple path but there might be instances where translation from old to new is more complicated and then the translation function should be provided in translation field.

The plan is to remove translate_backwards field in the future in favor of replaced_with.

Checklist

  • The Pull Request has tests
  • A changelog file has been created under changelog/unreleased/kong or skip-changelog label added on PR if changelog is unnecessary. README.md
  • There is a user-facing docs PR against https://github.com/Kong/docs.konghq.com - PUT DOCS PR HERE

Issue reference

KAG-5262

@nowNick nowNick force-pushed the fix/reject-config-when-deprecated-field-mismatch-new-field branch from 27cab5b to 493588c Compare August 23, 2024 17:11
kong/db/schema/init.lua Outdated Show resolved Hide resolved
@nowNick nowNick force-pushed the fix/reject-config-when-deprecated-field-mismatch-new-field branch from 9621432 to c24de51 Compare August 27, 2024 07:16
@nowNick nowNick added this to the 3.8.0 milestone Aug 27, 2024
@nowNick nowNick marked this pull request as ready for review August 27, 2024 09:09
@nowNick nowNick marked this pull request as draft August 27, 2024 09:22
@nowNick
Copy link
Contributor Author

nowNick commented Aug 27, 2024

I jumped the gun a little bit - let me add one more test 👀

@nowNick nowNick force-pushed the fix/reject-config-when-deprecated-field-mismatch-new-field branch from c24de51 to 935ca82 Compare August 27, 2024 09:31
@nowNick nowNick requested a review from bungle August 27, 2024 09:56
@nowNick nowNick marked this pull request as ready for review August 27, 2024 09:56
@nowNick nowNick requested a review from samugi August 27, 2024 09:56
@nowNick nowNick force-pushed the fix/reject-config-when-deprecated-field-mismatch-new-field branch from 935ca82 to ea61bad Compare August 27, 2024 09:59
bungle

This comment was marked as resolved.

Copy link
Member

@bungle bungle left a comment

Choose a reason for hiding this comment

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

Just asking.

Comment on lines 55 to +57
translate_backwards = {'server_name'},
deprecation = {
replaced_with = { { path = { 'server_name' } } },
Copy link
Member

Choose a reason for hiding this comment

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

We have translate_backwards and now replaced_with. what is the difference here and what is this path = ..., there is no path = with translate_backwards. Can we use single thing for both?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The plan is to use only one of them - I want to get rid of translate_backwards - however it would require quite a lot code removal so I wanted to get it in another PR. It's going to be a refactor PR so it's not going to block the release.
This addition - although it's a little bit of code duplication I think it's just safer / quicker path. I'll prepare cleanup PRs once this one is merged - I promise 😄

As a bonus I think we can even automate the message - I'm planning to still allow custom message but the way right now it's defined is rather repetitive and it looks like we have all the knowledge we need to generate those deprecation warnings automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Plus... the more I work with it the more I hate the name translate_backwards - it's just confusing. replaced_with inside deprecation right now makes more sense to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

The plan is to use only one of them

If both translate_backwards and replaced_with can fix the bug, we'd better stick with the translate_backwards and avoid introducing an extra metaschema in this PR.

The refactor and introduction of replaced_with can be made in another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately we cannot use only one of the since translate_backwards is a single just a table path and we need to have an array of table paths. The reason is that one field can be replaced by a few fields ex: redis.timeout and redis.connect_timeout / redis.send_timeout / redis.read_timeout.
We need to have a way to check against all 3 of these.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a test case just for that. Maybe it explains it a little bit better: https://github.com/Kong/kong/pull/13565/files#diff-be157ebd3368ec7ae7c30ab60332aebbd18f627ec4fa680156e6d6cd1706f668R4233

kong/db/schema/init.lua Outdated Show resolved Hide resolved
kong/db/schema/init.lua Outdated Show resolved Hide resolved
@nowNick nowNick marked this pull request as draft August 28, 2024 08:59
@nowNick
Copy link
Contributor Author

nowNick commented Aug 28, 2024

I'm changing this back to draft since we've found some issues with this approach and gateway compatibility between the upcoming 3.8 and older versions. Feel free to review this PR but please hold off merging.

kong/db/schema/init.lua Outdated Show resolved Hide resolved
kong/db/schema/init.lua Outdated Show resolved Hide resolved
@nowNick nowNick force-pushed the fix/reject-config-when-deprecated-field-mismatch-new-field branch 2 times, most recently from 537cbab to a3ea812 Compare August 29, 2024 10:03
…eir values mismatch

This commit adds a validation to deprecated fields
that checks if in case both new field and old field were defined -
their values must match.

Note that if one of the fields is null then the validation passes even
if the other is not null.

KAG-5262
@nowNick nowNick force-pushed the fix/reject-config-when-deprecated-field-mismatch-new-field branch from a3ea812 to eabcd44 Compare August 29, 2024 10:17
@nowNick nowNick marked this pull request as ready for review August 29, 2024 10:49
Copy link
Contributor

@jschmid1 jschmid1 left a comment

Choose a reason for hiding this comment

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

1/n

kong/db/schema/init.lua Outdated Show resolved Hide resolved
kong/db/schema/metaschema.lua Outdated Show resolved Hide resolved
kong/db/schema/init.lua Outdated Show resolved Hide resolved
@nowNick nowNick force-pushed the fix/reject-config-when-deprecated-field-mismatch-new-field branch from 2360ef6 to e69e9fb Compare August 29, 2024 12:22
Copy link
Contributor

@StarlightIbuki StarlightIbuki left a comment

Choose a reason for hiding this comment

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

I'm OK with the current version

Copy link
Member

@kikito kikito left a comment

Choose a reason for hiding this comment

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

Approved with a small possible perf optimization when an error is detected

kong/db/schema/init.lua Outdated Show resolved Hide resolved
@kikito kikito merged commit d10408c into master Aug 29, 2024
28 checks passed
@kikito kikito deleted the fix/reject-config-when-deprecated-field-mismatch-new-field branch August 29, 2024 14:57
github-actions bot pushed a commit that referenced this pull request Aug 29, 2024
…eir values mismatch (#13565)

* fix(*): reject config if both deprecated and new field defined and their values mismatch

This commit adds a validation to deprecated fields
that checks if in case both new field and old field were defined -
their values must match.

Note that if one of the fields is null then the validation passes even
if the other is not null.

KAG-5262

* fixup! fix(*): reject config if both deprecated and new field defined and their values mismatch

PR fixes

* fixup! fix(*): reject config if both deprecated and new field defined and their values mismatch

PR fixes 2

(cherry picked from commit d10408c)
@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-13565-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-13565-to-master-to-upstream
git checkout -b cherry-pick-13565-to-master-to-upstream
ancref=$(git merge-base 83de84393fbd7445cb68d72dea36d24890b2fc3a 125c653914ce0eb4f242fdc02ac8eb3dc35cb5c3)
git cherry-pick -x $ancref..125c653914ce0eb4f242fdc02ac8eb3dc35cb5c3

@github-actions github-actions bot added the incomplete-cherry-pick A cherry-pick was incomplete and needs manual intervention label Aug 29, 2024
@team-gateway-bot
Copy link
Collaborator

andrewgkew pushed a commit to andrewgkew/kong that referenced this pull request Sep 5, 2024
…eir values mismatch (Kong#13565)

* fix(*): reject config if both deprecated and new field defined and their values mismatch

This commit adds a validation to deprecated fields
that checks if in case both new field and old field were defined -
their values must match.

Note that if one of the fields is null then the validation passes even
if the other is not null.

KAG-5262

* fixup! fix(*): reject config if both deprecated and new field defined and their values mismatch

PR fixes

* fixup! fix(*): reject config if both deprecated and new field defined and their values mismatch

PR fixes 2
@kikito kikito removed the incomplete-cherry-pick A cherry-pick was incomplete and needs manual intervention label Sep 10, 2024
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.

7 participants