Melkeydev / go-blueprint

Go-blueprint allows users to spin up a quick Go project using a popular framework
MIT License
2.07k stars 141 forks source link

[Database Template] Enhance Health Function #200

Closed H0llyW00dzZ closed 1 month ago

H0llyW00dzZ commented 1 month ago

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

briancbarrow commented 1 month ago

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

H0llyW00dzZ commented 1 month ago

@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 commented 1 month ago

@briancbarrow @Ujstor CI error again

image

H0llyW00dzZ commented 1 month ago

deadlock image

briancbarrow commented 1 month ago

@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 commented 1 month ago

@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 commented 1 month ago

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.