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

[Database Template] Enhance Health Function #200

Merged
merged 10 commits into from
Apr 17, 2024

Conversation

H0llyW00dzZ
Copy link
Contributor

@H0llyW00dzZ H0llyW00dzZ commented Mar 27, 2024

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

Problem/Feature

Enhance Health function with comprehensive database connection statistics

Description of Changes:

This is an example where I am using the Fiber framework.

mysql_fiber

Checklist

  • I have self-reviewed the changes being requested
  • I have updated the documentation (if applicable)

@briancbarrow briancbarrow self-requested a review April 4, 2024 12:29
@briancbarrow
Copy link
Collaborator

@H0llyW00dzZ I like this idea. Before accepting the PR though we would need to have it implemented for all the database options.

@H0llyW00dzZ
Copy link
Contributor Author

H0llyW00dzZ commented Apr 4, 2024

@H0llyW00dzZ I like this idea. Before accepting the PR though we would need to have it implemented for all the database options.

@briancbarrow I will need to test it one by one for other databases, as my current implementation supports MySQL using the github.com/go-sql-driver/mysql driver.

@H0llyW00dzZ H0llyW00dzZ changed the title [Database Template] [MYSQL] Enhance Health Function [Database Template] Enhance Health Function Apr 5, 2024
@H0llyW00dzZ
Copy link
Contributor Author

@briancbarrow @Ujstor CI error again

image

@H0llyW00dzZ
Copy link
Contributor Author

deadlock
image

@briancbarrow
Copy link
Collaborator

@H0llyW00dzZ I like this idea. Before accepting the PR though we would need to have it implemented for all the database options.

@briancbarrow I will need to test it one by one for other databases, as my current implementation supports MySQL using the github.com/go-sql-driver/mysql driver.

Yeah, unfortunately we'll need to test each one individually. Time consuming but necessary.

@H0llyW00dzZ
Copy link
Contributor Author

@H0llyW00dzZ I like this idea. Before accepting the PR though we would need to have it implemented for all the database options.

@briancbarrow I will need to test it one by one for other databases, as my current implementation supports MySQL using the github.com/go-sql-driver/mysql driver.

Yeah, unfortunately we'll need to test each one individually. Time consuming but necessary.

@briancbarrow Only MongoDB and Redis need to be tested, as other databases support calling DB.Stats.

@H0llyW00dzZ
Copy link
Contributor Author

bump another example how it work about this:

2024/04/07 18:03:42 [H0llyW00dzZ Project] [VISITOR] Method: GET, Activity: viewed the health of the database - IP: *********, User-Agent: *********** ******** ** ***** ****** **** ****************** ******* **** ****** **************** *************
2024/04/07 18:03:43 [H0llyW00dzZ Project] [INFO] Database Status: It's healthy, Stats: Open Connections: 1, In Use: 0, Idle: 1, Wait Count: 0, Wait Duration: 0s

Note

The format containing * is my perfect implementation for censoring any variadic/formatting object in Golang (e.g., %s, %w, %v, etc.) that is used in production to avoid leaking sensitive information.

- [+] feat(mysql.tmpl): enhance Health function with comprehensive database connection statistics
- [+] fix(mysql.tmpl): update 'message' field in Health() to display actual error message instead of static text
- [+] feat(postgres.tmpl): enhance Health function to return detailed database statistics and health messages
- [+] refactor(dbdriver): remove redundant error message in Health function for both mysql and postgres templates
- [+] feat(postgres.tmpl): import strconv package
- [+] fix(postgres.tmpl): remove unnecessary trailing line at the end of the file
- [+] feat(sqlite.tmpl): enhance Health method with detailed database statistics and health messages
- [+] style(mysql.tmpl): add newline at end of file
- [+] style(sqlite.tmpl): add newline at end of file
- [+] fix(dbdriver): lower threshold for heavy load message from 90 to 40 in mysql, postgres and sqlite templates
@briancbarrow briancbarrow merged commit c02d088 into Melkeydev:main Apr 17, 2024
127 checks passed
@H0llyW00dzZ H0llyW00dzZ deleted the mysql branch May 17, 2024 11:55
@Ujstor Ujstor mentioned this pull request May 29, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants