Skip to content

Commit

Permalink
refactor: use table for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed Apr 22, 2024
1 parent b0ce404 commit 9154e42
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ frappe.ui.form.on("System Health Report", {
};

const style = document.createElement("style");
style.innerText = ".health-check-failed { border: 1px solid var(--error-border); }";
style.innerText =
".health-check-failed { border: 1px solid var(--error-border) !important; }";
document.head.appendChild(style);

const update_fields = () => {
Expand Down
18 changes: 12 additions & 6 deletions frappe/desk/doctype/system_health_report/system_health_report.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"unhandled_emails",
"errors_generated_in_last_1_day_section",
"total_errors",
"top_errors"
"top_errors",
"column_break_fzke"
],
"fields": [
{
Expand Down Expand Up @@ -171,18 +172,19 @@
{
"fieldname": "errors_generated_in_last_1_day_section",
"fieldtype": "Section Break",
"label": "Errors generated in last 1 day"
"label": "Errors"
},
{
"documentation_url": "/app/error-log",
"fieldname": "total_errors",
"fieldtype": "Int",
"label": "Total Errors"
"label": "Total Errors (last 1 day)"
},
{
"fieldname": "top_errors",
"fieldtype": "Code",
"label": "Top Errors"
"fieldtype": "Table",
"label": "Top Errors",
"options": "System Health Report Errors"
},
{
"fieldname": "database",
Expand Down Expand Up @@ -361,14 +363,18 @@
"fieldtype": "Data",
"hidden": 1,
"label": "Test Job ID"
},
{
"fieldname": "column_break_fzke",
"fieldtype": "Column Break"
}
],
"hide_toolbar": 1,
"index_web_pages_for_search": 1,
"is_virtual": 1,
"issingle": 1,
"links": [],
"modified": "2024-04-19 16:36:01.698178",
"modified": "2024-04-19 17:12:37.889872",
"modified_by": "Administrator",
"module": "Desk",
"name": "System Health Report",
Expand Down
25 changes: 13 additions & 12 deletions frappe/desk/doctype/system_health_report/system_health_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class SystemHealthReport(Document):
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from frappe.desk.doctype.system_health_report_errors.system_health_report_errors import (
SystemHealthReportErrors,
)
from frappe.desk.doctype.system_health_report_queue.system_health_report_queue import (
SystemHealthReportQueue,
)
Expand Down Expand Up @@ -92,7 +95,7 @@ class SystemHealthReport(Document):
socketio_transport_mode: DF.Literal["Polling", "Websocket"]
test_job_id: DF.Data | None
top_db_tables: DF.Table[SystemHealthReportTables]
top_errors: DF.Code | None
top_errors: DF.Table[SystemHealthReportErrors]
total_background_workers: DF.Int
total_errors: DF.Int
total_outgoing_emails: DF.Int
Expand Down Expand Up @@ -167,24 +170,22 @@ def fetch_email_stats(self):

@health_check("Errors")
def fetch_errors(self):
from terminaltables import AsciiTable

threshold = add_to_date(None, days=-1, as_datetime=True)
filters = {"creation": (">", threshold), "modified": (">", threshold)}
self.total_errors = frappe.db.count("Error Log", filters)

top_errors = frappe.db.sql(
"""select method, count(*) as occurance
"""select method as title, count(*) as occurrences
from `tabError Log`
where modified > %(threshold)s and creation > %(threshold)s
group by method
order by occurance desc
order by occurrences desc
limit 5""",
{"threshold": threshold},
as_list=True,
as_dict=True,
)
if top_errors:
self.top_errors = AsciiTable([["Error Title", "Count"], *top_errors]).table
for row in top_errors:
self.append("top_errors", row)

@health_check("Database")
def fetch_database_details(self):
Expand Down Expand Up @@ -221,15 +222,15 @@ def get_directory_size(cls, *path):
total_size += os.path.getsize(itempath)
elif os.path.isdir(itempath):
total_size += cls.get_directory_size(itempath)
return total_size / (1024 * 1024)
return total_size

@health_check("Storage")
def fetch_storage_details(self):
from frappe.desk.page.backups.backups import get_context

self.backups_size = self.get_directory_size("private", "backups")
self.private_files_size = self.get_directory_size("private", "files")
self.public_files_size = self.get_directory_size("public", "files")
self.backups_size = self.get_directory_size("private", "backups") / (1024 * 1024)
self.private_files_size = self.get_directory_size("private", "files") / (1024 * 1024)
self.public_files_size = self.get_directory_size("public", "files") / (1024 * 1024)
self.onsite_backups = len(get_context({}).get("files", []))

@health_check("Users")
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2024-04-19 17:02:48.566902",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"title",
"occurrences"
],
"fields": [
{
"fieldname": "title",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Title"
},
{
"fieldname": "occurrences",
"fieldtype": "Int",
"in_list_view": 1,
"label": "Occurrences"
}
],
"index_web_pages_for_search": 1,
"is_virtual": 1,
"istable": 1,
"links": [],
"modified": "2024-04-19 17:10:43.199907",
"modified_by": "Administrator",
"module": "Desk",
"name": "System Health Report Errors",
"owner": "Administrator",
"permissions": [],
"sort_field": "creation",
"sort_order": "DESC",
"states": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (c) 2024, Frappe Technologies and contributors
# For license information, please see license.txt

# import frappe
from frappe.model.document import Document


class SystemHealthReportErrors(Document):
# begin: auto-generated types
# This code is auto-generated. Do not modify anything in this block.

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from frappe.types import DF

occurrences: DF.Int
parent: DF.Data
parentfield: DF.Data
parenttype: DF.Data
title: DF.Data | None
# end: auto-generated types

def db_insert(self, *args, **kwargs):
raise NotImplementedError

def load_from_db(self):
raise NotImplementedError

def db_update(self):
raise NotImplementedError

def delete(self):
raise NotImplementedError

@staticmethod
def get_list(filters=None, page_length=20, **kwargs):
pass

@staticmethod
def get_count(filters=None, **kwargs):
pass

@staticmethod
def get_stats(**kwargs):
pass

0 comments on commit 9154e42

Please sign in to comment.