-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
feat(pdk): increase the precision of JSON number encoding from 14 to 16 decimals #12019
Conversation
as a remember: if some else that use releated: #11389 |
How are we going to solve or mitigate the concern from @tzssangglass ? Is it a bug in cjson package? |
I don't think so. I think we can wrap the |
work for me, but it is a break change. |
8babe20
to
dad99d0
Compare
Didn't read up on the specific case here, but we ran into something similar before, see Tieske/lua-resty-ljsonschema#21 by @vm-001 Just leaving it here as info for whomever wants to double check. |
dad99d0
to
a8740bf
Compare
The PR Tieske/lua-resty-ljsonschema#21 fixed loss precision by string.format, and does not related to cjson lib. |
97a6f1d
to
cb4fdc5
Compare
56e7849
to
88347c5
Compare
decimals With this, we can safely store integers up to 2^53, with no loss of precision. Before the change, cJSON started generating scientific notation output at a much smaller value than 2^53.
…n of 16" This reverts commit dad99d098a77f2c0a3693a767f87a3cb954b5e81.
and has settings with the encoding of numbers with a precision of 16 decimals
503eb0e
to
f9de965
Compare
f9de965
to
9deee70
Compare
@@ -15,15 +17,16 @@ return function(options) | |||
local meta = require "kong.meta" | |||
|
|||
|
|||
local cjson = require("cjson.safe") | |||
cjson.encode_sparse_array(nil, nil, 2^15) | |||
local cjson_safe = require("cjson.safe") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we replace it with kong.tools.cjson
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt you can, since this is in globalpatches, which gets loaded very early on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't simply replace it, because currently, our global patch doesn't set cjson.decode_array_with_array_mt(true)
, whereas kong.tools.cjson
does.
Line 4 in b7a8361
cjson.decode_array_with_array_mt(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got. The code makes me a bit confusing.
Cherry-pick failed for 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-12019-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-12019-to-master-to-upstream
git checkout -b cherry-pick-12019-to-master-to-upstream
ancref=$(git merge-base 2a3a013766d99887f6a0416c2a6abcf0ecae9b27 9deee708395ba714a2813bcdba35638b9bc86bea)
git cherry-pick -x $ancref..9deee708395ba714a2813bcdba35638b9bc86bea |
Simplify the implementation of #12019.
Summary
Currently, when Kong is serializing JSON, it can only encode numbers with a precision of up to 14 decimals. For numbers with a precision exceeding 14 decimals, kong will output them using scientific notation, resulting in a loss of decimal precision. This also causes an issue where KIC cannot use integers exceeding
2^46
bits to configure thepriority
attribute of route.Now, we are increasing this limitation to 16 decimals. With this change, we can safely store integers up to
2^53
bits without losing precision.Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.mdIssue reference
Fix FTI-5515