@@ -22,7 +22,7 @@ class MonitorEmailTemplate(BaseNotificationTemplate):
2222 def get_subject_template (self ) -> str :
2323 return (
2424 "[TestGen] Monitors Alert: {{summary.table_groups_name}}"
25- "{{#if summary.table_name}} | {{test_run_monitor_summary .table_name}}{{/if}}"
25+ "{{#if summary.table_name}} | {{summary .table_name}}{{/if}}"
2626 ' | {{total_anomalies}} {{pluralize total_anomalies "anomaly" "anomalies"}}'
2727 )
2828
@@ -65,7 +65,7 @@ def get_main_content_template(self):
6565 border="0">
6666 <tr>
6767 <td class="summary__title">Anomalies Summary</td>
68- <td align="left ">
68+ <td align="right ">
6969 <a class="link" href="{{view_in_testgen_url}}" target="_blank">View on TestGen ></a>
7070 </td>
7171 </tr>
@@ -94,7 +94,7 @@ def get_main_content_template(self):
9494 border="0">
9595 <tr class="text-caption">
9696 <td>Table</td>
97- <td>Type/Focus </td>
97+ <td>Monitor </td>
9898 <td>Details</td>
9999 </tr>
100100 {{#each anomalies}}
@@ -119,19 +119,18 @@ def get_main_content_template(self):
119119
120120 def get_anomaly_tag_template (self ):
121121 return """
122- <td valign="middle">
122+ <td valign="middle" style="padding-right: 24px;" >
123123 <table border="0" cellpadding="0" cellspacing="0" role="presentation">
124124 <tr>
125125 <td valign="middle">
126126 <div style="{{#if count}}background-color: #EF5350; min-width: 15px; padding: 0px 5px; border-radius: 10px; text-align: center; line-height: 20px;{{else}}background-color: #9CCC65; width: 20px; height: 20px; border-radius: 50%; text-align: center; line-height: 21px;{{/if}} color: #ffffff; font-weight: bold; font-size: 13px;">
127127 {{#if count}}{{count}}{{else}}✓{{/if}}
128128 </div>
129129 </td>
130- <td width="4"></td> <td valign="middle" style="color: #111111;">{{type}}</td>
130+ <td valign="middle" style="color: #111111; padding-left: 8px ;">{{type}}</td>
131131 </tr>
132132 </table>
133133 </td>
134- {{#if @last}}{{else}}<td width="16"></td>{{/if}}
135134 """
136135
137136 def get_extra_css_template (self ) -> str :
@@ -171,7 +170,7 @@ def get_extra_css_template(self) -> str:
171170
172171@log_and_swallow_exception
173172@with_database_session
174- def send_monitor_notifications (test_run : TestRun ):
173+ def send_monitor_notifications (test_run : TestRun , result_list_ct = 20 ):
175174 notifications = list (MonitorNotificationSettings .select (
176175 enabled = True ,
177176 test_suite_id = test_run .test_suite_id ,
@@ -206,10 +205,20 @@ def send_monitor_notifications(test_run: TestRun):
206205 for test_result in test_results :
207206 label = _TEST_TYPE_LABELS .get (test_result .test_type )
208207 anomaly_counts [label ] = (anomaly_counts .get (label ) or 0 ) + 1
208+ details = test_result .message or "N/A"
209+
210+ if test_result .test_type == "Freshness_Trend" :
211+ parts = details .split (". " , 1 )
212+ message = parts [1 ].rstrip ("." ) if len (parts ) > 1 else None
213+ prefix = "Table updated" if "detected: Yes" in details else "No table update"
214+ details = f"{ prefix } - { message } " if message else prefix
215+ elif test_result .test_type == "Metric_Trend" :
216+ label = f"{ label } : { test_result .column_names } "
217+
209218 anomalies .append ({
210219 "table_name" : test_result .table_name or "N/A" ,
211220 "type" : label ,
212- "details" : test_result . message or "N/A" ,
221+ "details" : details ,
213222 })
214223
215224 view_in_testgen_url = "" .join (
@@ -238,12 +247,8 @@ def send_monitor_notifications(test_run: TestRun):
238247 {"type" : key , "count" : value }
239248 for key , value in anomaly_counts .items ()
240249 ],
241- # "anomaly_counts": [
242- # {"type": "Freshness", "count": freshness_anomalies},
243- # {"type": "Schema", "count": schema_anomalies},
244- # {"type": "Volume", "count": volume_anomalies},
245- # ],
246- "anomalies" : anomalies ,
250+ "anomalies" : anomalies [:result_list_ct ],
251+ "truncated" : max (len (anomalies ) - result_list_ct , 0 ),
247252 "view_in_testgen_url" : view_in_testgen_url ,
248253 },
249254 )
@@ -252,7 +257,8 @@ def send_monitor_notifications(test_run: TestRun):
252257
253258
254259_TEST_TYPE_LABELS = {
255- "Table_Freshness" : "Freshness" ,
256- "Schema_Drift" : "Schema" ,
260+ "Freshness_Trend" : "Freshness" ,
257261 "Volume_Trend" : "Volume" ,
262+ "Schema_Drift" : "Schema" ,
263+ "Metric_Trend" : "Metric" ,
258264}
0 commit comments