-
Notifications
You must be signed in to change notification settings - Fork 61
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
[#465] Replace cJSON dependancy with the native in-tree json API #477
base: master
Are you sure you want to change the base?
Conversation
Start by putting the definitions into Also, look at the return values from the functions so f.ex. But, you are close on this ! |
Ok so appearantly the issue was the way printing using text was coupled with cJSON which would have wasted a lot of time and effort to debug on it so instead I used the native API's way --> As for the definitions , not sure if I got this right but I tried moving the functions to the Added another commit , I know I should squash but for the sake of readability since this has a lot of changes I let it like this till all is good then ill squash Update: |
e6b9930
to
c38214a
Compare
See CI - always init to |
c38214a
to
c12254f
Compare
@MohanadKh03 See #466 which is next, and how it is done in pgmoneta. You can just follow |
@MohanadKh03 You can do both at the same time if that is easier... and you want to |
It's all good I will fix the memory leaks issue and continue with this one before getting to the 466 if (pgagroal_executable_version_string(&version_buf, version))
{
goto error;
} This is the end of the function which has been like this before my changes so im kinda confused why did it detect a leak only now not before ? free(buffer);
return json;
error:
free(buffer);
return NULL; |
Maybe it depends on the path of the code in question, and likely the Mac builds are using much older software. I use clang 18.x w/ Debug to catch most of them - valgrind is too slow |
... and GitHub have seemed to update their platform yesterday so more reports are coming in now - I'm guessing the |
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 think the work is very good, but the main point I don't like at all is the printing out the whole json stuff in a text tree when the output is specified as text and the verbosity flag is turned on. While text output is not supposed to be stable, do we need to append such a bulk of information?
Second, I'm not sure the idea naming "possibly handling other formats in the future" functions without the json suffix really works: as far as I understand we will use json as the backbone format from now on, so make it clear a function works on json even when is dealing with another format.
// do I need to provide JSON output? | ||
if (output_format == COMMAND_OUTPUT_FORMAT_JSON) | ||
{ | ||
return pgagroal_print_and_free_object(json,FORMAT_JSON); |
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'm not sure this function should not have json
in its name. While I agree that we could have more formats in the future, the function will always print from a json object and free a json object. The printing could be in YAML, as an example, but we start and free always a json struct, right?
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.
Yeah I noticed json was the main format in everything even when printing out text it was basically extracted from json. Makes sense
{ | ||
printf("%s = %s\n", key->valuestring, value->valuestring); | ||
pgagroal_json_print(json,FORMAT_TEXT); |
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.
This is much too information according to me.
If verbose
is specified, the previous version of the application was printing the result and the exit status, e.g.:
% pgagroal-cli conf get max_connections --verbose
max_connections = 10
pgagroal-cli: Success (0)
Now it is printing out the whole json, that is somehow confusing and difficult to parse:
% pgagroal-cli conf get max_connections --verbose
application:
major: 2
minor: 0
name: pgagroal
patch: 0
version: 2.0.0
command:
error: 0
exit-status: 0
name: conf get
output:
key: max_connections
value: 10
status: OK
pgagroal-cli: Success (0)
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 think it about getting the conf get | set
ported to pgmoneta, and then we can work from there
@Jubilee101 Cc:
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.
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.
True I actually thought that by verbose
it meant literally verbose
to print out everything out but now I get it
The second commit is actually more of a trial-and-error tbh but ill rewrite the logic of text format again starting the first commit as a fresh one now that I understand most of the logic
Though in status details
for example isnt it normal to have all the details so the whole object should be printed out right ?
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.
@MohanadKh03 Maybe we should start with pgmoneta's 401 to figure out the best way to extract a single value, or set it...
Because the changes will likely be part of pgagroal's 466 anyway
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.
True I actually thought that by
verbose
it meant literallyverbose
to print out everything out but now I get it The second commit is actually more of a trial-and-error tbh but ill rewrite the logic of text format again starting the first commit as a fresh one now that I understand most of the logic Though instatus details
for example isnt it normal to have all the details so the whole object should be printed out right ?
Well, details
is a very rich command, and it is text printed in a kind of tabular data. We could simplify the output by simply printing out the json object, but I would not change the current text format too much in order to not "scary" users that could have been scripting on the text output.
That's also why --verbose
should not be the implementation of a dump
command, according to me.
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.
@fluca1978 Take a look at the output from pgmoneta - it is A LOT easier to maintain. And, this is a 2.0 release, so I/O and management will change... maybe people may just use tools like jq
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.
@jesperpedersen After reading pgmoneta's way imo it's much easier to read and maintain tbh compared to the current pgagroal's way
So do you suggest holding this PR off until 401 in pgmoneta is done and then we can standardize the IO,Management in both pgmoneta and pgagroal ?
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.
@MohanadKh03 Yes, the management part should be unified across pgagroal, pgmoneta and pgexporter.
@decarv is taking care of the I/O part
Replaced cJSON completely with the native json parser.
Tested manually using the following commands from the docs user guide section 6.4 JSON Output Format
pgagroal-cli conf ls --format json
pgagroal-cli conf set max_connections 1000 --format json
pgagroal-cli status --format json
pgagroal-cli ping --format json
Though I noticed that when using text format it gave a status of 1 and exits for some reason ?
After debugging I think the problem is that some exit status is not what it should be I think ? I am kind of stuck in it cuz now it's only working with json formats not text somehow