From 5f3e1295b98938137a4db6c5b151d976d36274f6 Mon Sep 17 00:00:00 2001 From: kbatra Date: Fri, 28 Jul 2023 11:58:58 -0500 Subject: [PATCH] fix: add exception handling Signed-off-by: kbatra --- udf/anomaly-detection/src/udf/inference.py | 10 ++++++++++ udf/anomaly-detection/src/udf/preprocess.py | 10 ++++++++++ udf/anomaly-detection/src/udf/threshold.py | 11 +++++++++++ 3 files changed, 31 insertions(+) diff --git a/udf/anomaly-detection/src/udf/inference.py b/udf/anomaly-detection/src/udf/inference.py index 2f9601c4..7e4c1f70 100644 --- a/udf/anomaly-detection/src/udf/inference.py +++ b/udf/anomaly-detection/src/udf/inference.py @@ -93,6 +93,16 @@ def inference( ) return static_response + except Exception as ex: + _LOGGER.exception( + "%s - Unhandled exception while fetching inference artifact, Keys: %s, Metric: %s, Error: %r", + payload.uuid, + payload.composite_keys, + payload.metrics, + ex, + ) + return static_response + # Check if artifact is found if not artifact_data: _LOGGER.info( diff --git a/udf/anomaly-detection/src/udf/preprocess.py b/udf/anomaly-detection/src/udf/preprocess.py index 8ccd1ac2..e9064f29 100644 --- a/udf/anomaly-detection/src/udf/preprocess.py +++ b/udf/anomaly-detection/src/udf/preprocess.py @@ -67,6 +67,16 @@ def preprocess(self, keys: List[str], payload: StreamPayload) -> (np.ndarray, St ) return None, Status.RUNTIME_ERROR + except Exception as ex: + _LOGGER.exception( + "%s - Unhandled exception while fetching preproc artifact, Keys: %s, Metric: %s, Error: %r", + payload.uuid, + payload.composite_keys, + payload.metrics, + ex, + ) + return None, Status.RUNTIME_ERROR + # Check if artifact is found if not preproc_artifact: _LOGGER.info( diff --git a/udf/anomaly-detection/src/udf/threshold.py b/udf/anomaly-detection/src/udf/threshold.py index 733ff1e9..6785ce0a 100644 --- a/udf/anomaly-detection/src/udf/threshold.py +++ b/udf/anomaly-detection/src/udf/threshold.py @@ -64,6 +64,17 @@ def threshold( static_scores = calculate_static_thresh(metric_arr, static_thresh) return static_scores, Status.RUNTIME_ERROR, Header.STATIC_INFERENCE, -1 + except Exception as ex: + _LOGGER.exception( + "%s - Unhandled exception while fetching threshold artifact, Keys: %s, Metric: %s, Error: %r", + payload.uuid, + payload.composite_keys, + payload.metrics, + ex, + ) + static_scores = calculate_static_thresh(metric_arr, static_thresh) + return static_scores, Status.RUNTIME_ERROR, Header.STATIC_INFERENCE, -1 + # Check if artifact is found if not thresh_artifact: _LOGGER.info(