get pipeline status from elastic search (#16089)

* get pipeline status from elastic search

* fix cypress
This commit is contained in:
Karan Hotchandani 2024-04-30 20:06:50 +05:30 committed by GitHub
parent 7cc6015574
commit 818030b65d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 45 additions and 101 deletions

View File

@ -65,6 +65,7 @@ const EdgeInfoDrawer = ({
const getEdgeInfo = () => { const getEdgeInfo = () => {
const { source, target, data } = edge; const { source, target, data } = edge;
const { sourceHandle, targetHandle } = getColumnSourceTargetHandles(edge); const { sourceHandle, targetHandle } = getColumnSourceTargetHandles(edge);
const { pipeline, pipelineEntityType } = data?.edge ?? {};
let sourceData: Node | undefined, targetData: Node | undefined; let sourceData: Node | undefined, targetData: Node | undefined;
nodes.forEach((node) => { nodes.forEach((node) => {
@ -110,14 +111,12 @@ const EdgeInfoDrawer = ({
}, },
pipeline: { pipeline: {
key: t('label.edge'), key: t('label.edge'),
value: data?.edge?.pipeline value: pipeline ? getEntityName(pipeline) : undefined,
? getEntityName(data?.edge?.pipeline)
: undefined,
link: link:
data?.edge?.pipeline && pipeline &&
entityUtilClassBase.getEntityLink( entityUtilClassBase.getEntityLink(
data?.edge?.pipeline.type, pipelineEntityType,
data?.edge?.pipeline.fullyQualifiedName pipeline.fullyQualifiedName
), ),
}, },
functionInfo: { functionInfo: {

View File

@ -14,13 +14,7 @@
import Icon from '@ant-design/icons/lib/components/Icon'; import Icon from '@ant-design/icons/lib/components/Icon';
import { Button, Tag } from 'antd'; import { Button, Tag } from 'antd';
import classNames from 'classnames'; import classNames from 'classnames';
import React, { import React, { Fragment, useCallback, useMemo } from 'react';
Fragment,
useCallback,
useEffect,
useMemo,
useRef,
} from 'react';
import { EdgeProps, getBezierPath } from 'reactflow'; import { EdgeProps, getBezierPath } from 'reactflow';
import { ReactComponent as FunctionIcon } from '../../../assets/svg/ic-function.svg'; import { ReactComponent as FunctionIcon } from '../../../assets/svg/ic-function.svg';
import { ReactComponent as IconTimesCircle } from '../../../assets/svg/ic-times-circle.svg'; import { ReactComponent as IconTimesCircle } from '../../../assets/svg/ic-times-circle.svg';
@ -61,15 +55,6 @@ export const LineageEdgeIcon = ({
); );
}; };
function usePrevious<T>(value: T) {
const ref = useRef<T>(value);
useEffect(() => {
ref.current = value;
}, [value]);
return ref.current;
}
export const CustomEdge = ({ export const CustomEdge = ({
id, id,
sourceX, sourceX,
@ -93,19 +78,18 @@ export const CustomEdge = ({
} = data; } = data;
const offset = 4; const offset = 4;
const { fromEntity, toEntity, pipeline, pipelineEntityType } =
data?.edge ?? {};
const { const {
tracedNodes, tracedNodes,
tracedColumns, tracedColumns,
isEditMode, isEditMode,
pipelineStatus,
activeLayer, activeLayer,
onAddPipelineClick, onAddPipelineClick,
onColumnEdgeRemove, onColumnEdgeRemove,
fetchPipelineStatus,
} = useLineageProvider(); } = useLineageProvider();
const prevActiveLayer = usePrevious(activeLayer);
const { theme } = useApplicationStore(); const { theme } = useApplicationStore();
const isColumnHighlighted = useMemo(() => { const isColumnHighlighted = useMemo(() => {
@ -179,19 +163,18 @@ export const CustomEdge = ({
}; };
const isColumnLineageAllowed = const isColumnLineageAllowed =
!isColumnLineage && !isColumnLineage && isPipelineEdgeAllowed(fromEntity.type, toEntity.type);
isPipelineEdgeAllowed(data.edge.fromEntity.type, data.edge.toEntity.type);
const hasLabel = useMemo(() => { const hasLabel = useMemo(() => {
if (isColumnLineage) { if (isColumnLineage) {
return false; return false;
} }
if (data.edge?.pipeline) { if (pipeline) {
return getEntityName(data.edge?.pipeline); return getEntityName(pipeline);
} }
return false; return false;
}, [isColumnLineage, data]); }, [isColumnLineage, pipeline]);
const isSelectedEditMode = selected && isEditMode; const isSelectedEditMode = selected && isEditMode;
const isSelected = selected; const isSelected = selected;
@ -210,8 +193,9 @@ export const CustomEdge = ({
}; };
const currentPipelineStatus = useMemo(() => { const currentPipelineStatus = useMemo(() => {
const pipelineData = pipelineStatus[data.edge.pipeline?.fullyQualifiedName]; const isPipelineActiveNow = activeLayer.includes(LineageLayerView.PIPELINE);
if (pipelineData) { const pipelineData = pipeline?.pipelineStatus;
if (pipelineData && isPipelineActiveNow) {
switch (pipelineData.executionStatus) { switch (pipelineData.executionStatus) {
case StatusType.Failed: case StatusType.Failed:
return 'red'; return 'red';
@ -220,11 +204,13 @@ export const CustomEdge = ({
return 'amber'; return 'amber';
case StatusType.Successful: case StatusType.Successful:
return 'green'; return 'green';
default:
return '';
} }
} else {
return '';
} }
}, [data, pipelineStatus]);
return '';
}, [pipeline, activeLayer]);
const blinkingClass = useMemo(() => { const blinkingClass = useMemo(() => {
if (isPipelineRootNode && currentPipelineStatus) { if (isPipelineRootNode && currentPipelineStatus) {
@ -238,8 +224,7 @@ export const CustomEdge = ({
const getLineageEdgeIcon = useCallback( const getLineageEdgeIcon = useCallback(
(icon: React.ReactNode, dataTestId: string, pipelineClass?: string) => { (icon: React.ReactNode, dataTestId: string, pipelineClass?: string) => {
const pipelineData = const pipelineData = pipeline?.pipelineStatus;
pipelineStatus[data.edge.pipeline?.fullyQualifiedName];
return ( return (
<LineageEdgeIcon offset={3} x={edgeCenterX} y={edgeCenterY}> <LineageEdgeIcon offset={3} x={edgeCenterX} y={edgeCenterY}>
@ -256,8 +241,8 @@ export const CustomEdge = ({
/> />
) : ( ) : (
<EntityPopOverCard <EntityPopOverCard
entityFQN={data.edge.pipeline?.fullyQualifiedName} entityFQN={pipeline?.fullyQualifiedName}
entityType={data.edge.pipeline?.type} entityType={pipelineEntityType}
extraInfo={ extraInfo={
pipelineData && ( pipelineData && (
<Tag className={pipelineClass}> <Tag className={pipelineClass}>
@ -280,15 +265,7 @@ export const CustomEdge = ({
</LineageEdgeIcon> </LineageEdgeIcon>
); );
}, },
[ [edgeCenterX, edgeCenterY, rest, pipeline, blinkingClass, isEditMode]
edgeCenterX,
edgeCenterY,
rest,
data,
pipelineStatus,
blinkingClass,
isEditMode,
]
); );
const getEditLineageIcon = useCallback( const getEditLineageIcon = useCallback(
@ -335,22 +312,6 @@ export const CustomEdge = ({
} }
}, [edge, isColumnLineage, sourceHandle, targetHandle]); }, [edge, isColumnLineage, sourceHandle, targetHandle]);
useEffect(() => {
const wasPipelineAlreadyActive = prevActiveLayer?.includes(
LineageLayerView.PIPELINE
);
const isPipelineActiveNow = activeLayer.includes(LineageLayerView.PIPELINE);
if (
data.edge.pipeline &&
data.edge.pipeline.type === EntityType.PIPELINE &&
!wasPipelineAlreadyActive &&
isPipelineActiveNow
) {
fetchPipelineStatus(data.edge.pipeline.fullyQualifiedName);
}
}, [data.edge.pipeline, activeLayer]);
return ( return (
<Fragment> <Fragment>
<path <path

View File

@ -51,4 +51,5 @@ export interface EdgeDetails {
sqlQuery?: string; sqlQuery?: string;
columns?: ColumnLineage[]; columns?: ColumnLineage[];
description?: string; description?: string;
pipelineEntityType?: EntityType.PIPELINE | EntityType.STORED_PROCEDURE;
} }

View File

@ -31,7 +31,6 @@ import {
} from '../../components/Lineage/Lineage.interface'; } from '../../components/Lineage/Lineage.interface';
import { SourceType } from '../../components/SearchedData/SearchedData.interface'; import { SourceType } from '../../components/SearchedData/SearchedData.interface';
import { EntityType } from '../../enums/entity.enum'; import { EntityType } from '../../enums/entity.enum';
import { PipelineStatus } from '../../generated/entity/data/pipeline';
import { EntityReference } from '../../generated/entity/type'; import { EntityReference } from '../../generated/entity/type';
export interface LineageProviderProps { export interface LineageProviderProps {
@ -70,7 +69,6 @@ export interface LineageContextType {
upstreamDownstreamData: UpstreamDownstreamData; upstreamDownstreamData: UpstreamDownstreamData;
selectedColumn: string; selectedColumn: string;
expandAllColumns: boolean; expandAllColumns: boolean;
pipelineStatus: Record<string, PipelineStatus>;
activeLayer: LineageLayerView[]; activeLayer: LineageLayerView[];
onInitReactFlow: (reactFlowInstance: ReactFlowInstance) => void; onInitReactFlow: (reactFlowInstance: ReactFlowInstance) => void;
onPaneClick: () => void; onPaneClick: () => void;
@ -97,7 +95,6 @@ export interface LineageContextType {
lineageConfig: LineageConfig lineageConfig: LineageConfig
) => void; ) => void;
onExportClick: () => void; onExportClick: () => void;
fetchPipelineStatus: (pipelineFqn: string) => void;
removeNodeHandler: (node: Node | NodeProps) => void; removeNodeHandler: (node: Node | NodeProps) => void;
onColumnEdgeRemove: () => void; onColumnEdgeRemove: () => void;
onAddPipelineClick: () => void; onAddPipelineClick: () => void;

View File

@ -69,7 +69,6 @@ import {
EntityType, EntityType,
} from '../../enums/entity.enum'; } from '../../enums/entity.enum';
import { AddLineage } from '../../generated/api/lineage/addLineage'; import { AddLineage } from '../../generated/api/lineage/addLineage';
import { PipelineStatus } from '../../generated/entity/data/pipeline';
import { import {
ColumnLineage, ColumnLineage,
EntityReference, EntityReference,
@ -81,8 +80,6 @@ import {
getLineageDataByFQN, getLineageDataByFQN,
updateLineageEdge, updateLineageEdge,
} from '../../rest/lineageAPI'; } from '../../rest/lineageAPI';
import { getPipelineStatus } from '../../rest/pipelineAPI';
import { getEpochMillisForPastDays } from '../../utils/date-time/DateTimeUtils';
import { import {
addLineageHandler, addLineageHandler,
createEdges, createEdges,
@ -106,6 +103,7 @@ import {
onLoad, onLoad,
removeLineageHandler, removeLineageHandler,
} from '../../utils/EntityLineageUtils'; } from '../../utils/EntityLineageUtils';
import { getEntityReferenceFromEntity } from '../../utils/EntityUtils';
import { showErrorToast } from '../../utils/ToastUtils'; import { showErrorToast } from '../../utils/ToastUtils';
import { useTourProvider } from '../TourProvider/TourProvider'; import { useTourProvider } from '../TourProvider/TourProvider';
import { import {
@ -172,9 +170,6 @@ const LineageProvider = ({ children }: LineageProviderProps) => {
nodesPerLayer: 50, nodesPerLayer: 50,
}); });
const [queryFilter, setQueryFilter] = useState<string>(''); const [queryFilter, setQueryFilter] = useState<string>('');
const [pipelineStatus, setPipelineStatus] = useState<
Record<string, PipelineStatus>
>({});
const [entityType, setEntityType] = useState(''); const [entityType, setEntityType] = useState('');
const queryParams = new URLSearchParams(location.search); const queryParams = new URLSearchParams(location.search);
const isFullScreen = queryParams.get('fullscreen') === 'true'; const isFullScreen = queryParams.get('fullscreen') === 'true';
@ -364,26 +359,6 @@ const LineageProvider = ({ children }: LineageProviderProps) => {
[nodes, edges, lineageConfig, entityLineage, setEntityLineage, queryFilter] [nodes, edges, lineageConfig, entityLineage, setEntityLineage, queryFilter]
); );
const fetchPipelineStatus = useCallback(async (pipelineFQN: string) => {
try {
const currentTime = Date.now();
// past 1 day
const startDay = getEpochMillisForPastDays(1);
const response = await getPipelineStatus(pipelineFQN, {
startTs: startDay,
endTs: currentTime,
});
setPipelineStatus((prev) => {
return {
...prev,
[pipelineFQN]: response.data[0],
};
});
} catch (error) {
// do not show toast error
}
}, []);
const handleLineageTracing = useCallback( const handleLineageTracing = useCallback(
(selectedNode: Node) => { (selectedNode: Node) => {
const { normalEdge } = getClassifiedEdge(edges); const { normalEdge } = getClassifiedEdge(edges);
@ -837,7 +812,12 @@ const LineageProvider = ({ children }: LineageProviderProps) => {
updatedColumns = getUpdatedColumnsFromEdge(params, currentEdge); updatedColumns = getUpdatedColumnsFromEdge(params, currentEdge);
const lineageDetails: LineageDetails = { const lineageDetails: LineageDetails = {
pipeline: currentEdge.pipeline, pipeline: currentEdge.pipeline
? getEntityReferenceFromEntity(
currentEdge.pipeline,
currentEdge.pipelineEntityType ?? EntityType.PIPELINE
)
: undefined,
columnsLineage: [], columnsLineage: [],
description: currentEdge?.description ?? '', description: currentEdge?.description ?? '',
sqlQuery: currentEdge?.sqlQuery, sqlQuery: currentEdge?.sqlQuery,
@ -871,7 +851,10 @@ const LineageProvider = ({ children }: LineageProviderProps) => {
setEntityLineage((pre) => { setEntityLineage((pre) => {
const newData = { const newData = {
...pre, ...pre,
nodes: uniqWith([pre.entity, ...allNodes], isEqual), nodes: uniqWith(
[...(pre.entity ? [pre.entity] : []), ...allNodes],
isEqual
),
edges: uniqWith(allEdges, isEqual), edges: uniqWith(allEdges, isEqual),
}; };
@ -963,6 +946,9 @@ const LineageProvider = ({ children }: LineageProviderProps) => {
if (pipelineData) { if (pipelineData) {
existingEdge.pipeline = pipelineData; existingEdge.pipeline = pipelineData;
existingEdge.pipelineEntityType = pipelineData.type as
| EntityType.PIPELINE
| EntityType.STORED_PROCEDURE;
} }
} }
@ -1101,9 +1087,13 @@ const LineageProvider = ({ children }: LineageProviderProps) => {
const redrawLineage = useCallback( const redrawLineage = useCallback(
(lineageData: EntityLineageResponse) => { (lineageData: EntityLineageResponse) => {
const allNodes = uniqWith( const allNodes = uniqWith(
[...(lineageData.nodes ?? []), lineageData.entity], [
...(lineageData.nodes ?? []),
...(lineageData.entity ? [lineageData.entity] : []),
],
isEqual isEqual
); );
const updatedNodes = createNodes( const updatedNodes = createNodes(
allNodes, allNodes,
lineageData.edges ?? [], lineageData.edges ?? [],
@ -1215,7 +1205,6 @@ const LineageProvider = ({ children }: LineageProviderProps) => {
tracedNodes, tracedNodes,
tracedColumns, tracedColumns,
expandAllColumns, expandAllColumns,
pipelineStatus,
upstreamDownstreamData, upstreamDownstreamData,
init, init,
activeLayer, activeLayer,
@ -1234,7 +1223,6 @@ const LineageProvider = ({ children }: LineageProviderProps) => {
toggleColumnView, toggleColumnView,
loadChildNodesHandler, loadChildNodesHandler,
fetchLineageData, fetchLineageData,
fetchPipelineStatus,
removeNodeHandler, removeNodeHandler,
onNodeClick, onNodeClick,
onEdgeClick, onEdgeClick,
@ -1262,7 +1250,6 @@ const LineageProvider = ({ children }: LineageProviderProps) => {
tracedNodes, tracedNodes,
tracedColumns, tracedColumns,
expandAllColumns, expandAllColumns,
pipelineStatus,
upstreamDownstreamData, upstreamDownstreamData,
init, init,
activeLayer, activeLayer,
@ -1280,7 +1267,6 @@ const LineageProvider = ({ children }: LineageProviderProps) => {
updateEntityType, updateEntityType,
loadChildNodesHandler, loadChildNodesHandler,
fetchLineageData, fetchLineageData,
fetchPipelineStatus,
toggleColumnView, toggleColumnView,
removeNodeHandler, removeNodeHandler,
onNodeClick, onNodeClick,