forked from feast-dev/feast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseLoadOpenLineageGraph.ts
More file actions
132 lines (117 loc) · 3.14 KB
/
Copy pathuseLoadOpenLineageGraph.ts
File metadata and controls
132 lines (117 loc) · 3.14 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
import { useContext } from "react";
import { useQuery } from "react-query";
import RegistryPathContext from "../contexts/RegistryPathContext";
import { useDataMode } from "../contexts/DataModeContext";
import restFetch from "./restApiClient";
export interface OpenLineageNode {
type: string;
namespace: string;
name: string;
producer?: string;
feast_object_type?: string;
feast_object_name?: string;
feast_project?: string;
schema?: any;
description?: string;
job_type?: string;
source_type?: string;
facets?: Record<string, any>;
}
export interface OpenLineageEdge {
source_type: string;
source_namespace: string;
source_name: string;
target_type: string;
target_namespace: string;
target_name: string;
edge_type?: string;
updated_at?: number;
}
export interface OpenLineageSymlink {
dataset_namespace: string;
dataset_name: string;
linked_namespace: string;
linked_name: string;
link_type: string;
}
export interface OpenLineageGraphData {
nodes: OpenLineageNode[];
edges: OpenLineageEdge[];
symlinks?: OpenLineageSymlink[];
}
export interface OpenLineageEvent {
event_id: string;
event_type: string;
event_time: number;
producer?: string;
job_namespace: string;
job_name: string;
run_id?: string;
event_json: string;
created_at: number;
}
export interface RegistryRelationship {
source: { type: string; name: string };
target: { type: string; name: string };
type: string;
project?: string;
}
export interface RegistryLineageData {
relationships: RegistryRelationship[];
indirect_relationships: RegistryRelationship[];
}
const useLoadOpenLineageGraph = () => {
const registryUrl = useContext(RegistryPathContext);
const { fetchOptions } = useDataMode();
return useQuery<OpenLineageGraphData>(
["openlineage-graph"],
() =>
restFetch<OpenLineageGraphData>(
registryUrl,
"/lineage/openlineage/graph",
fetchOptions,
),
{ enabled: !!registryUrl },
);
};
const useLoadOpenLineageEvents = (
namespace?: string,
jobName?: string,
limit: number = 100,
) => {
const registryUrl = useContext(RegistryPathContext);
const { fetchOptions } = useDataMode();
const params = new URLSearchParams();
if (namespace) params.set("namespace", namespace);
if (jobName) params.set("job_name", jobName);
params.set("limit", limit.toString());
return useQuery<{ events: OpenLineageEvent[]; total: number }>(
["openlineage-events", namespace, jobName, limit],
() =>
restFetch(
registryUrl,
`/lineage/openlineage/events?${params.toString()}`,
fetchOptions,
),
{ enabled: !!registryUrl },
);
};
const useLoadRegistryLineage = (project?: string) => {
const registryUrl = useContext(RegistryPathContext);
const { fetchOptions } = useDataMode();
return useQuery<RegistryLineageData>(
["registry-lineage", project],
() =>
restFetch<RegistryLineageData>(
registryUrl,
`/lineage/registry?project=${project}`,
fetchOptions,
),
{ enabled: !!registryUrl && !!project },
);
};
export {
useLoadOpenLineageGraph,
useLoadOpenLineageEvents,
useLoadRegistryLineage,
};