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

feat: support to configure max database connections for site database users #2316

Merged
merged 17 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
3951202
chore(site): remove database access related fields and add field for …
tanmoysrt Nov 28, 2024
95a6839
chore(site): remove `Show Database Credentials` button from site actions
tanmoysrt Nov 28, 2024
400935f
chore(site): remove redundant agent callback for database access
tanmoysrt Nov 28, 2024
e3d8cc7
chore(site-database-user): add field for max database connection
tanmoysrt Nov 28, 2024
2427ded
chore(site-database-user): validation added for max database connection
tanmoysrt Nov 28, 2024
953586a
chore(site-database-user): while calling agent apis pass max database…
tanmoysrt Nov 29, 2024
a8cdb1f
chore(site-database-user): set default max database connections to 16
tanmoysrt Nov 29, 2024
62a1269
chore(site-database-user): rename max_database_connections to max_con…
tanmoysrt Nov 29, 2024
a6419e0
feat(site-database-user): ui updated to allow setting up database use…
tanmoysrt Nov 29, 2024
fc969b1
Merge branch 'master' into limit_user_connection_limit
tanmoysrt Nov 29, 2024
36918e1
feat(site-database-user): added field for label of db user cred
tanmoysrt Nov 29, 2024
ad5f60f
feat(site-database-user): label for site database user added
tanmoysrt Nov 29, 2024
b872087
feat(site-database-user): show database user label in list view
tanmoysrt Nov 29, 2024
0e82652
feat(site-database-user): write patch to fill label for existing db u…
tanmoysrt Nov 29, 2024
b09ff4b
Merge branch 'master' into limit_user_connection_limit
tanmoysrt Dec 2, 2024
f1fb163
Merge branch 'master' into limit_user_connection_limit
tanmoysrt Dec 2, 2024
af22760
chore(site-database-user): allow support to configure only label of user
tanmoysrt Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions dashboard/src2/components/SiteDatabaseAccessDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Dialog
:options="{
title: 'Manage Database Users',
size: planSupportsDatabaseAccess ? '2xl' : 'xl'
size: planSupportsDatabaseAccess ? '3xl' : 'xl'
}"
v-model="show"
>
Expand Down Expand Up @@ -122,7 +122,7 @@ export default {
site: this.site,
status: ['!=', 'Archived']
},
searchField: 'username',
searchField: 'label',
filterControls() {
return [
{
Expand All @@ -135,9 +135,9 @@ export default {
},
columns: [
{
label: 'Username',
fieldname: 'username',
width: 1
label: 'Label',
fieldname: 'label',
width: '150px'
},
{
label: 'Status',
Expand All @@ -146,6 +146,13 @@ export default {
align: 'center',
type: 'Badge'
},
{
label: 'DB Connections',
fieldname: 'max_connections',
width: 0.5,
align: 'center',
format: value => `${value} Connection` + (value > 1 ? 's' : '')
},
{
label: 'Mode',
fieldname: 'mode',
Expand All @@ -168,7 +175,7 @@ export default {
}
],
rowActions: ({ row, listResource, documentResource }) => {
if (row.status === 'Archived') {
if (row.status === 'Archived' || row.status === 'Pending') {
return [];
}
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
type="error"
>
</AlertBanner>
<FormControl
class="mt-2"
type="text"
size="sm"
variant="subtle"
label="Label (to identify the user)"
v-model="label"
/>
<FormControl
type="select"
:options="[
Expand All @@ -40,6 +48,15 @@
label="Access Mode"
v-model="mode"
/>
<FormControl
v-if="!isEditMode"
class="mt-2"
type="number"
size="sm"
variant="subtle"
label="Database Connections"
v-model="database_connections"
/>
<!-- Permission configuration for Granular Mode -->
<div v-if="mode == 'granular'">
<div
Expand Down Expand Up @@ -130,7 +147,9 @@ export default {
},
data() {
return {
label: '',
mode: 'read_only',
database_connections: 1,
permissions: [],
lastGeneratedRowId: 0
};
Expand Down Expand Up @@ -163,6 +182,7 @@ export default {
name: this.db_user_name,
auto: false,
onSuccess: data => {
this.label = data?.label;
this.mode = data?.mode;
let fetched_permissions = (data?.permissions ?? []).map(x => {
return {
Expand All @@ -171,6 +191,7 @@ export default {
};
});
this.permissions = fetched_permissions;
this.database_connections = data?.max_connections ?? 1;
}
};
},
Expand All @@ -192,10 +213,12 @@ export default {
return {
doc: {
doctype: 'Site Database User',
label: this.label,
team: this.$team.doc.name,
site: this.site,
mode: this.mode,
permissions: permissions
permissions: permissions,
max_connections: parseInt(this.database_connections || 1)
}
};
},
Expand Down Expand Up @@ -225,6 +248,7 @@ export default {
dn: this.db_user_name,
method: 'save_and_apply_changes',
args: {
label: this.label,
mode: this.mode,
permissions: permissions
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
Password: {{ databaseCredential?.password }}
</p>
<p class="ml-1 font-mono text-sm">Use SSL: Yes</p>
<p class="ml-1 font-mono text-sm">
Max Database Connection{{
databaseCredential?.max_connections > 1 ? 's' : ''
}}: {{ databaseCredential?.max_connections }}
</p>
</div>
<div class="pb-2 pt-5">
<p class="mb-2 text-base font-semibold text-gray-700">
Expand Down
11 changes: 10 additions & 1 deletion press/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,12 +620,21 @@ def remove_ssh_user(self, bench):
)

def add_proxysql_user(
self, site, database, username, password, database_server, reference_doctype=None, reference_name=None
self,
site,
database: str,
username: str,
password: str,
max_connections: int,
database_server,
reference_doctype=None,
reference_name=None,
):
data = {
"username": username,
"password": password,
"database": database,
"max_connections": max_connections,
"backend": {"ip": database_server.private_ip, "id": database_server.server_id},
}
return self.create_agent_job(
Expand Down
1 change: 1 addition & 0 deletions press/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,4 @@ press.patches.v0_7_0.update_enable_performance_tuning
press.press.doctype.server.patches.set_plan_and_subscription
press.patches.v0_7_0.move_site_db_access_users_to_site_db_perm_manager
press.press.doctype.drip_email.patches.set_correct_field_for_html
press.patches.v0_7_0.set_label_for_site_database_user
12 changes: 12 additions & 0 deletions press/patches/v0_7_0/set_label_for_site_database_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import frappe


def execute():
db_users = frappe.get_all(
"Site Database User",
filters={"status": ("!=", "Archived")},
fields=["name", "username"],
)

for db_user in db_users:
frappe.db.set_value("Site Database User", db_user.name, "label", f"User {db_user.username}")
11 changes: 1 addition & 10 deletions press/press/doctype/agent_job/agent_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,6 @@ def process_job_updates(job_name: str, response_data: dict | None = None): # no
process_setup_erpnext_site_job_update,
)
from press.press.doctype.site.site import (
process_add_proxysql_user_job_update,
process_archive_site_job_update,
process_complete_setup_wizard_job_update,
process_create_user_job_update,
Expand All @@ -905,7 +904,6 @@ def process_job_updates(job_name: str, response_data: dict | None = None): # no
process_move_site_to_bench_job_update,
process_new_site_job_update,
process_reinstall_site_job_update,
process_remove_proxysql_user_job_update,
process_rename_site_job_update,
process_restore_job_update,
process_restore_tables_job_update,
Expand Down Expand Up @@ -979,16 +977,9 @@ def process_job_updates(job_name: str, response_data: dict | None = None): # no
process_add_ssh_user_job_update(job)
elif job.job_type == "Remove User from Proxy":
process_remove_ssh_user_job_update(job)
elif job.job_type == "Add User to ProxySQL":
elif job.job_type == "Add User to ProxySQL" or job.job_type == "Remove User from ProxySQL":
if job.reference_doctype == "Site Database User":
SiteDatabaseUser.process_job_update(job)
else:
process_add_proxysql_user_job_update(job)
elif job.job_type == "Remove User from ProxySQL":
if job.reference_doctype == "Site Database User":
SiteDatabaseUser.process_job_update(job)
else:
process_remove_proxysql_user_job_update(job)
elif job.job_type == "Reload NGINX":
process_update_nginx_job_update(job)
elif job.job_type == "Move Site to Bench":
Expand Down
23 changes: 0 additions & 23 deletions press/press/doctype/site/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,29 +185,6 @@ frappe.ui.form.on('Site', {
});
frm.toggle_enable(['host_name'], frm.doc.status === 'Active');

if (frm.doc.is_database_access_enabled) {
frm.add_custom_button(
__('Show Database Credentials'),
() =>
frm.call('get_database_credentials').then((r) => {
let message = `Host: ${r.message.host}

Port: ${r.message.port}

Database: ${r.message.database}

Username: ${r.message.username}

Password: ${r.message.password}

\`\`\`\nmysql -u ${r.message.username} -p${r.message.password} -h ${r.message.host} -P ${r.message.port} --ssl --ssl-verify-server-cert\n\`\`\``;

frappe.msgprint(frappe.markdown(message), 'Database Credentials');
}),
__('Actions'),
);
}

frm.add_custom_button(
__('Replicate Site'),
() => {
Expand Down
44 changes: 8 additions & 36 deletions press/press/doctype/site/site.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@
"setup_wizard_status_check_retries",
"setup_wizard_status_check_next_retry_on",
"database_section",
"is_database_access_enabled",
"database_access_mode",
"column_break_lfuz",
"database_access_user",
"database_access_password",
"database_access_connection_limit",
"saas_section",
"is_standby",
"standby_for",
Expand Down Expand Up @@ -452,13 +448,6 @@
"fieldtype": "Section Break",
"label": "Database Access"
},
{
"default": "0",
"fieldname": "is_database_access_enabled",
"fieldtype": "Check",
"label": "Is Database Access Enabled",
"read_only": 1
},
{
"fieldname": "standby_for",
"fieldtype": "Link",
Expand Down Expand Up @@ -528,29 +517,6 @@
"fieldtype": "Check",
"label": "Hide Config"
},
{
"fieldname": "database_access_password",
"fieldtype": "Password",
"label": "Database Access Password",
"read_only": 1
},
{
"fieldname": "database_access_mode",
"fieldtype": "Select",
"label": "Database Access Mode",
"options": "\nread_only\nread_write",
"read_only": 1
},
{
"fieldname": "column_break_lfuz",
"fieldtype": "Column Break"
},
{
"fieldname": "database_access_user",
"fieldtype": "Data",
"label": "Database Access User",
"read_only": 1
},
{
"collapsible": 1,
"fieldname": "backups_section",
Expand Down Expand Up @@ -628,6 +594,12 @@
"fieldname": "setup_wizard_status_check_next_retry_on",
"fieldtype": "Datetime",
"label": "Next Retry On"
},
{
"default": "16",
"fieldname": "database_access_connection_limit",
"fieldtype": "Int",
"label": "Database Access Connection Limit"
}
],
"links": [
Expand Down Expand Up @@ -702,7 +674,7 @@
"link_fieldname": "site"
}
],
"modified": "2024-11-04 09:40:44.252728",
"modified": "2024-11-28 15:40:02.431631",
"modified_by": "Administrator",
"module": "Press",
"name": "Site",
Expand Down
18 changes: 2 additions & 16 deletions press/press/doctype/site/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ class Site(Document, TagHelpers):
current_cpu_usage: DF.Int
current_database_usage: DF.Int
current_disk_usage: DF.Int
database_access_mode: DF.Literal["", "read_only", "read_write"]
database_access_password: DF.Password | None
database_access_user: DF.Data | None
database_access_connection_limit: DF.Int
database_name: DF.Data | None
domain: DF.Link | None
erpnext_consultant: DF.Link | None
Expand All @@ -136,7 +134,6 @@ class Site(Document, TagHelpers):
hide_config: DF.Check
host_name: DF.Data | None
hybrid_saas_pool: DF.Link | None
is_database_access_enabled: DF.Check
is_erpnext_setup: DF.Check
is_standby: DF.Check
notify_email: DF.Data | None
Expand Down Expand Up @@ -189,7 +186,7 @@ class Site(Document, TagHelpers):
"cluster",
"bench",
"group",
"is_database_access_enabled",
"database_access_connection_limit",
"trial_end_date",
"tags",
"server",
Expand Down Expand Up @@ -3038,17 +3035,6 @@ def process_rename_site_job_update(job): # noqa: C901
create_site_status_update_webhook_event(job.site)


# TODO
def process_add_proxysql_user_job_update(job):
if job.status == "Success":
frappe.db.set_value("Site", job.site, "is_database_access_enabled", True)


def process_remove_proxysql_user_job_update(job):
if job.status == "Success":
frappe.db.set_value("Site", job.site, "is_database_access_enabled", False)


def process_move_site_to_bench_job_update(job):
updated_status = {
"Pending": "Pending",
Expand Down
Loading
Loading