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

JsonEncode(): serialize integers w/o trailing .0 #8697

Merged
merged 1 commit into from
Mar 25, 2021
Merged

Conversation

Al2Klimov
Copy link
Member

... so Icinga DB can parse them as integers.

@Al2Klimov Al2Klimov added bug Something isn't working area/icingadb New backend labels Mar 23, 2021
@icinga-probot icinga-probot bot added this to the 2.13.0 milestone Mar 23, 2021
@Al2Klimov
Copy link
Member Author

Before

$ redis-cli hgetall icinga:config:zone
1) "8f4f44e4157cf0c72575e46bf7dc34afdc41586d"
2) "{\"depth\":0.0,\"environment_id\":\"da39a3ee5e6b4b0d3255bfef95601890afd80709\",\"is_global\":true,\"name\":\"director-global\",\"name_checksum\":\"eb0f7c06c2d1223428158205496d2b40d5eed02a\"}"
3) "eacc957a8198ba4f157edc29993912b219559aa5"
4) "{\"depth\":0.0,\"environment_id\":\"da39a3ee5e6b4b0d3255bfef95601890afd80709\",\"is_global\":true,\"name\":\"global-templates\",\"name_checksum\":\"a78b3be036345b12649b2814068d62033b8639fb\"}"
5) "5ffd3470e558666b25ccd505c329faa0f1932596"
6) "{\"depth\":0.0,\"environment_id\":\"da39a3ee5e6b4b0d3255bfef95601890afd80709\",\"is_global\":false,\"name\":\"Alexanders-MacBook-Pro.local\",\"name_checksum\":\"aa0db2d5375043173db4a7b4c95a919a056c8355\"}"
$

After

$ redis-cli hgetall icinga:config:zone
1) "8f4f44e4157cf0c72575e46bf7dc34afdc41586d"
2) "{\"depth\":0,\"environment_id\":\"da39a3ee5e6b4b0d3255bfef95601890afd80709\",\"is_global\":true,\"name\":\"director-global\",\"name_checksum\":\"eb0f7c06c2d1223428158205496d2b40d5eed02a\"}"
3) "eacc957a8198ba4f157edc29993912b219559aa5"
4) "{\"depth\":0,\"environment_id\":\"da39a3ee5e6b4b0d3255bfef95601890afd80709\",\"is_global\":true,\"name\":\"global-templates\",\"name_checksum\":\"a78b3be036345b12649b2814068d62033b8639fb\"}"
5) "5ffd3470e558666b25ccd505c329faa0f1932596"
6) "{\"depth\":0,\"environment_id\":\"da39a3ee5e6b4b0d3255bfef95601890afd80709\",\"is_global\":false,\"name\":\"Alexanders-MacBook-Pro.local\",\"name_checksum\":\"aa0db2d5375043173db4a7b4c95a919a056c8355\"}"
$

Copy link
Contributor

@julianbrost julianbrost left a comment

Choose a reason for hiding this comment

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

That's indeed one of the things that I find quite strange (especially these 200.0 status codes), so I'm happy to see this addressed. I remember writing workarounds for this in Python ages ago.

You should be able to parse a JSON int into a float/double value. However, for example in Go, unmarshalling into interface{} and then type asserting into float64 will break, so with some weird code, this might be incompatible.

Regarding the other side (so Icinga DB in this case): we still have to be careful to only try to parse values into ints for which we know for sure that this code will never return any decimals.

lib/base/json.cpp Outdated Show resolved Hide resolved
... so Icinga DB can parse them as integers.
@julianbrost julianbrost merged commit e1c6e53 into master Mar 25, 2021
@Al2Klimov Al2Klimov deleted the bugfix/json-int branch May 26, 2021 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/icingadb New backend bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants