-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: Add feature quality monitoring with statistical metrics, REST API, and CLI #6202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jyejare
wants to merge
1
commit into
feast-dev:master
Choose a base branch
from
jyejare:monitoring_plus
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,232 @@ | ||
| import logging | ||
| from datetime import date | ||
| from typing import List, Optional | ||
|
|
||
| from fastapi import APIRouter, HTTPException, Query | ||
| from pydantic import BaseModel, Field | ||
|
|
||
| from feast.monitoring.monitoring_service import MonitoringService | ||
| from feast.permissions.action import AuthzedAction | ||
| from feast.permissions.security_manager import assert_permissions | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class ComputeMetricsRequest(BaseModel): | ||
| project: str = Field(..., description="Feast project name") | ||
| feature_view_name: Optional[str] = Field( | ||
| None, description="Feature view name (null = all)" | ||
| ) | ||
| feature_names: Optional[List[str]] = Field( | ||
| None, description="Feature names to compute (null = all)" | ||
| ) | ||
| start_date: Optional[str] = Field( | ||
| None, description="Start date (YYYY-MM-DD), defaults to yesterday" | ||
| ) | ||
| end_date: Optional[str] = Field( | ||
| None, description="End date (YYYY-MM-DD), defaults to today" | ||
| ) | ||
| data_source_type: str = Field(..., description="Data source: 'batch' or 'log'") | ||
| set_baseline: bool = Field( | ||
| False, description="Mark this computation as the baseline" | ||
| ) | ||
|
|
||
|
|
||
| class ComputeMetricsResponse(BaseModel): | ||
| status: str | ||
| data_source_type: str | ||
| computed_features: int | ||
| computed_feature_views: int | ||
| computed_feature_services: int | ||
| metric_dates: List[str] | ||
| duration_ms: int | ||
|
|
||
|
|
||
| def get_monitoring_router(grpc_handler, server=None) -> APIRouter: | ||
| router = APIRouter() | ||
|
|
||
| def _get_monitoring_service() -> MonitoringService: | ||
| if server is None or not hasattr(server, "store"): | ||
| raise HTTPException( | ||
| status_code=500, | ||
| detail="Failed to access monitoring service: server store not available", | ||
| ) | ||
| return MonitoringService(server.store) | ||
|
|
||
| def _assert_fv_permission( | ||
| project: str, feature_view_name: str, action: AuthzedAction | ||
| ): | ||
| try: | ||
| fv = server.store.registry.get_feature_view( | ||
| name=feature_view_name, project=project | ||
| ) | ||
| assert_permissions(fv, actions=[action]) | ||
| except Exception: | ||
| pass | ||
|
|
||
| @router.post( | ||
| "/monitoring/compute", | ||
| tags=["Monitoring"], | ||
| response_model=ComputeMetricsResponse, | ||
| ) | ||
| async def compute_metrics(request: ComputeMetricsRequest): | ||
| if request.data_source_type not in ("batch", "log"): | ||
| raise HTTPException( | ||
| status_code=422, | ||
| detail="data_source_type must be 'batch' or 'log'", | ||
| ) | ||
|
|
||
| if request.feature_view_name: | ||
| _assert_fv_permission( | ||
| request.project, request.feature_view_name, AuthzedAction.UPDATE | ||
| ) | ||
|
|
||
| svc = _get_monitoring_service() | ||
|
|
||
| start_d = _parse_date(request.start_date) if request.start_date else None | ||
| end_d = _parse_date(request.end_date) if request.end_date else None | ||
|
|
||
| try: | ||
| result = svc.compute_metrics( | ||
| project=request.project, | ||
| feature_view_name=request.feature_view_name, | ||
| feature_names=request.feature_names, | ||
| start_date=start_d, | ||
| end_date=end_d, | ||
| data_source_type=request.data_source_type, | ||
| set_baseline=request.set_baseline, | ||
| ) | ||
| return ComputeMetricsResponse(**result) | ||
| except NotImplementedError as e: | ||
| raise HTTPException(status_code=501, detail=str(e)) | ||
| except Exception as e: | ||
| logger.exception("Failed to compute monitoring metrics") | ||
| raise HTTPException( | ||
| status_code=500, | ||
| detail=f"Failed to compute monitoring metrics: {str(e)}", | ||
| ) | ||
|
|
||
| @router.get("/monitoring/metrics/features", tags=["Monitoring"]) | ||
| async def get_feature_metrics( | ||
| project: str = Query(...), | ||
| feature_view_name: Optional[str] = Query(None), | ||
| feature_name: Optional[str] = Query(None), | ||
| feature_service_name: Optional[str] = Query(None), | ||
| data_source_type: Optional[str] = Query(None), | ||
| start_date: Optional[str] = Query(None), | ||
| end_date: Optional[str] = Query(None), | ||
| ): | ||
| if feature_view_name: | ||
| _assert_fv_permission(project, feature_view_name, AuthzedAction.DESCRIBE) | ||
|
|
||
| svc = _get_monitoring_service() | ||
| return { | ||
| "metrics": svc.get_feature_metrics( | ||
| project=project, | ||
| feature_service_name=feature_service_name, | ||
| feature_view_name=feature_view_name, | ||
| feature_name=feature_name, | ||
| data_source_type=data_source_type, | ||
| start_date=_parse_date(start_date) if start_date else None, | ||
| end_date=_parse_date(end_date) if end_date else None, | ||
| ) | ||
| } | ||
|
|
||
| @router.get("/monitoring/metrics/feature_views", tags=["Monitoring"]) | ||
| async def get_feature_view_metrics( | ||
| project: str = Query(...), | ||
| feature_view_name: Optional[str] = Query(None), | ||
| feature_service_name: Optional[str] = Query(None), | ||
| data_source_type: Optional[str] = Query(None), | ||
| start_date: Optional[str] = Query(None), | ||
| end_date: Optional[str] = Query(None), | ||
| ): | ||
| if feature_view_name: | ||
| _assert_fv_permission(project, feature_view_name, AuthzedAction.DESCRIBE) | ||
|
|
||
| svc = _get_monitoring_service() | ||
| return { | ||
| "metrics": svc.get_feature_view_metrics( | ||
| project=project, | ||
| feature_service_name=feature_service_name, | ||
| feature_view_name=feature_view_name, | ||
| data_source_type=data_source_type, | ||
| start_date=_parse_date(start_date) if start_date else None, | ||
| end_date=_parse_date(end_date) if end_date else None, | ||
| ) | ||
| } | ||
|
|
||
| @router.get("/monitoring/metrics/feature_services", tags=["Monitoring"]) | ||
| async def get_feature_service_metrics( | ||
| project: str = Query(...), | ||
| feature_service_name: Optional[str] = Query(None), | ||
| data_source_type: Optional[str] = Query(None), | ||
| start_date: Optional[str] = Query(None), | ||
| end_date: Optional[str] = Query(None), | ||
| ): | ||
| svc = _get_monitoring_service() | ||
| return { | ||
| "metrics": svc.get_feature_service_metrics( | ||
| project=project, | ||
| feature_service_name=feature_service_name, | ||
| data_source_type=data_source_type, | ||
| start_date=_parse_date(start_date) if start_date else None, | ||
| end_date=_parse_date(end_date) if end_date else None, | ||
| ) | ||
| } | ||
|
|
||
| @router.get("/monitoring/metrics/baseline", tags=["Monitoring"]) | ||
| async def get_baseline( | ||
| project: str = Query(...), | ||
| feature_view_name: Optional[str] = Query(None), | ||
| feature_name: Optional[str] = Query(None), | ||
| data_source_type: Optional[str] = Query(None), | ||
| ): | ||
| if feature_view_name: | ||
| _assert_fv_permission(project, feature_view_name, AuthzedAction.DESCRIBE) | ||
|
|
||
| svc = _get_monitoring_service() | ||
| return { | ||
| "metrics": svc.get_baseline( | ||
| project=project, | ||
| feature_view_name=feature_view_name, | ||
| feature_name=feature_name, | ||
| data_source_type=data_source_type, | ||
| ) | ||
| } | ||
|
|
||
| @router.get("/monitoring/metrics/timeseries", tags=["Monitoring"]) | ||
| async def get_timeseries( | ||
| project: str = Query(...), | ||
| feature_view_name: Optional[str] = Query(None), | ||
| feature_name: Optional[str] = Query(None), | ||
| feature_service_name: Optional[str] = Query(None), | ||
| data_source_type: Optional[str] = Query(None), | ||
| start_date: Optional[str] = Query(None), | ||
| end_date: Optional[str] = Query(None), | ||
| granularity: str = Query("daily"), | ||
| ): | ||
| if feature_view_name: | ||
| _assert_fv_permission(project, feature_view_name, AuthzedAction.DESCRIBE) | ||
|
|
||
| svc = _get_monitoring_service() | ||
| metrics = svc.get_timeseries( | ||
| project=project, | ||
| feature_view_name=feature_view_name, | ||
| feature_name=feature_name, | ||
| feature_service_name=feature_service_name, | ||
| data_source_type=data_source_type, | ||
| start_date=_parse_date(start_date) if start_date else None, | ||
| end_date=_parse_date(end_date) if end_date else None, | ||
| ) | ||
|
|
||
| return { | ||
| "granularity": granularity, | ||
| "timeseries": metrics, | ||
| } | ||
|
|
||
| return router | ||
|
|
||
|
|
||
| def _parse_date(date_str: str) -> date: | ||
| return date.fromisoformat(date_str) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Permission check silently swallows all exceptions, completely bypassing RBAC
_assert_fv_permissionwraps the entire permission check inexcept Exception: pass, which catches and ignoresFeastPermissionErrorraised byassert_permissionswhen the user is unauthorized. As confirmed infeast/permissions/enforcer.py,FeastPermissionErrorinherits fromException(viafeast/errors.py:568). This means every call to_assert_fv_permissionis a no-op — unauthorized users can compute metrics (UPDATE action) and read monitoring data (DESCRIBE action) for any feature view without restriction.Was this helpful? React with 👍 or 👎 to provide feedback.