Skip to content

Commit 52ade4f

Browse files
authored
🚨 Monitors and alerts (#115)
1 parent 9fbe26c commit 52ade4f

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

docs/mkdocs/docs/tutorial/monitors_alerts.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
## Monitors
44

5+
You can create a monitor in whitebox so that alert are created automaticaly when some value is out of bounds. Here is an example:
6+
7+
```Python
8+
from whitebox import Whitebox, MonitorStatus, MonitorMetrics, AlertSeverity
9+
10+
wb = Whitebox(host="127.0.0.1:8000", api_key="some_api_key")
11+
12+
model_monitor = wb.create_model_monitor(
13+
model_id="mock_model_id",
14+
name="test",
15+
status=MonitorStatus.active,
16+
metric=MonitorMetrics.accuracy,
17+
feature="feature1",
18+
lower_threshold=0.7,
19+
severity=AlertSeverity.high,
20+
email="jaclie.chan@somemail.io",
21+
)
22+
```
23+
524
## Alerts
625

726
Once the metrics reports have been produced, the monitoring alert pipeline is triggered. This means that if you have created any model monitors for a specific metric, alerts will be created if certain criteria are met, based on the thresholds and the monitor types you have specified.

whitebox/sdk/whitebox.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def delete_model(self, model_id: str):
9595

9696
def log_training_dataset(
9797
self, model_id: str, non_processed: pd.DataFrame, processed: pd.DataFrame
98-
):
98+
) -> bool:
9999
"""
100100
Logs a training dataset for a model.
101101
@@ -133,7 +133,7 @@ def log_inferences(
133133
processed: pd.DataFrame,
134134
timestamps: pd.Series,
135135
actuals: pd.Series = None,
136-
):
136+
) -> bool:
137137
"""
138138
Logs inferences of a model.
139139
@@ -195,7 +195,7 @@ def create_model_monitor(
195195
lower_threshold: Optional[float],
196196
severity: AlertSeverity,
197197
email: str,
198-
):
198+
) -> dict:
199199
"""
200200
Creates a monitor for a model.
201201
"""
@@ -219,3 +219,15 @@ def create_model_monitor(
219219

220220
logger.info(result.json())
221221
return result.json()
222+
223+
def get_alerts(self, model_id: str = "") -> dict:
224+
"""
225+
Returns all alerts for a model.
226+
"""
227+
result = requests.get(
228+
url=f"{self.host}/{self.api_version}/alerts?modelId={model_id}",
229+
headers={"api-key": self.api_key},
230+
)
231+
232+
logger.info(result.json())
233+
return result.json()

whitebox/tests/v1/test_sdk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,4 @@ def test_sdk_create_model_monitor(client):
194194
email="jaclie.chan@chinamail.io",
195195
)
196196

197-
assert model_monitor == model_monitor
197+
assert model_monitor is not None

0 commit comments

Comments
 (0)