-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2802 from Gkrumbach07/mlmd-logs-fix
Read pipeline run node details from mlmd context
- Loading branch information
Showing
13 changed files
with
495 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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,7 @@ | ||
import { Context } from '~/third_party/mlmd'; | ||
|
||
export type MlmdContext = Context; | ||
|
||
export enum MlmdContextTypes { | ||
RUN = 'system.PipelineRun', | ||
} |
31 changes: 31 additions & 0 deletions
31
frontend/src/concepts/pipelines/apiHooks/mlmd/useExecutionsFromMlmdContext.ts
This file contains 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,31 @@ | ||
import React from 'react'; | ||
import { MlmdContext } from '~/concepts/pipelines/apiHooks/mlmd/types'; | ||
import { usePipelinesAPI } from '~/concepts/pipelines/context'; | ||
import { Execution, GetExecutionsByContextRequest } from '~/third_party/mlmd'; | ||
import useFetchState, { | ||
FetchState, | ||
FetchStateCallbackPromise, | ||
NotReadyError, | ||
} from '~/utilities/useFetchState'; | ||
|
||
export const useExecutionsFromMlmdContext = ( | ||
context: MlmdContext | null, | ||
refreshRate?: number, | ||
): FetchState<Execution[] | null> => { | ||
const { metadataStoreServiceClient } = usePipelinesAPI(); | ||
|
||
const call = React.useCallback<FetchStateCallbackPromise<Execution[] | null>>(async () => { | ||
if (!context) { | ||
return Promise.reject(new NotReadyError('No context')); | ||
} | ||
|
||
const request = new GetExecutionsByContextRequest(); | ||
request.setContextId(context.getId()); | ||
const res = await metadataStoreServiceClient.getExecutionsByContext(request); | ||
return res.getExecutionsList(); | ||
}, [metadataStoreServiceClient, context]); | ||
|
||
return useFetchState(call, null, { | ||
refreshRate, | ||
}); | ||
}; |
45 changes: 45 additions & 0 deletions
45
frontend/src/concepts/pipelines/apiHooks/mlmd/useMlmdContext.ts
This file contains 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,45 @@ | ||
import React from 'react'; | ||
import { MlmdContext, MlmdContextTypes } from '~/concepts/pipelines/apiHooks/mlmd/types'; | ||
import { usePipelinesAPI } from '~/concepts/pipelines/context'; | ||
import { GetContextByTypeAndNameRequest } from '~/third_party/mlmd'; | ||
import useFetchState, { | ||
FetchState, | ||
FetchStateCallbackPromise, | ||
NotReadyError, | ||
} from '~/utilities/useFetchState'; | ||
|
||
/** | ||
* A hook used to use the MLMD service and fetch the MLMD context | ||
* If being used without name/type, this hook will throw an error | ||
* @param name The identifier to query a specific type of MLMD context. e.g. The runID for a pipeline run | ||
*/ | ||
export const useMlmdContext = ( | ||
name?: string, | ||
type?: MlmdContextTypes, | ||
refreshRate?: number, | ||
): FetchState<MlmdContext | null> => { | ||
const { metadataStoreServiceClient } = usePipelinesAPI(); | ||
|
||
const call = React.useCallback<FetchStateCallbackPromise<MlmdContext | null>>(async () => { | ||
if (!type) { | ||
return Promise.reject(new NotReadyError('No context type')); | ||
} | ||
if (!name) { | ||
return Promise.reject(new NotReadyError('No context name')); | ||
} | ||
|
||
const request = new GetContextByTypeAndNameRequest(); | ||
request.setTypeName(type); | ||
request.setContextName(name); | ||
const res = await metadataStoreServiceClient.getContextByTypeAndName(request); | ||
const context = res.getContext(); | ||
if (!context) { | ||
return Promise.reject(new Error('Cannot find specified context')); | ||
} | ||
return context; | ||
}, [metadataStoreServiceClient, type, name]); | ||
|
||
return useFetchState(call, null, { | ||
refreshRate, | ||
}); | ||
}; |
8 changes: 8 additions & 0 deletions
8
frontend/src/concepts/pipelines/apiHooks/mlmd/usePipelineRunMlmdContext.ts
This file contains 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,8 @@ | ||
import { FetchState } from '~/utilities/useFetchState'; | ||
import { MlmdContext, MlmdContextTypes } from '~/concepts/pipelines/apiHooks/mlmd/types'; | ||
import { useMlmdContext } from '~/concepts/pipelines/apiHooks/mlmd/useMlmdContext'; | ||
|
||
export const usePipelineRunMlmdContext = ( | ||
runID?: string, | ||
refreshRate?: number, | ||
): FetchState<MlmdContext | null> => useMlmdContext(runID, MlmdContextTypes.RUN, refreshRate); |
This file contains 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 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 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
21 changes: 21 additions & 0 deletions
21
...rc/concepts/pipelines/content/pipelinesDetails/pipelineRun/useExecutionsForPipelineRun.ts
This file contains 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,21 @@ | ||
import { useExecutionsFromMlmdContext } from '~/concepts/pipelines/apiHooks/mlmd/useExecutionsFromMlmdContext'; | ||
import { usePipelineRunMlmdContext } from '~/concepts/pipelines/apiHooks/mlmd/usePipelineRunMlmdContext'; | ||
import { isPipelineRunFinished } from '~/concepts/pipelines/apiHooks/usePipelineRunById'; | ||
import { PipelineRunKFv2 } from '~/concepts/pipelines/kfTypes'; | ||
import { Execution } from '~/third_party/mlmd'; | ||
import { FAST_POLL_INTERVAL } from '~/utilities/const'; | ||
|
||
const useExecutionsForPipelineRun = ( | ||
run: PipelineRunKFv2 | null, | ||
): [executions: Execution[] | null, loaded: boolean, error?: Error] => { | ||
const isFinished = isPipelineRunFinished(run); | ||
const refreshRate = isFinished ? 0 : FAST_POLL_INTERVAL; | ||
// contextError means mlmd service is not available, no need to check executions | ||
const [context, , contextError] = usePipelineRunMlmdContext(run?.run_id, refreshRate); | ||
// executionsLoaded is the flag to show the spinner or not | ||
const [executions, executionsLoaded] = useExecutionsFromMlmdContext(context, refreshRate); | ||
|
||
return [executions, executionsLoaded, contextError]; | ||
}; | ||
|
||
export default useExecutionsForPipelineRun; |
This file contains 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
Oops, something went wrong.