@@ -51,37 +51,43 @@ class ComputeTransientRequest(BaseModel):
5151 end_date : Optional [str ] = None
5252
5353
54- def get_monitoring_router (grpc_handler , server = None ):
54+ def get_monitoring_router (grpc_handler , store = None ):
5555 router = APIRouter ()
5656
5757 _monitoring_service = None
5858
5959 def _get_monitoring_service ():
6060 nonlocal _monitoring_service
6161 if _monitoring_service is None :
62+ if store is None :
63+ raise HTTPException (
64+ status_code = 503 ,
65+ detail = "Monitoring service is not available: no FeatureStore configured" ,
66+ )
6267 from feast .monitoring .monitoring_service import MonitoringService
6368
64- store = server .store if server else grpc_handler .store
6569 _monitoring_service = MonitoringService (store )
6670 return _monitoring_service
6771
6872 def _get_store ():
69- return server .store if server else grpc_handler .store
73+ if store is None :
74+ raise HTTPException (
75+ status_code = 503 ,
76+ detail = "Monitoring service is not available: no FeatureStore configured" ,
77+ )
78+ return store
7079
7180 # ------------------------------------------------------------------ #
7281 # DQM Job: submit and track
7382 # ------------------------------------------------------------------ #
7483
7584 @router .post ("/monitoring/compute" , tags = ["Monitoring" ])
7685 async def compute_metrics (request : ComputeMetricsRequest ):
77- """Submit a DQM job to compute and store metrics. Returns job_id."""
78- if request .granularity not in VALID_GRANULARITIES :
79- raise HTTPException (
80- status_code = 400 ,
81- detail = f"Invalid granularity '{ request .granularity } '. "
82- f"Must be one of { VALID_GRANULARITIES } " ,
83- )
86+ """Submit a DQM job to compute and store metrics. Returns job_id.
8487
88+ When set_baseline is True and no date range is provided, computes
89+ baseline from all available source data.
90+ """
8591 store = _get_store ()
8692 if request .feature_view_name :
8793 fv = store .registry .get_feature_view (
@@ -91,6 +97,24 @@ async def compute_metrics(request: ComputeMetricsRequest):
9197
9298 svc = _get_monitoring_service ()
9399
100+ if request .set_baseline and not request .start_date and not request .end_date :
101+ try :
102+ result = svc .compute_baseline (
103+ project = request .project ,
104+ feature_view_name = request .feature_view_name ,
105+ feature_names = request .feature_names ,
106+ )
107+ return result
108+ except Exception as e :
109+ raise HTTPException (status_code = 500 , detail = str (e ))
110+
111+ if request .granularity not in VALID_GRANULARITIES :
112+ raise HTTPException (
113+ status_code = 400 ,
114+ detail = f"Invalid granularity '{ request .granularity } '. "
115+ f"Must be one of { VALID_GRANULARITIES } " ,
116+ )
117+
94118 params : Dict [str , Any ] = {}
95119 if request .start_date :
96120 params ["start_date" ] = request .start_date
@@ -108,7 +132,6 @@ async def compute_metrics(request: ComputeMetricsRequest):
108132 parameters = params ,
109133 )
110134
111- # Execute synchronously for now; async worker is a future enhancement
112135 try :
113136 result = svc .execute_job (job_id )
114137 return {"job_id" : job_id , ** result }
0 commit comments