-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathlineage.py
More file actions
288 lines (265 loc) · 11.5 KB
/
lineage.py
File metadata and controls
288 lines (265 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
"""REST API endpoints for registry lineage and relationships."""
import logging
from typing import Optional
from fastapi import APIRouter, Depends, Query
from feast.api.registry.rest.rest_utils import (
create_grpc_pagination_params,
create_grpc_sorting_params,
get_all_project_resources,
get_pagination_params,
get_sorting_params,
grpc_call,
)
from feast.protos.feast.registry import RegistryServer_pb2
logger = logging.getLogger(__name__)
def get_lineage_router(grpc_handler) -> APIRouter:
router = APIRouter()
@router.get("/lineage/registry")
def get_registry_lineage(
project: str = Query(...),
allow_cache: bool = Query(True),
filter_object_type: Optional[str] = Query(None),
filter_object_name: Optional[str] = Query(None),
pagination_params: dict = Depends(get_pagination_params),
sorting_params: dict = Depends(get_sorting_params),
):
"""
Get complete registry lineage with relationships and indirect relationships.
Args:
project: Project name
allow_cache: Whether to allow cached data
filter_object_type: Optional filter by object type (dataSource, entity, featureView, featureService, feature)
filter_object_name: Optional filter by object name
Returns:
Dictionary containing relationships and indirect_relationships arrays
"""
req = RegistryServer_pb2.GetRegistryLineageRequest(
project=project,
allow_cache=allow_cache,
filter_object_type=filter_object_type or "",
filter_object_name=filter_object_name or "",
pagination=create_grpc_pagination_params(pagination_params),
sorting=create_grpc_sorting_params(sorting_params),
)
response = grpc_call(grpc_handler.GetRegistryLineage, req)
return {
"relationships": response.get("relationships", []),
"indirect_relationships": response.get("indirectRelationships", []),
"relationships_pagination": response.get("relationshipsPagination", {}),
"indirect_relationships_pagination": response.get(
"indirectRelationshipsPagination", {}
),
}
@router.get("/lineage/objects/{object_type}/{object_name}")
def get_object_relationships_path(
object_type: str,
object_name: str,
project: str = Query(...),
include_indirect: bool = Query(False),
allow_cache: bool = Query(True),
pagination_params: dict = Depends(get_pagination_params),
sorting_params: dict = Depends(get_sorting_params),
):
"""
Get relationships for a specific object.
Args:
object_type: Type of object (dataSource, entity, featureView, featureService, feature)
object_name: Name of the object
project: Project name
include_indirect: Whether to include indirect relationships
allow_cache: Whether to allow cached data
Returns:
Dictionary containing relationships array for the specific object
"""
valid_types = [
"dataSource",
"entity",
"featureView",
"featureService",
"feature",
]
if object_type not in valid_types:
raise ValueError(
f"Invalid object_type. Must be one of: {', '.join(valid_types)}"
)
req = RegistryServer_pb2.GetObjectRelationshipsRequest(
project=project,
object_type=object_type,
object_name=object_name,
include_indirect=include_indirect,
allow_cache=allow_cache,
pagination=create_grpc_pagination_params(pagination_params),
sorting=create_grpc_sorting_params(sorting_params),
)
return grpc_call(grpc_handler.GetObjectRelationships, req)
@router.get("/lineage/complete")
def get_complete_registry_data(
project: str = Query(...),
allow_cache: bool = Query(True),
pagination_params: dict = Depends(get_pagination_params),
sorting_params: dict = Depends(get_sorting_params),
):
"""
Get complete registry data.
This endpoint provides all the data the UI currently loads:
- All registry objects
- Relationships
- Indirect relationships
- Merged feature view data
- Features
Args:
project: Project name
allow_cache: Whether to allow cached data
pagination_params: Pagination parameters (page, page_size)
sorting_params: Sorting parameters (sort_by, sort_order)
Returns:
Complete registry data structure with pagination metadata.
Note:
Pagination and sorting are applied to each object type separately.
"""
# Create pagination and sorting parameters for gRPC calls
grpc_pagination = create_grpc_pagination_params(pagination_params)
grpc_sorting = create_grpc_sorting_params(sorting_params)
# Get lineage data
lineage_req = RegistryServer_pb2.GetRegistryLineageRequest(
project=project,
allow_cache=allow_cache,
pagination=grpc_pagination,
sorting=grpc_sorting,
)
lineage_response = grpc_call(grpc_handler.GetRegistryLineage, lineage_req)
# Get all registry objects using shared helper function
project_resources, pagination, errors = get_all_project_resources(
grpc_handler,
project,
allow_cache,
tags={},
pagination_params=pagination_params,
sorting_params=sorting_params,
)
if errors and not project_resources:
logger.error(
f"Error getting project resources for project {project}: {errors}"
)
return {
"project": project,
"objects": {},
"relationships": [],
"indirectRelationships": [],
"pagination": {},
}
return {
"project": project,
"objects": {
"entities": project_resources.get("entities", []),
"dataSources": project_resources.get("dataSources", []),
"featureViews": project_resources.get("featureViews", []),
"featureServices": project_resources.get("featureServices", []),
"features": project_resources.get("features", []),
},
"relationships": lineage_response.get("relationships", []),
"indirectRelationships": lineage_response.get("indirectRelationships", []),
"pagination": {
# Get pagination metadata from project_resources if available, otherwise use empty dicts
"entities": pagination.get("entities", {}),
"dataSources": pagination.get("dataSources", {}),
"featureViews": pagination.get("featureViews", {}),
"featureServices": pagination.get("featureServices", {}),
"features": pagination.get("features", {}),
"relationships": lineage_response.get("relationshipsPagination", {}),
"indirectRelationships": lineage_response.get(
"indirectRelationshipsPagination", {}
),
},
}
@router.get("/lineage/registry/all")
def get_registry_lineage_all(
allow_cache: bool = Query(True),
filter_object_type: Optional[str] = Query(None),
filter_object_name: Optional[str] = Query(None),
):
projects_resp = grpc_call(
grpc_handler.ListProjects,
RegistryServer_pb2.ListProjectsRequest(allow_cache=allow_cache),
)
projects = projects_resp.get("projects", [])
all_relationships = []
all_indirect_relationships = []
for project in projects:
project_name = project["spec"]["name"]
req = RegistryServer_pb2.GetRegistryLineageRequest(
project=project_name,
allow_cache=allow_cache,
filter_object_type=filter_object_type or "",
filter_object_name=filter_object_name or "",
)
response = grpc_call(grpc_handler.GetRegistryLineage, req)
relationships = response.get("relationships", [])
indirect_relationships = response.get("indirectRelationships", [])
# Optionally add project info to each relationship
for rel in relationships:
rel["project"] = project_name
for rel in indirect_relationships:
rel["project"] = project_name
all_relationships.extend(relationships)
all_indirect_relationships.extend(indirect_relationships)
return {
"relationships": all_relationships,
"indirect_relationships": all_indirect_relationships,
}
@router.get("/lineage/complete/all")
def get_complete_registry_data_all(
allow_cache: bool = Query(True),
):
projects_resp = grpc_call(
grpc_handler.ListProjects,
RegistryServer_pb2.ListProjectsRequest(allow_cache=allow_cache),
)
projects = projects_resp.get("projects", [])
all_data = []
for project in projects:
project_name = project["spec"]["name"]
# Get lineage data
lineage_req = RegistryServer_pb2.GetRegistryLineageRequest(
project=project_name,
allow_cache=allow_cache,
)
lineage_response = grpc_call(grpc_handler.GetRegistryLineage, lineage_req)
# Get all registry objects using shared helper function
project_resources, _, errors = get_all_project_resources(
grpc_handler, project_name, allow_cache, tags={}
)
if errors and not project_resources:
logger.error(
f"Error getting project resources for project {project_name}: {errors}"
)
continue
# Add project field to each object
for entity in project_resources.get("entities", []):
entity["project"] = project_name
for ds in project_resources.get("dataSources", []):
ds["project"] = project_name
for fv in project_resources.get("featureViews", []):
fv["project"] = project_name
for fs in project_resources.get("featureServices", []):
fs["project"] = project_name
for feat in project_resources.get("features", []):
feat["project"] = project_name
all_data.append(
{
"project": project_name,
"objects": {
"entities": project_resources.get("entities", []),
"dataSources": project_resources.get("dataSources", []),
"featureViews": project_resources.get("featureViews", []),
"featureServices": project_resources.get("featureServices", []),
"features": project_resources.get("features", []),
},
"relationships": lineage_response.get("relationships", []),
"indirectRelationships": lineage_response.get(
"indirectRelationships", []
),
}
)
return {"projects": all_data}
return router