-
-
Notifications
You must be signed in to change notification settings - Fork 7k
feat: make mariadb max pool connections controllable via env #6386
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
base: master
Are you sure you want to change the base?
Conversation
CommanderStorm
left a comment
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.
Could you please make sure that all environment variables stick to our existing naming scheme
https://github.com/louislam/uptime-kuma/wiki/Environment-Variables#mariadb-environment-variables
I am also not entirely sure if the min pool size should be configurable. What is the effect there?
It's now following standards and i removed the min connections env |
|
I think it needs some validations. Like checking a empty string, |
CommanderStorm
left a comment
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.
LGTM now, thanks 🙏
Should be uncontroversial and help the few people on a limited pool Mariadb hoster
Head branch was pushed to by a user without write access
|
@CommanderStorm i added validation as Louis said |
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.
Please polish your code one round.
Please instead default to 10 and then add an if statement if the env var contains a valid number.
Number.MAX_SAFE_INTEGER for example is not a sensible max.
Also please log if a value does not get applied.
|
Plus, you don't need to call |
|
Changes:
|
|
@CommanderStorm This is ready |
CommanderStorm
left a comment
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.
The code isn’t yet at a level where I can merge it.
I’ve given more detailed feedback this time - please incorporate those changes, and then we can move forward.
CommanderStorm
left a comment
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 still think that the code quality does not 100% meet what I would like the code to be in terms of readability.
What do you think of my variant of writing ths
| let parsedMaxPoolConnections = parseInt(process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS); | ||
| let error = undefined; | ||
|
|
||
| if (!process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS || Number.isNaN(parsedMaxPoolConnections)) { | ||
| error = "invalid"; | ||
| } else if (parsedMaxPoolConnections < 1) { | ||
| error = "less than 1"; | ||
| } else if (parsedMaxPoolConnections > 100) { | ||
| error = "more than 100"; | ||
| log.warn("db", "We cap pool connections because Mysql/Mariadb connections are heavy. consider using a proxy like ProxySQL or MaxScale."); | ||
| } | ||
|
|
||
| if (error) { | ||
| log.warn("db", `Max database connections defaulted to 10 because UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS was ${error}.`); | ||
| } else { | ||
| log.info("db", `Max database connections: ${parsedMaxPoolConnections}`); | ||
| } |
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.
Your switching on error way of writing this is fairly hard to read.
Lets simplify
| let parsedMaxPoolConnections = parseInt(process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS); | |
| let error = undefined; | |
| if (!process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS || Number.isNaN(parsedMaxPoolConnections)) { | |
| error = "invalid"; | |
| } else if (parsedMaxPoolConnections < 1) { | |
| error = "less than 1"; | |
| } else if (parsedMaxPoolConnections > 100) { | |
| error = "more than 100"; | |
| log.warn("db", "We cap pool connections because Mysql/Mariadb connections are heavy. consider using a proxy like ProxySQL or MaxScale."); | |
| } | |
| if (error) { | |
| log.warn("db", `Max database connections defaulted to 10 because UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS was ${error}.`); | |
| } else { | |
| log.info("db", `Max database connections: ${parsedMaxPoolConnections}`); | |
| } | |
| let parsedMaxPoolConnections = parseInt(process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS); | |
| if (!process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS) { | |
| parsedMaxPoolConnections = 10; | |
| } else if (Number.isNaN(parsedMaxPoolConnections)) { | |
| log.warn("db", "Max database connections defaulted to 10 because UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS was invalid."); | |
| parsedMaxPoolConnections = 10; | |
| } else if (parsedMaxPoolConnections < 1) { | |
| log.warn("db", "Max database connections defaulted to 10 because UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS was less than 1."); | |
| parsedMaxPoolConnections = 10; | |
| } else if (parsedMaxPoolConnections > 100) { | |
| log.warn("db", "Max database connections capped to 100 because Mysql/Mariadb connections are heavy. consider using a proxy like ProxySQL or MaxScale."); | |
| parsedMaxPoolConnections = 100; | |
| } |
| let mariadbPoolConfig = { | ||
| min: 0, | ||
| max: 10, | ||
| max: error ? 10 : parsedMaxPoolConnections, |
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.
| max: error ? 10 : parsedMaxPoolConnections, | |
| max: parsedMaxPoolConnections, |
📋 Overview
I saw an issue saying that mariadb max connections should be controllable through env variables so this PR fixes that with a new env variable:
🛠️ Type of change
📄 Checklist
📷 Screenshots or Visual Changes