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: add support to record performance report of database #1395

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e749091
feat: add performance report doctype and functions
tanmoysrt Jan 28, 2024
c96c8b4
feat: add cronjob
tanmoysrt Jan 28, 2024
27f5441
feat: cleanup
tanmoysrt Jan 29, 2024
81e041d
chore: remove transactions perf schema consumer
tanmoysrt Jan 29, 2024
17888f8
feat: top_io_by_file_activity_report added
tanmoysrt Jan 30, 2024
3dbcee3
feat: top_io_by_file_by_time added
tanmoysrt Jan 30, 2024
4225ea1
feat: additional doctype for other perf schema has been added
tanmoysrt Jan 31, 2024
7b3bc06
chore: rename
tanmoysrt Jan 31, 2024
76a0d0e
feat: hotspot section completed
tanmoysrt Feb 1, 2024
4bb8a03
feat: make child table readonly
tanmoysrt Feb 1, 2024
2881dcc
feat: all section completed
tanmoysrt Feb 2, 2024
750e289
Merge branch 'master' into performance_report
tanmoysrt Feb 2, 2024
dcf536a
feat: option to fetch selected reports
tanmoysrt Feb 2, 2024
939f700
chore: remove js to remove checkbox
tanmoysrt Feb 2, 2024
9c47b18
chore: remove extra files
tanmoysrt Feb 2, 2024
1ded2e9
chore: run cronjob after every 15 minutes
tanmoysrt Feb 2, 2024
18a31da
feat: button to multiply billion with count and time field has been a…
tanmoysrt Feb 3, 2024
f797447
feat: add a intro notice after multiply
tanmoysrt Feb 3, 2024
fff327c
chore: remove enqueue now
tanmoysrt Feb 4, 2024
af10278
feat: add performance reports to database server dashboard
tanmoysrt Feb 4, 2024
7c3a7b5
Merge branch 'master' into performance_report
tanmoysrt Feb 4, 2024
ec90914
chore: remove junk doctype
tanmoysrt Feb 4, 2024
8d59f09
chore: remove junk doctype
tanmoysrt Feb 4, 2024
fdcf03b
Merge branch 'master' into performance_report
tanmoysrt Feb 8, 2024
c90e2c5
fix: resolve merge conflicts
tanmoysrt Feb 8, 2024
3396707
fix: default keep sections close
tanmoysrt Feb 8, 2024
9ac686b
Merge branch 'master' into performance_report
tanmoysrt Feb 8, 2024
5491333
Merge branch 'master' into performance_report
tanmoysrt Feb 11, 2024
0d2b613
Merge branch 'master' into performance_report
tanmoysrt Feb 16, 2024
9ba798c
Merge branch 'master' into performance_report
ankush Mar 18, 2024
5e2c8f5
chore: fix lint
tanmoysrt Mar 19, 2024
7ad47d9
Merge branch 'master' into performance_report
tanmoysrt Mar 22, 2024
559984b
Merge branch 'master' into performance_report
tanmoysrt May 31, 2024
831b988
Merge branch 'master' into performance_report
tanmoysrt Sep 13, 2024
51b9343
Merge branch 'master' into performance_report
tanmoysrt Sep 17, 2024
99fc8c4
fix: lint issue
tanmoysrt Sep 17, 2024
966bd55
feat: moved fetching tasks to agent job
tanmoysrt Sep 18, 2024
b8a66e8
chore: on disabling perf schema, disable auto fetch as well
tanmoysrt Sep 18, 2024
c356d14
chore: rename doctype to db performance report
tanmoysrt Sep 18, 2024
cbfaa6b
chore: delete perf report of more than 7 day old
tanmoysrt Sep 18, 2024
dce0455
chore: lint
tanmoysrt Sep 18, 2024
ab8df8c
Merge branch 'master' into performance_report
tanmoysrt Sep 18, 2024
96a2a9a
chore: typo
tanmoysrt Sep 18, 2024
86aa9ca
Merge branch 'master' into performance_report
tanmoysrt Sep 25, 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
47 changes: 47 additions & 0 deletions press/agent.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# -*- coding: utf-8 -*-

Check failure on line 1 in press/agent.py

View workflow job for this annotation

GitHub Actions / Lint and Format

Ruff (UP009)

press/agent.py:1:1: UP009 UTF-8 encoding declaration is unnecessary
# Copyright (c) 2020, Frappe and contributors
# For license information, please see license.txt
from contextlib import suppress
import _io
import json
import os
from datetime import date
from typing import TYPE_CHECKING, List

import frappe
import requests
from frappe.utils.password import get_decrypted_password

from press.utils import log_error, sanitize_config

if TYPE_CHECKING:

Check failure on line 17 in press/agent.py

View workflow job for this annotation

GitHub Actions / Lint and Format

Ruff (I001)

press/agent.py:4:1: I001 Import block is un-sorted or un-formatted
from io import BufferedReader

from press.press.doctype.app_patch.app_patch import AgentPatchConfig, AppPatch
from press.press.doctype.agent_job.agent_job import AgentJob
from press.press.doctype.site.site import Site

Check failure on line 23 in press/agent.py

View workflow job for this annotation

GitHub Actions / Lint and Format

Ruff (I001)

press/agent.py:18:1: I001 Import block is un-sorted or un-formatted

class Agent:
if TYPE_CHECKING:
Expand All @@ -28,7 +28,7 @@

from requests import Response

response: "Optional[Response]"

Check failure on line 31 in press/agent.py

View workflow job for this annotation

GitHub Actions / Lint and Format

Ruff (FA100)

press/agent.py:31:14: FA100 Add `from __future__ import annotations` to simplify `typing.Optional`

def __init__(self, server, server_type="Server"):
self.server_type = server_type
Expand Down Expand Up @@ -126,7 +126,7 @@
as_dict=1,
)

def new_site(self, site, create_user: dict = None):

Check failure on line 129 in press/agent.py

View workflow job for this annotation

GitHub Actions / Lint and Format

Ruff (RUF013)

press/agent.py:129:40: RUF013 PEP 484 prohibits implicit `Optional`
apps = [app.app for app in site.apps]

data = {
Expand Down Expand Up @@ -189,7 +189,7 @@
)

def rename_site(
self, site, new_name: str, create_user: dict = None, config: dict = None

Check failure on line 192 in press/agent.py

View workflow job for this annotation

GitHub Actions / Lint and Format

Ruff (RUF013)

press/agent.py:192:43: RUF013 PEP 484 prohibits implicit `Optional`

Check failure on line 192 in press/agent.py

View workflow job for this annotation

GitHub Actions / Lint and Format

Ruff (RUF013)

press/agent.py:192:64: RUF013 PEP 484 prohibits implicit `Optional`
):
data = {"new_name": new_name}
if create_user:
Expand Down Expand Up @@ -236,7 +236,7 @@
site=site.name,
)

def rename_upstream_site(self, server: str, site, new_name: str, domains: List[str]):

Check failure on line 239 in press/agent.py

View workflow job for this annotation

GitHub Actions / Lint and Format

Ruff (FA100)

press/agent.py:239:76: FA100 Add `from __future__ import annotations` to simplify `typing.List`
_server = frappe.get_doc("Server", server)
ip = _server.ip if _server.is_self_hosted else _server.private_ip
data = {"new_name": new_name, "domains": domains}
Expand Down Expand Up @@ -517,13 +517,13 @@
"Add Wildcard Hosts to Proxy", "proxy/wildcards", wildcards
)

def setup_redirects(self, site: str, domains: List[str], target: str):

Check failure on line 520 in press/agent.py

View workflow job for this annotation

GitHub Actions / Lint and Format

Ruff (FA100)

press/agent.py:520:48: FA100 Add `from __future__ import annotations` to simplify `typing.List`
data = {"domains": domains, "target": target}
return self.create_agent_job(
"Setup Redirects on Hosts", "proxy/hosts/redirects", data, site=site
)

def remove_redirects(self, site: str, domains: List[str]):

Check failure on line 526 in press/agent.py

View workflow job for this annotation

GitHub Actions / Lint and Format

Ruff (FA100)

press/agent.py:526:49: FA100 Add `from __future__ import annotations` to simplify `typing.List`
data = {"domains": domains}
return self.create_agent_job(
"Remove Redirects on Hosts",
Expand Down Expand Up @@ -1144,6 +1144,53 @@
]
return apps

def get_db_performance_report(self):
server_record = frappe.get_doc("Database Server", self.server)
reports_is_enabled_status = {

Check warning on line 1149 in press/agent.py

View check run for this annotation

Codecov / codecov/patch

press/agent.py#L1148-L1149

Added lines #L1148 - L1149 were not covered by tests
"total_allocated_memory": server_record.is_total_allocated_memory_perf_report_enabled,
"top_memory_by_event": server_record.is_top_memory_by_event_perf_report_enabled,
"top_memory_by_user": server_record.is_top_memory_by_user_perf_report_enabled,
"top_memory_by_host": server_record.is_top_memory_by_host_perf_report_enabled,
"top_memory_by_thread": server_record.is_top_memory_by_thread_perf_report_enabled,
"top_io_by_file_activity_report": server_record.is_top_io_by_file_activity_report_perf_report_enabled,
"top_io_by_file_by_time": server_record.is_top_io_by_file_by_time_perf_report_enabled,
"top_io_by_event_category": server_record.is_top_io_by_event_category_perf_report_enabled,
"top_io_in_time_by_event_category": server_record.is_top_io_in_time_by_event_category_perf_report_enabled,
"top_io_by_user_or_thread": server_record.is_top_io_by_user_or_thread_perf_report_enabled,
"statement_analysis": server_record.is_statement_analysis_perf_report_enabled,
"statements_in_highest_5_percentile": server_record.is_statements_in_highest_5_percentile_perf_report_enabled,
"statements_using_temp_tables": server_record.is_statements_using_temp_tables_perf_report_enabled,
"statements_with_sorting": server_record.is_statements_with_sorting_perf_report_enabled,
"statements_with_full_table_scans": server_record.is_statements_with_full_table_scans_perf_report_enabled,
"statements_with_errors_or_warnings": server_record.is_statements_with_errors_or_warnings_perf_report_enabled,
"schema_index_statistics": server_record.is_schema_index_statistics_perf_report_enabled,
"schema_table_statistics": server_record.is_schema_table_statistics_perf_report_enabled,
"schema_table_statistics_with_innodb_buffer": server_record.is_schema_table_statistics_with_innodb_perf_report_enabled,
"schema_tables_with_full_table_scans": server_record.is_schema_tables_with_full_table_scans_perf_report_enabled,
"schema_unused_indexes": server_record.is_schema_unused_indexes_perf_report_enabled,
"global_waits_by_time": server_record.is_global_waits_by_time_perf_report_enabled,
"waits_by_user_by_time": server_record.is_waits_by_user_by_time_perf_report_enabled,
"wait_classes_by_time": server_record.is_wait_classes_by_time_perf_report_enabled,
"waits_classes_by_avg_time": server_record.is_waits_classes_by_avg_time_perf_report_enabled,
"innodb_buffer_stats_by_schema": server_record.is_innodb_buffer_stats_by_schema_perf_report_enabled,
"innodb_buffer_stats_by_table": server_record.is_innodb_buffer_stats_by_table_perf_report_enabled,
"user_resource_use_overview": server_record.is_user_resource_use_overview_perf_report_enabled,
"user_resource_use_io_statistics": server_record.is_user_resource_use_io_statistics_perf_report_enabled,
"user_resource_use_statement_statistics": server_record.is_user_resource_use_statement_statistics_perf_report_enabled,
}

return self.create_agent_job(

Check warning on line 1182 in press/agent.py

View check run for this annotation

Codecov / codecov/patch

press/agent.py#L1182

Added line #L1182 was not covered by tests
"Fetch Performance Report",
f"database/performance_report",
data={
"private_ip": server_record.private_ip,
"mariadb_root_password": server_record.get_password("mariadb_root_password"),
"reports": [
report for report, enabled in reports_is_enabled_status.items() if enabled
],
},
)


class AgentCallbackException(Exception):
pass
Expand Down
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2024, Frappe and contributors
// For license information, please see license.txt

frappe.ui.form.on("DB Performance Report", {
refresh(frm) {
frm.add_custom_button(__('Multiply 10^9 with Count & Time Field'), function(){
format_fields_helper(frm.get_doc());
frm.refresh_fields();
let notice_msg = __("All the count & time fields with billion and billion ps as unit have been multiplied by 10^9");
msgprint(notice_msg);
frm.remove_custom_button(__('Multiply 10^9 with Count & Time Field'));
frm.set_intro(notice_msg);
});
},
});

function format_fields_helper(fields_map){
for (const [key, value] of Object.entries(fields_map)) {
if (typeof value === 'object') {
format_fields_helper(value);
} else {
if (key.endsWith('_billion') || key.endsWith('_billion_ps')){
if (typeof value === 'number'){
fields_map[key] = value*1000000000;
}
}
}
}
return fields_map;
}
Loading
Loading