Skip to content

[#174] Add JSON configuration support for pgexporter metrics - #178

Closed
bassamadnan wants to merge 1 commit into
pgexporter:mainfrom
bassamadnan:json-config
Closed

bassamadnan wants to merge 1 commit into
pgexporter:mainfrom
bassamadnan:json-config

Conversation

@bassamadnan

Copy link
Copy Markdown
Collaborator

This is to support custom matrics by specifying a JSON path, this can be run from source using the -J flag, addressing #174.

Examples from the current contrib/yaml have also been added to the new directory contrib/json and only one flag (either -Y or -J) is allowed to be set at a time. To run:

./pgexporter -c /path/to/pgexporter.conf -u /path/to/pgexporter_users.conf -J /path/to/json/directory/

Much like the YAML, this also has file support (-J /path/to/json/file/).

@jesperpedersen

Copy link
Copy Markdown
Contributor

@resyfer Can you take a look ?

* @return 0 upon success, otherwise 1
*/
int
pgexporter_read_json(struct prometheus* prometheus, int prometheus_idx, char* filename, int* number_of_metrics);

@Jubilee101 Jubilee101 Feb 26, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi, the json APIs are actually migrated from pgexporter's sister project pgmoneta, where it's a few updates ahead, one of which includes a pgmoneta_json_read_file(). I'm pretty sure that's what you need. Could you migrate it from pgmoneta to json.c and use that instead? We try to keep the core APIs consistent across projects but I'm pretty tied up lately.

You'll need to remove some of the duplicated implementations (sorry about that), but I think you can still keep most of your work. Remember, that you'll need to change the prefix from pgmoneta_ to pgexporter_

If you need anything just let me know.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hi, I will look into it. I will go through pgmoneta's implementation for the APIs i have used from pgexporter's json.c and import over whatever is needed to itself. Just to be sure though, should i make these changes in the current PR or raise an issue for importing (& updating) current implementations?

Thank you for bringing this to my attention, will be happy to work on this as well.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hey,

Hi, I will look into it. I will go through pgmoneta's implementation for the APIs i have used from pgexporter's json.c and import over whatever is needed to itself.

Great! I would only port things related to read_file. We have had some other fixes and changes here and there so it's quite trivial to pick up all of them. We probably would just do a complete copy'n'paste some other day. Nevertheless, feel free to go through the APIs and propose ideas if you have any, we are pretty proud of our JSON APIs.

Just to be sure though, should i make these changes in the current PR or raise an issue for importing (& updating) current implementations?

Core API migration is under issue #141, so make sure you tag your commit with that issue number. I'm fine with either do this in one PR or in a separate one. @jesperpedersen Thoughts?

Thank you for bringing this to my attention, will be happy to work on this as well.

Thank you for working on this! Welcome to the community~

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@bassamadnan Try and port all the core APIs to here in a separate pull request. If it is just the function then you can do it in this pull request

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hey, seems that #141 has been closed. So we opened #179 for you. If you are only porting read_file then feel free to just do it in this PR. Thank you.

@jesperpedersen

Copy link
Copy Markdown
Contributor

You can rebase this now.

Remember to add yourself to the manuals too, and describe the feature

@bassamadnan

Copy link
Copy Markdown
Collaborator Author

i've added myself to the AUTHORS in this PR if that is what we are talking about. Also in doc/manual i'll add a user-13-json.md (renumbering the extension.md to 14). The contents of it would be roughly the same as doc/JSON.md in this PR (since its the same for the manual of YAML as well) and i hope that is fine. Working on the rebase right now

@jesperpedersen

Copy link
Copy Markdown
Contributor

There are a few more files ... see my latest commit

@bassamadnan

Copy link
Copy Markdown
Collaborator Author

@jesperpedersen something i just noticed with the recent merge is this:

  1. I run
./src/pgexporter -c ./config/pgexporter.conf -u ./config/pgexporter_users.conf -Y /home/bassam/Documents/os/pgexporter/contrib/yaml/
  1. I run prometheus to pull metrics
  2. the logs has these errors:
2025-03-01 18:17:41 DEBUG main.c:955 Configuration size: 737600
2025-03-01 18:17:41 DEBUG main.c:956 Known users: 1
2025-03-01 18:17:41 DEBUG main.c:957 Known admins: 0
2025-03-01 18:18:07 DEBUG main.c:1359 pgexporter: Transfer connection: Server 0 FD 11
2025-03-01 18:18:22 ERROR message.c:851 SSL_ERROR_SSL: Success (9)
2025-03-01 18:18:22 ERROR message.c:852 Reason: decryption failed or bad record mac
2025-03-01 18:18:22 DEBUG main.c:1359 pgexporter: Transfer connection: Server 0 FD 12
2025-03-01 18:18:37 ERROR message.c:935 SSL_ERROR_SSL: Success (-1)
2025-03-01 18:18:37 ERROR message.c:936 Reason: uninitialized
2025-03-01 18:18:37 DEBUG main.c:1359 pgexporter: Transfer connection: Server 0 FD 13
2025-03-01 18:18:52 ERROR message.c:935 SSL_ERROR_SSL: Success (-1)
2025-03-01 18:18:52 ERROR message.c:936 Reason: uninitialized
2025-03-01 18:18:52 DEBUG main.c:1359 pgexporter: Transfer connection: Server 0 FD 14
2025-03-01 18:19:07 ERROR message.c:935 SSL_ERROR_SSL: Success (-1)
2025-03-01 18:19:07 ERROR message.c:936 Reason: uninitialized
2025-03-01 18:19:07 DEBUG main.c:1359 pgexporter: Transfer connection: Server 0 FD 15
2025-03-01 18:19:22 ERROR message.c:935 SSL_ERROR_SSL: Success (-1)

should this be a matter of concern?

also for the JSON thing im trying out i have these logs:

2025-03-01 18:21:35 DEBUG main.c:986 Known users: 1
2025-03-01 18:21:35 DEBUG main.c:987 Known admins: 0
2025-03-01 18:21:52 DEBUG main.c:1389 pgexporter: Transfer connection: Server 0 FD 11
2025-03-01 18:22:07 ERROR message.c:851 SSL_ERROR_SSL: Success (9)
2025-03-01 18:22:07 ERROR message.c:852 Reason: decryption failed or bad record mac
2025-03-01 18:22:07 DEBUG main.c:1389 pgexporter: Transfer connection: Server 0 FD 12

This is likely due to memory leaks im assuming? trying to fix this ATM (these do not seem to come from the latest changes, but was a bug in this PR itself)

@jesperpedersen

Copy link
Copy Markdown
Contributor

Do

cmake -DCMAKE_C_COMPILER=clang -DCMAKE_BUILD_TYPE=Debug ..

that will enable ASAN and give you more clues, but yes, it is something that need to be investigated

@bassamadnan

bassamadnan commented Mar 1, 2025 •

Copy link
Copy Markdown
Collaborator Author

thanks, will try to fix the json issue asap. this is also reproduceable with simple curl requests on pgexporter/metrics
edit: The issue was me, using the entire JSON directory with the J flag where some of the queries were incompatible with my postgres version (16). Got derped on this one.

@bassamadnan
bassamadnan force-pushed the json-config branch 2 times, most recently from 5386820 to 7a8d747 Compare March 2, 2025 10:53
@bassamadnan

Copy link
Copy Markdown
Collaborator Author

updated the code to use the recently imported pgexporter_json_read_file from json.h should be ready for review,

@jesperpedersen

Copy link
Copy Markdown
Contributor

Rebased, and merged.

Thanks for your contribution !

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

Labels

feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants