@@ -149,8 +149,9 @@ def evaluate(
149149 execution_time : TimeLike ,
150150 deployability_index : DeployabilityIndex ,
151151 batch_index : int ,
152+ environment_naming_info : t .Optional [EnvironmentNamingInfo ] = None ,
152153 ** kwargs : t .Any ,
153- ) -> t .Tuple [ t . List [AuditResult ], t . List [ AuditError ] ]:
154+ ) -> t .List [AuditResult ]:
154155 """Evaluate a snapshot and add the processed interval to the state sync.
155156
156157 Args:
@@ -182,8 +183,9 @@ def evaluate(
182183 batch_index = batch_index ,
183184 ** kwargs ,
184185 )
185- audit_results = self .snapshot_evaluator . audit (
186+ audit_results = self ._audit_snapshot (
186187 snapshot = snapshot ,
188+ environment_naming_info = environment_naming_info ,
187189 start = start ,
188190 end = end ,
189191 execution_time = execution_time ,
@@ -193,32 +195,8 @@ def evaluate(
193195 ** kwargs ,
194196 )
195197
196- audit_errors_to_raise : t .List [AuditError ] = []
197- audit_errors_to_warn : t .List [AuditError ] = []
198- for audit_result in (result for result in audit_results if result .count ):
199- error = AuditError (
200- audit_name = audit_result .audit .name ,
201- audit_args = audit_result .audit_args ,
202- model = snapshot .model_or_none ,
203- count = t .cast (int , audit_result .count ),
204- query = t .cast (exp .Query , audit_result .query ),
205- adapter_dialect = self .snapshot_evaluator .adapter .dialect ,
206- )
207- self .notification_target_manager .notify (NotificationEvent .AUDIT_FAILURE , error )
208- if is_deployable and snapshot .node .owner :
209- self .notification_target_manager .notify_user (
210- NotificationEvent .AUDIT_FAILURE , snapshot .node .owner , error
211- )
212- if audit_result .blocking :
213- audit_errors_to_raise .append (error )
214- else :
215- audit_errors_to_warn .append (error )
216-
217- if audit_errors_to_raise :
218- raise NodeAuditsErrors (audit_errors_to_raise )
219-
220198 self .state_sync .add_interval (snapshot , start , end , is_dev = not is_deployable )
221- return audit_results , audit_errors_to_warn
199+ return audit_results
222200
223201 def run (
224202 self ,
@@ -465,30 +443,19 @@ def evaluate_node(node: SchedulingUnit) -> None:
465443 evaluation_duration_ms : t .Optional [int ] = None
466444
467445 audit_results : t .List [AuditResult ] = []
468- audit_errors_to_warn : t .List [AuditError ] = []
469446 try :
470447 assert execution_time # mypy
471448 assert deployability_index # mypy
472- audit_results , audit_errors_to_warn = self .evaluate (
449+ audit_results = self .evaluate (
473450 snapshot = snapshot ,
451+ environment_naming_info = environment_naming_info ,
474452 start = start ,
475453 end = end ,
476454 execution_time = execution_time ,
477455 deployability_index = deployability_index ,
478456 batch_index = batch_idx ,
479457 )
480458
481- for audit_error in audit_errors_to_warn :
482- display_name = snapshot .display_name (
483- environment_naming_info ,
484- self .default_catalog ,
485- self .snapshot_evaluator .adapter .dialect ,
486- )
487- self .console .log_warning (
488- f"\n { display_name } : { audit_error } ." ,
489- f"{ audit_error } . Audit query:\n { audit_error .query .sql (audit_error .adapter_dialect )} " ,
490- )
491-
492459 evaluation_duration_ms = now_timestamp () - execution_start_ts
493460 finally :
494461 num_audits = len (audit_results )
@@ -583,6 +550,69 @@ def _dag(self, batches: SnapshotToIntervals) -> DAG[SchedulingUnit]:
583550 )
584551 return dag
585552
553+ def _audit_snapshot (
554+ self ,
555+ snapshot : Snapshot ,
556+ deployability_index : DeployabilityIndex ,
557+ snapshots : t .Dict [str , Snapshot ],
558+ start : t .Optional [TimeLike ] = None ,
559+ end : t .Optional [TimeLike ] = None ,
560+ execution_time : t .Optional [TimeLike ] = None ,
561+ wap_id : t .Optional [str ] = None ,
562+ environment_naming_info : t .Optional [EnvironmentNamingInfo ] = None ,
563+ ** kwargs : t .Any ,
564+ ) -> t .List [AuditResult ]:
565+ is_deployable = deployability_index .is_deployable (snapshot )
566+
567+ audit_results = self .snapshot_evaluator .audit (
568+ snapshot = snapshot ,
569+ start = start ,
570+ end = end ,
571+ execution_time = execution_time ,
572+ snapshots = snapshots ,
573+ deployability_index = deployability_index ,
574+ wap_id = wap_id ,
575+ ** kwargs ,
576+ )
577+
578+ audit_errors_to_raise : t .List [AuditError ] = []
579+ audit_errors_to_warn : t .List [AuditError ] = []
580+ for audit_result in (result for result in audit_results if result .count ):
581+ error = AuditError (
582+ audit_name = audit_result .audit .name ,
583+ audit_args = audit_result .audit_args ,
584+ model = snapshot .model_or_none ,
585+ count = t .cast (int , audit_result .count ),
586+ query = t .cast (exp .Query , audit_result .query ),
587+ adapter_dialect = self .snapshot_evaluator .adapter .dialect ,
588+ )
589+ self .notification_target_manager .notify (NotificationEvent .AUDIT_FAILURE , error )
590+ if is_deployable and snapshot .node .owner :
591+ self .notification_target_manager .notify_user (
592+ NotificationEvent .AUDIT_FAILURE , snapshot .node .owner , error
593+ )
594+ if audit_result .blocking :
595+ audit_errors_to_raise .append (error )
596+ else :
597+ audit_errors_to_warn .append (error )
598+
599+ if audit_errors_to_raise :
600+ raise NodeAuditsErrors (audit_errors_to_raise )
601+
602+ if environment_naming_info :
603+ for audit_error in audit_errors_to_warn :
604+ display_name = snapshot .display_name (
605+ environment_naming_info ,
606+ self .default_catalog ,
607+ self .snapshot_evaluator .adapter .dialect ,
608+ )
609+ self .console .log_warning (
610+ f"\n { display_name } : { audit_error } ." ,
611+ f"{ audit_error } . Audit query:\n { audit_error .query .sql (audit_error .adapter_dialect )} " ,
612+ )
613+
614+ return audit_results
615+
586616
587617def compute_interval_params (
588618 snapshots : t .Collection [Snapshot ],
0 commit comments