Skip to content

Commit 92feb60

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: Add properties feature_stats_and_anomalies to FeatureMonitorJob
PiperOrigin-RevId: 704833055
1 parent 52ce05a commit 92feb60

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

tests/unit/vertexai/feature_store_constants.py

+23
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,33 @@
421421
_TEST_FG1_FMJ1_PATH = f"{_TEST_PARENT}/featureGroups/{_TEST_FG1_ID}/featureMonitors/{_TEST_FG1_FM1_ID}/featureMonitorJobs/{_TEST_FG1_FMJ1_ID}"
422422
_TEST_FG1_FMJ1_DESCRIPTION = "My feature monitor job 1 in feature monitor 1"
423423
_TEST_FG1_FMJ1_LABELS = {"my_fg1_feature_monitor_job": "fmj1"}
424+
_TEST_FG1_F1_FEATURE_STATS_AND_ANOMALY = types.feature_monitor.FeatureStatsAndAnomaly(
425+
feature_id="my_fg1_f1",
426+
distribution_deviation=0.5,
427+
drift_detection_threshold=0.4,
428+
drift_detected=True,
429+
feature_monitor_job_id=_TEST_FG1_FMJ1_ID,
430+
feature_monitor_id=_TEST_FG1_FM1_ID,
431+
)
432+
_TEST_FG1_F2_FEATURE_STATS_AND_ANOMALY = types.feature_monitor.FeatureStatsAndAnomaly(
433+
feature_id="my_fg1_f2",
434+
distribution_deviation=0.2,
435+
drift_detection_threshold=0.4,
436+
drift_detected=False,
437+
feature_monitor_job_id=_TEST_FG1_FMJ1_ID,
438+
feature_monitor_id=_TEST_FG1_FM1_ID,
439+
)
440+
_TEST_FG1_FMJ1_FEATURE_STATS_AND_ANOMALIES = [
441+
_TEST_FG1_F1_FEATURE_STATS_AND_ANOMALY,
442+
_TEST_FG1_F2_FEATURE_STATS_AND_ANOMALY,
443+
]
424444
_TEST_FG1_FMJ1 = types.feature_monitor_job.FeatureMonitorJob(
425445
name=_TEST_FG1_FMJ1_PATH,
426446
description=_TEST_FG1_FMJ1_DESCRIPTION,
427447
labels=_TEST_FG1_FMJ1_LABELS,
448+
job_summary=types.feature_monitor_job.FeatureMonitorJob.JobSummary(
449+
feature_stats_and_anomalies=_TEST_FG1_FMJ1_FEATURE_STATS_AND_ANOMALIES
450+
),
428451
)
429452
_TEST_FG1_FMJ2_ID = "1234567891"
430453
_TEST_FG1_FMJ2_PATH = f"{_TEST_PARENT}/featureGroups/{_TEST_FG1_ID}/featureMonitors/{_TEST_FG1_FM1_ID}/featureMonitorJobs/{_TEST_FG1_FMJ2_ID}"

tests/unit/vertexai/test_feature_monitor.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#
1717

1818
import re
19-
from typing import Dict, List, Tuple
19+
from typing import Dict, List, Optional, Tuple
2020
from unittest.mock import patch
2121

2222
from google.cloud import aiplatform
@@ -34,6 +34,7 @@
3434
_TEST_FG1_FM1_SCHEDULE_CONFIG,
3535
_TEST_FG1_FMJ1,
3636
_TEST_FG1_FMJ1_DESCRIPTION,
37+
_TEST_FG1_FMJ1_FEATURE_STATS_AND_ANOMALIES,
3738
_TEST_FG1_FMJ1_ID,
3839
_TEST_FG1_FMJ1_LABELS,
3940
_TEST_FG1_FMJ_LIST,
@@ -127,13 +128,21 @@ def feature_monitor_job_eq(
127128
location: str,
128129
description: str,
129130
labels: Dict[str, str],
131+
feature_stats_and_anomalies: Optional[
132+
List[types.feature_monitor.FeatureStatsAndAnomaly]
133+
] = None,
130134
):
131135
"""Check if a Feature Monitor Job has the appropriate values set."""
132136
assert feature_monitor_job_to_check.resource_name == resource_name
133137
assert feature_monitor_job_to_check.project == project
134138
assert feature_monitor_job_to_check.location == location
135139
assert feature_monitor_job_to_check.description == description
136140
assert feature_monitor_job_to_check.labels == labels
141+
if feature_stats_and_anomalies:
142+
assert (
143+
feature_monitor_job_to_check.feature_stats_and_anomalies
144+
== feature_stats_and_anomalies
145+
)
137146

138147

139148
def test_init_with_feature_monitor_id_and_no_fg_id_raises_error():
@@ -247,6 +256,7 @@ def test_init_with_feature_monitor_job_path(get_feature_monitor_job_mock):
247256
location=_TEST_LOCATION,
248257
description=_TEST_FG1_FMJ1_DESCRIPTION,
249258
labels=_TEST_FG1_FMJ1_LABELS,
259+
feature_stats_and_anomalies=_TEST_FG1_FMJ1_FEATURE_STATS_AND_ANOMALIES,
250260
)
251261

252262

@@ -291,6 +301,7 @@ def test_create_feature_monitor_job(
291301
location=_TEST_LOCATION,
292302
description=_TEST_FG1_FMJ1_DESCRIPTION,
293303
labels=_TEST_FG1_FMJ1_LABELS,
304+
feature_stats_and_anomalies=_TEST_FG1_FMJ1_FEATURE_STATS_AND_ANOMALIES,
294305
)
295306

296307

@@ -320,6 +331,7 @@ def test_get_feature_monitor_job(
320331
location=_TEST_LOCATION,
321332
description=_TEST_FG1_FMJ1_DESCRIPTION,
322333
labels=_TEST_FG1_FMJ1_LABELS,
334+
feature_stats_and_anomalies=_TEST_FG1_FMJ1_FEATURE_STATS_AND_ANOMALIES,
323335
)
324336

325337

vertexai/resources/preview/feature_store/feature_monitor.py

+9
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,15 @@ def description(self) -> str:
189189
"""The description of the feature monitor."""
190190
return self._gca_resource.description
191191

192+
@property
193+
def feature_stats_and_anomalies(
194+
self,
195+
) -> List[gca_feature_monitor.FeatureStatsAndAnomaly]:
196+
"""The feature stats and anomaly of the feature monitor job."""
197+
if self._gca_resource.job_summary:
198+
return self._gca_resource.job_summary.feature_stats_and_anomalies
199+
return []
200+
192201
def create_feature_monitor_job(
193202
self,
194203
description: Optional[str] = None,

0 commit comments

Comments
 (0)