Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(mail): slow query log weekly report template (#5701)
h3n4l4b639d00bd83
diff --git a/backend/api/v1/mail_templates/testmail/hahaha/need_configure.html b/backend/api/v1/mail_templates/testmail/hahaha/need_configure.htmlnew file mode 100644index 0000000000..ac357c6e9a--- /dev/null+++ b/backend/api/v1/mail_templates/testmail/hahaha/need_configure.html@@ -0,0 +1,44 @@+<!DOCTYPE html>+<meta content="text/html; charset=UTF-8" />+<html lang="en">+ <head>+ <style type="text/css">+ .mail-heading {+ font-size: 32px;+ line-height: 1.3;+ font-weight: 700;+ text-align: center;+ letter-spacing:-1px;+ }+ .mail-text {+ font-size: 16px;+ line-height: 20px;+ margin-top: 16px;+ margin-left:0;+ margin-right:0;+ word-wrap: normal;+ }+ </style>+ </head>+ <body style="background-color: #ffffff;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif">+ <h1 data-id="mail-heading" class="mail-heading">Configure your database slow query report</h1>+ <p data-id="mail-first-graph" class="mail-text">+ You have successfully configured the mail server in Bytebase.+ <br>+ </p>+ <p class="mail-text">+ Next, you can visit+ <a href="{{VISIT_URL}}"><span class="mail-text">{{VISIT_URL}}</span></a>+ to enable slow query log collection.+ <br>+ </p>+ <p class="mail-text">+ Once configured, Bytebase will send you slow query report every week, and the email will list the slow queries collected on the enabled instances.+ <br>+ </p>+ <p class="mail-text">+ Please read our doc <a href="{{DOC_LINK}}"><span class="mail-text">{{DOC_LINK}}</span></a> for detailed instructions.+ <br>+ </p>+ </body>+</html>\ No newline at end of filediff --git a/backend/api/v1/mail_templates/testmail/hahaha/weekly_for_dba.html b/backend/api/v1/mail_templates/testmail/hahaha/weekly_for_dba.htmlnew file mode 100644index 0000000000..36c2b2a563--- /dev/null+++ b/backend/api/v1/mail_templates/testmail/hahaha/weekly_for_dba.html@@ -0,0 +1,98 @@+<!DOCTYPE html>+<meta content="text/html; charset=UTF-8" />+<html lang="en">+ <head>+ <style type="text/css">+ .mail-heading {+ font-size: 40px;+ line-height: 1.3;+ font-weight: 700;+ text-align: center;+ letter-spacing:-1px;+ }+ .mail-text {+ font-size: 16px;+ line-height: 20px;+ margin-top: 16px;+ margin-left:0;+ margin-right:0;+ word-wrap: normal;+ }+ .env-title {+ font-size: 32px;+ line-height: 20px;+ word-wrap: normal;+ }+ .instance-title {+ font-size: 24px;+ line-height: 20px;+ word-wrap: normal;+ }+ .hint-text {+ font-size: 20px;+ line-height: 20px;+ word-wrap: normal;+ }+ .text-center {+ text-align: center;+ }++ .sql-text {+ font-size: 16px;+ line-height: 20px;+ word-wrap: normal;+ font-family: monospace;+ }++ #slow-query-table td, #slow-query-table th {+ white-space: pre-wrap;+ border: 1px solid #ddd;+ padding: 8px;+ }++ #slow-query-table tr:nth-child(even){background-color: #f2f2f2;}++ #slow-query-table tr:hover {background-color: #ddd;}++ #slow-query-table th {+ padding-top: 12px;+ padding-bottom: 12px;+ text-align: left;+ background-color: #4f46e5;+ color: white;+ }+ </style>+ </head>+ <body style="background-color: #ffffff;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",monospace,sans-serif">+ <h1 data-id="mail-heading" class="mail-heading">Database slow query weekly report {{BEGIN_DATE}} ~ {{END_DATE}}</h1>+ <p data-id="mail-first-graph" class="mail-text" style="text-align: center;">+ Below is the slow query for {{BEGIN_DATE}} ~ {{END_DATE}}, each database lists at most 5 slow queries.+ You can visit <a href="{{VISIT_URL}}"><span class="mail-text">{{VISIT_URL}}</span></a> to enable/disable slow query collection.+ <br>+ </p>+ <!-- TODO(junyi): For loop this div block to generate multiple environments block.-->+ <div style="margin-top: 32px;">+ <h2 class="env-title text-center"> {{ENV_NAME}} </h2>+ <!-- TODO(junyi): For loop this div block to generate multiple instance in one environment.-->+ <div style="margin-top: 24px;">+ <h2 class="instance-tile text-center"><a href="{{INSTANCE_LINK}}">{{INSTANCE_NAME}}</a></h2>+ <!-- TODO(junyi) Use the following p block if no instance has configured slow query collection.-->+ <p class="hint-text text-center">💤 No instance has configured slow query collection</p>+ <!-- TODO(junyi) Use the following p block if no slow query found in all configured instances.-->+ <p class="hint-text text-center">🎉 No slow query found in all configured instances</p>+ <!-- TODO(junyi): Using the following table block if there are any slow queries.-->+ <table id="slow-query-table" style="margin: auto">+ <tr>+ <th>DB</th>+ <th>Slow Query</th>+ </tr>+ <!-- TODO(junyi) For loop this tr block to generate all slow query entry in table element.-->+ <tr>+ <td>{{DB_NAME}}</td>+ <td><span class="sql-text">{{SLOW_QUERY}}</span></td>+ </tr>+ </table>+ </div>+ </div>+ </body>+</html>diff --git a/backend/api/v1/mail_templates/testmail/hahaha/weekly_for_dba_example.html b/backend/api/v1/mail_templates/testmail/hahaha/weekly_for_dba_example.htmlnew file mode 100644index 0000000000..b892f8970c--- /dev/null+++ b/backend/api/v1/mail_templates/testmail/hahaha/weekly_for_dba_example.html@@ -0,0 +1,174 @@+<!DOCTYPE html>+<meta content="text/html; charset=UTF-8" />+<html lang="en">+ <head>+ <style type="text/css">+ .mail-heading {+ font-size: 40px;+ line-height: 1.3;+ font-weight: 700;+ text-align: center;+ letter-spacing:-1px;+ }+ .mail-text {+ font-size: 16px;+ line-height: 20px;+ margin-top: 16px;+ margin-left:0;+ margin-right:0;+ word-wrap: normal;+ }+ .env-title {+ font-size: 32px;+ line-height: 20px;+ word-wrap: normal;+ }+ .instance-title {+ font-size: 24px;+ line-height: 20px;+ word-wrap: normal;+ }+ .hint-text {+ font-size: 20px;+ line-height: 20px;+ word-wrap: normal;+ }+ .text-center {+ text-align: center;+ }+ .sql-text {+ font-size: 16px;+ line-height: 20px;+ word-wrap: normal;+ font-family: monospace;+ }++ #slow-query-table td, #slow-query-table th {+ white-space: pre-wrap;+ border: 1px solid #ddd;+ padding: 8px;+ }++ #slow-query-table tr:nth-child(even){background-color: #f2f2f2;}++ #slow-query-table tr:hover {background-color: #ddd;}++ #slow-query-table th {+ padding-top: 12px;+ padding-bottom: 12px;+ text-align: left;+ background-color: #4f46e5;+ color: white;+ }+ </style>+ </head>+ <body style="background-color: #ffffff;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",monospace,sans-serif">+ <h1 data-id="mail-heading" class="mail-heading">Database slow query weekly report {{BEGIN_DATE}} ~ {{END_DATE}}</h1>+ <p data-id="mail-first-graph" class="mail-text text-center">+ Below is the slow query for {{BEGIN_DATE}} ~ {{END_DATE}}, each database lists at most 5 slow queries.+ You can visit <a href="{{VISIT_URL}}"><span class="mail-text">https://bytebase.com</span></a> to enable/disable slow query collection.+ <br>+ </p>+ <!-- TODO(junyi): For loop this div block to generate multiple environments block.-->+ <div style="margin-top: 32px;">+ <h2 class="env-title text-center"> Prod </h2>+ <!-- TODO(junyi): For loop this div block to generate multiple instance in one environment.-->+ <div style="margin-top: 24px;">+ <h2 class="instance-tile text-center"><a href="{{INSTANCE_LINK}}">Instance 1</a></h2>+ <table id="slow-query-table" style="margin:auto;">+ <tr>+ <th>DB</th>+ <th>Slow Query</th>+ </tr>+ <!-- TODO(junyi) For loop this tr block to generate all slow query entry in table element.-->+ <tr>+ <td>Employee</td>+ <td><span class="sql-text"> -- create a dummy table with 10 rows+CREATE TABLE dummy_table (id INT NOT NULL PRIMARY KEY);+INSERT INTO dummy_table VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);+-- create the table if it doesn't exist+CREATE TABLE my_table (+ id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,+ name VARCHAR(50),+ age INT,+ salary INT+);++-- insert 1,000,000 rows into the table+INSERT INTO my_table (name, age, salary)+SELECT CONCAT('Name', t1.id), FLOOR(RAND() * 47) + 18, FLOOR(RAND() * 40000) + 10000+FROM dummy_table t1, dummy_table t2, dummy_table t3, dummy_table t4, dummy_table t5, dummy_table t6, dummy_table t7, dummy_table t8;++-- run a complex query that takes more than 10 seconds to execute+SELECT t1.name, AVG(t1.salary)+FROM my_table t1+JOIN my_table t2 ON t1.id = t2.id+WHERE t1.age > 30+GROUP BY t1.name+HAVING COUNT(*) > 1000;+</span></td>+ </tr>+ <tr>+ <td>Employee</td>+ <td><span class="sql-text"> -- create a dummy table with 10 rows+CREATE TABLE dummy_table (id INT NOT NULL PRIMARY KEY);+INSERT INTO dummy_table VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);+-- create the table if it doesn't exist+CREATE TABLE my_table (+ id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,+ name VARCHAR(50),+ age INT,+ salary INT+);++-- insert 1,000,000 rows into the table+INSERT INTO my_table (name, age, salary)+SELECT CONCAT('Name', t1.id), FLOOR(RAND() * 47) + 18, FLOOR(RAND() * 40000) + 10000+FROM dummy_table t1, dummy_table t2, dummy_table t3, dummy_table t4, dummy_table t5, dummy_table t6, dummy_table t7, dummy_table t8;++-- run a complex query that takes more than 10 seconds to execute+SELECT t1.name, AVG(t1.salary)+FROM my_table t1+JOIN my_table t2 ON t1.id = t2.id+WHERE t1.age > 30+GROUP BY t1.name+HAVING COUNT(*) > 1000;+</span></td>+ </tr>+ <tr>+ <td>Salary</td>+ <td><span class="sql-text">+-- run a complex query that takes more than 10 seconds to execute+SELECT t1.name, AVG(t1.salary)+FROM my_table t1+JOIN my_table t2 ON t1.id = t2.id+WHERE t1.age > 30+GROUP BY t1.name+HAVING COUNT(*) > 1000;+</span></td>+ </tr>+ </table>+ </div>+ </div>++ <div style="margin-top: 32px;">+ <h2 class="env-title text-center"> Staging </h2>+ <!-- TODO(junyi): For loop this div block to generate multiple instance in one environment.-->+ <div style="margin-top: 24px;">+ <h2 class="instance-tile text-center"><a href="{{INSTANCE_LINK}}">Instance 2</a></h2>+ <!-- TODO(junyi) Use the following p block if no instance has configured slow query collection.-->+ <p class="hint-text text-center">💤 No instance has configured slow query collection</p>+ </div>+ </div>++ <div style="margin-top: 32px;">+ <h2 class="env-title text-center"> Test </h2>+ <!-- TODO(junyi): For loop this div block to generate multiple instance in one environment.-->+ <div style="margin-top: 24px;">+ <h2 class="instance-tile text-center"><a href="{{INSTANCE_LINK}}">Instance 3</a></h2>+ <!-- TODO(junyi) Use the following p block if no slow query found in all configured instances.-->+ <p class="hint-text text-center">🎉 No slow query found in all configured instances</p>+ </div>+ </div>+ </body>+</html>diff --git a/backend/api/v1/mail_templates/testmail/hahaha/weekly_for_project_owner.html b/backend/api/v1/mail_templates/testmail/hahaha/weekly_for_project_owner.htmlnew file mode 100644index 0000000000..7dd2310bb7--- /dev/null+++ b/backend/api/v1/mail_templates/testmail/hahaha/weekly_for_project_owner.html@@ -0,0 +1,97 @@+<!DOCTYPE html>+<meta content="text/html; charset=UTF-8" />+<html lang="en">+ <head>+ <style type="text/css">+ .mail-heading {+ font-size: 40px;+ line-height: 1.3;+ font-weight: 700;+ text-align: center;+ letter-spacing:-1px;+ }+ .mail-text {+ font-size: 16px;+ line-height: 20px;+ margin-top: 16px;+ margin-left:0;+ margin-right:0;+ word-wrap: normal;+ }+ .project-title {+ font-size: 32px;+ line-height: 20px;+ word-wrap: normal;+ }+ .environment-title {+ font-size: 24px;+ line-height: 20px;+ word-wrap: normal;+ }+ .hint-text {+ font-size: 20px;+ line-height: 20px;+ word-wrap: normal;+ }+ .text-center {+ text-align: center;+ }+ .sql-text {+ font-size: 16px;+ line-height: 20px;+ word-wrap: normal;+ font-family: monospace;+ }++ #slow-query td, #slow-query th {+ border: 1px solid #ddd;+ padding: 8px;+ }++ #slow-query tr:nth-child(even){background-color: #f2f2f2;}++ #slow-query tr:hover {background-color: #ddd;}++ #slow-query th {+ padding-top: 12px;+ padding-bottom: 12px;+ text-align: left;+ background-color: #4f46e5;+ color: white;+ }+ </style>+ </head>+ <body style="background-color: #ffffff;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",monospace,sans-serif">+ <h1 data-id="mail-heading" class="mail-heading">{{PROJECT_NAME}} database slow query weekly report {{BEGIN_DATE}} ~ {{END_DATE}}</h1>+ <p data-id="mail-first-graph" class="mail-text" style="text-align: center;">+ Below is the {{PROJECT_NAME}} slow query for {{BEGIN_DATE}} ~ {{END_DATE}}, each database lists at most 5 slow queries.+ <br>+ </p>+ <!-- TODO(junyi): For loop this div block to generate multiple environments block.-->+ <div style="margin-top: 32px;">+ <h2 class="project-title text-center"><a href="{{PROJECT_LINK}}">{{PROJECT_NAME}}</a> </h2>+ <!-- TODO(junyi): For loop this div block to generate multiple instance in one environment.-->+ <div style="margin-top: 24px;">+ <h2 class="environment-tile text-center">{{ENVIRONMENT_NAME}}</a></h2>+ <!-- TODO(junyi) Use the following p block if no instance has configured slow query collection.-->+ <p class="hint-text text-center">💤 No instance has configured slow query collection</p>+ <!-- TODO(junyi) Use the following p block if no slow query found in all configured instances.-->+ <p class="hint-text text-center">🎉 No slow query found in all configured instances</p>+ <!-- TODO(junyi): Using the following table block if there are any slow queries.-->+ <table id="slow-query" style="margin: auto">+ <tr>+ <th>Type</th>+ <th>DB</th>+ <th>Slow Query</th>+ </tr>+ <!-- TODO(junyi) For loop this tr block to generate all slow query entry in table element.-->+ <tr>+ <td><{{DB_TYPE}}</td>+ <td>{{DB_NAME}}</td>+ <td><span class="sql-text">{{SLOW_QUERY}}</span></td>+ </tr>+ </table>+ </div>+ </div>+ </body>+</html>diff --git a/backend/api/v1/mail_templates/testmail/hahaha/weekly_for_project_owner_example.html b/backend/api/v1/mail_templates/testmail/hahaha/weekly_for_project_owner_example.htmlnew file mode 100644index 0000000000..963cd9e87d--- /dev/null+++ b/backend/api/v1/mail_templates/testmail/hahaha/weekly_for_project_owner_example.html@@ -0,0 +1,161 @@+<!DOCTYPE html>+<meta content="text/html; charset=UTF-8" />+<html lang="en">+ <head>+ <style type="text/css">+ .mail-heading {+ font-size: 40px;+ line-height: 1.3;+ font-weight: 700;+ text-align: center;+ letter-spacing:-1px;+ }+ .mail-text {+ font-size: 16px;+ line-height: 20px;+ margin-top: 16px;+ margin-left:0;+ margin-right:0;+ word-wrap: normal;+ }+ .project-title {+ font-size: 32px;+ line-height: 20px;+ word-wrap: normal;+ }+ .environment-title {+ font-size: 24px;+ line-height: 20px;+ word-wrap: normal;+ }+ .hint-text {+ font-size: 20px;+ line-height: 20px;+ word-wrap: normal;+ }+ .text-center {+ text-align: center;+ }+ .sql-text {+ font-size: 16px;+ line-height: 20px;+ word-wrap: normal;+ font-family: monospace;+ }+ #slow-query-table td, #slow-query-table th {+ white-space: pre-wrap;+ border: 1px solid #ddd;+ padding: 8px;+ }++ #slow-query-table tr:nth-child(even){background-color: #f2f2f2;}++ #slow-query-table tr:hover {background-color: #ddd;}++ #slow-query-table th {+ padding-top: 12px;+ padding-bottom: 12px;+ text-align: left;+ background-color: #4f46e5;+ color: white;+ }+ </style>+ </head>+ <body style="background-color: #ffffff;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",monospace,sans-serif">+ <h1 data-id="mail-heading" class="mail-heading">{{PROJECT_NAME}} database slow query weekly report {{BEGIN_DATE}} ~ {{END_DATE}}</h1>+ <p data-id="mail-first-graph" class="mail-text" style="text-align: center;">+ Below is the {{PROJECT_NAME}} slow query for {{BEGIN_DATE}} ~ {{END_DATE}}, each database lists at most 5 slow queries.+ <br>+ </p>+ <!-- TODO(junyi): For loop this div block to generate multiple environments block.-->+ <div style="margin-top: 32px;">+ <h2 class="project-title text-center"><a href="{{PROJECT_LINK}}">{{PROJECT_NAME}}</a> </h2>+ <!-- TODO(junyi): For loop this div block to generate multiple instance in one environment.-->+ <div style="margin-top: 24px;">+ <h2 class="environment-tile text-center">{{ENVIRONMENT_NAME}}</a></h2>+ <!-- TODO(junyi) Use the following p block if no instance has configured slow query collection.-->+ <p class="hint-text text-center">💤 No instance has configured slow query collection</p>+ <!-- TODO(junyi) Use the following p block if no slow query found in all configured instances.-->+ <p class="hint-text text-center">🎉 No slow query found in all configured instances</p>+ <!-- TODO(junyi): Using the following table block if there are any slow queries.-->+ <table id="slow-query-table" style="margin: auto">+ <tr>+ <th>Type</th>+ <th>DB</th>+ <th>Slow Query</th>+ </tr>+ <!-- TODO(junyi) For loop this tr block to generate all slow query entry in table element.-->+ <tr>+ <td>MySQL</td>+ <td>Employee</td>+ <td><span class="sql-text"> -- create a dummy table with 10 rows+CREATE TABLE dummy_table (id INT NOT NULL PRIMARY KEY);+INSERT INTO dummy_table VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);+-- create the table if it doesn't exist+CREATE TABLE my_table (+ id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,+ name VARCHAR(50),+ age INT,+ salary INT+);++-- insert 1,000,000 rows into the table+INSERT INTO my_table (name, age, salary)+SELECT CONCAT('Name', t1.id), FLOOR(RAND() * 47) + 18, FLOOR(RAND() * 40000) + 10000+FROM dummy_table t1, dummy_table t2, dummy_table t3, dummy_table t4, dummy_table t5, dummy_table t6, dummy_table t7, dummy_table t8;++-- run a complex query that takes more than 10 seconds to execute+SELECT t1.name, AVG(t1.salary)+FROM my_table t1+JOIN my_table t2 ON t1.id = t2.id+WHERE t1.age > 30+GROUP BY t1.name+HAVING COUNT(*) > 1000;+ </span></td>+ </tr>+ <tr>+ <td>MySQL</td>+ <td>Employee</td>+ <td> -- create a dummy table with 10 rows+CREATE TABLE dummy_table (id INT NOT NULL PRIMARY KEY);+INSERT INTO dummy_table VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);+-- create the table if it doesn't exist+CREATE TABLE my_table (+ id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,+ name VARCHAR(50),+ age INT,+ salary INT+);++-- insert 1,000,000 rows into the table+INSERT INTO my_table (name, age, salary)+SELECT CONCAT('Name', t1.id), FLOOR(RAND() * 47) + 18, FLOOR(RAND() * 40000) + 10000+FROM dummy_table t1, dummy_table t2, dummy_table t3, dummy_table t4, dummy_table t5, dummy_table t6, dummy_table t7, dummy_table t8;++-- run a complex query that takes more than 10 seconds to execute+SELECT t1.name, AVG(t1.salary)+FROM my_table t1+JOIN my_table t2 ON t1.id = t2.id+WHERE t1.age > 30+GROUP BY t1.name+HAVING COUNT(*) > 1000;+ </td>+ </tr>+ <tr>+ <td>PostgreSQL</td>+ <td>Salary</td>+ <td>+-- run a complex query that takes more than 10 seconds to execute+SELECT t1.name, AVG(t1.salary)+FROM my_table t1+JOIN my_table t2 ON t1.id = t2.id+WHERE t1.age > 30+GROUP BY t1.name+HAVING COUNT(*) > 1000;+ </td>+ </tr>+ </table>+ </div>+ </div>+ </body>+</html>