Skip to content

Commit 5d3e3fe

Browse files
committed
fix: correct metrics summary implementations
1 parent c66dec1 commit 5d3e3fe

File tree

1 file changed

+52
-32
lines changed

1 file changed

+52
-32
lines changed

sdk/python/feast/api/registry/rest/metrics.py

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -388,15 +388,15 @@ async def recently_visited(
388388
"pagination": pagination,
389389
}
390390

391-
@router.get("/metrics/summary", tags=["Metrics"])
392-
async def metrics_summary(
391+
@router.get("/metrics/summary", tags=["Metrics"])
392+
async def metrics_summary(
393393
allow_cache: bool = Query(True),
394-
):
395-
"""
396-
Returns registry-level metadat summary statistics.
397-
"""
394+
):
395+
"""
396+
Returns registry-level metadata summary statistics.
397+
"""
398398

399-
#Get all projects
399+
# Fetch all projects
400400
projects_resp = grpc_call(
401401
grpc_handler.ListProjects,
402402
RegistryServer_pb2.ListProjectsRequest(allow_cache=allow_cache),
@@ -405,7 +405,7 @@ async def metrics_summary(
405405
projects = projects_resp.get("projects", [])
406406
total_projects = len(projects)
407407

408-
#Initialize counters
408+
# Initialize totals
409409
totals = {
410410
"entities": 0,
411411
"dataSources": 0,
@@ -415,70 +415,90 @@ async def metrics_summary(
415415
"featureServices": 0,
416416
}
417417

418-
last__updates_ts = None
419-
420-
#Iterate through projects
418+
last_updated_ts = None
421419

420+
# Loop through projects
422421
for project in projects:
423422
project_name = project["spec"]["name"]
424423

425-
#count entities
424+
# Entities
426425
entities = grpc_call(
426+
grpc_handler.ListEntities,
427+
RegistryServer_pb2.ListEntitiesRequest(
428+
project=project_name, allow_cache=allow_cache
429+
),
430+
)
431+
432+
# Data sources
433+
data_sources = grpc_call(
427434
grpc_handler.ListDataSources,
428435
RegistryServer_pb2.ListDataSourcesRequest(
429436
project=project_name, allow_cache=allow_cache
430437
),
431438
)
432439

433-
#Count saved datasets
434-
try:
440+
# Saved datasets
441+
try:
435442
saved_datasets = grpc_call(
436443
grpc_handler.ListSavedDatasets,
437444
RegistryServer_pb2.ListSavedDatasetsRequest(
438445
project=project_name, allow_cache=allow_cache
439446
),
440447
)
448+
except Exception:
449+
saved_datasets = {"savedDatasets": []}
450+
451+
# Features
452+
try:
453+
features = grpc_call(
454+
grpc_handler.ListFeatures,
455+
RegistryServer_pb2.ListFeaturesRequest(
456+
project=project_name, allow_cache=allow_cache
457+
),
458+
)
441459
except Exception:
442460
features = {"features": []}
443461

444-
#Count feature views
462+
# Feature views
445463
try:
446464
feature_views = grpc_call(
447-
grpc_handler.ListAllFeaturesViews,
465+
grpc_handler.ListAllFeatureViews,
448466
RegistryServer_pb2.ListAllFeatureViewsRequest(
449467
project=project_name, allow_cache=allow_cache
450468
),
451469
)
452-
except:
453-
feature_views = {"feature_views": []}
470+
except Exception:
471+
feature_views = {"featureViews": []}
454472

455-
# Count feature services
473+
# Feature services
456474
try:
457475
feature_services = grpc_call(
458476
grpc_handler.ListFeatureServices,
459477
RegistryServer_pb2.ListFeatureServicesRequest(
460478
project=project_name, allow_cache=allow_cache
461479
),
462480
)
463-
except:
464-
feature_services = {"feature_services": []}
481+
except Exception:
482+
feature_services = {"featureServices": []}
465483

466484
# Aggregate counts
467-
total["entities"] += len(entities.get("entities", []))
468-
totals["dataSources"] += len(dataSources.get("dataSources", []))
469-
totals["savedDatasets"] += len(savedDatasets.get("savedDatsets", []))
485+
totals["entities"] += len(entities.get("entities", []))
486+
totals["dataSources"] += len(data_sources.get("dataSources", []))
487+
totals["savedDatasets"] += len(saved_datasets.get("savedDatasets", []))
470488
totals["features"] += len(features.get("features", []))
471-
totals["featureViews"] += len(featureViews.get("featureViews", []))
472-
totals["featureServices"] += len(featureServices.get("featureServices", []))
489+
totals["featureViews"] += len(feature_views.get("featureViews", []))
490+
totals["featureServices"] += len(
491+
feature_services.get("featureServices", [])
492+
)
473493

474-
# Track last updated timestamp (best effort)
494+
# Track latest update timestamp (best effort)
475495
for fv in feature_views.get("featureViews", []):
476496
meta = fv.get("meta", {})
477497
ts = meta.get("lastUpdatedTimestamp")
478498

479-
if ts:
480-
if last_updates_ts is None or ts > last_updated_ts:
481-
last_updated_ts
499+
if ts:
500+
if last_updated_ts is None or ts > last_updated_ts:
501+
last_updated_ts = ts
482502

483503
return {
484504
"totalProjects": total_projects,
@@ -487,8 +507,8 @@ async def metrics_summary(
487507
"totalSavedDatasets": totals["savedDatasets"],
488508
"totalFeatures": totals["features"],
489509
"totalFeatureViews": totals["featureViews"],
490-
"totalFeatureServices": totals["featureServices"],\
491-
"lastUpdatedTImestamp": last_updated_ts,
510+
"totalFeatureServices": totals["featureServices"],
511+
"lastUpdatedTimestamp": last_updated_ts,
492512
}
493513

494514
return router

0 commit comments

Comments
 (0)