Skip to content

Commit

Permalink
chore(anomaly-detection) Return meaningful errors on failure of save …
Browse files Browse the repository at this point in the history
…endpoint
  • Loading branch information
ram-senth committed Sep 11, 2024
1 parent c20a95e commit dc6ab89
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
39 changes: 27 additions & 12 deletions src/seer/anomaly_detection/anomaly_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ def store_data(
"minimum_required": min_len,
},
)
raise Exception(f"Insufficient time series data for alert {request.alert.id}")
return StoreDataResponse(
success=False, message=f"Insufficient time series data for alert {request.alert.id}"
)

logger.info(
"store_alert_request",
Expand All @@ -264,14 +266,27 @@ def store_data(
"num_datapoints": len(request.timeseries),
},
)
ts, anomalies = self._batch_detect(request.timeseries, request.config)
alert_data_accessor.save_alert(
organization_id=request.organization_id,
project_id=request.project_id,
external_alert_id=request.alert.id,
config=request.config,
timeseries=ts,
anomalies=anomalies,
anomaly_algo_data={"window_size": anomalies.window_size},
)
return StoreDataResponse(success=True)
try:
ts, anomalies = self._batch_detect(request.timeseries, request.config)
alert_data_accessor.save_alert(
organization_id=request.organization_id,
project_id=request.project_id,
external_alert_id=request.alert.id,
config=request.config,
timeseries=ts,
anomalies=anomalies,
anomaly_algo_data={"window_size": anomalies.window_size},
)
return StoreDataResponse(success=True)
except Exception as e:
sentry_sdk.capture_exception(e)
logger.error(
"error_saving_alert",
extra={
"organization_id": request.organization_id,
"project_id": request.project_id,
"external_alert_id": request.alert.id,
},
exc_info=e,
)
return StoreDataResponse(success=False, message=str(e))
1 change: 1 addition & 0 deletions src/seer/anomaly_detection/models/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ class StoreDataRequest(BaseModel):

class StoreDataResponse(BaseModel):
success: bool
message: Optional[str] = Field(None)

0 comments on commit dc6ab89

Please sign in to comment.