Skip to content

Commit

Permalink
[ui] Move stepStats out of RunRootQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
hellendag committed Dec 19, 2024
1 parent f4ca960 commit 737fa48
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 75 deletions.
5 changes: 3 additions & 2 deletions js_modules/dagster-ui/packages/ui-core/client.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions js_modules/dagster-ui/packages/ui-core/src/runs/RunFragments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,6 @@ export const RUN_FRAGMENT = gql`
}
stepKeysToExecute
updateTime
stepStats {
stepKey
status
startTime
endTime
attempts {
startTime
endTime
}
markers {
startTime
endTime
}
}
...RunTimingFragment
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import * as React from 'react';
import {useMemo} from 'react';

import {LogsProviderLogs} from './LogsProvider';
import {RunContext} from './RunContext';
import {gql} from '../apollo-client';
import {gql, useQuery} from '../apollo-client';
import {flattenOneLevel} from '../util/flattenOneLevel';
import {RunFragment} from './types/RunFragments.types';
import {RunMetadataProviderMessageFragment} from './types/RunMetadataProvider.types';
import {
RunMetadataProviderMessageFragment,
RunStepStatsFragment,
RunStepStatsQuery,
RunStepStatsQueryVariables,
} from './types/RunMetadataProvider.types';
import {StepEventStatus} from '../graphql/types';
import {METADATA_ENTRY_FRAGMENT} from '../metadata/MetadataEntryFragment';

Expand Down Expand Up @@ -103,13 +109,17 @@ export const extractLogCaptureStepsFromLegacySteps = (stepKeys: string[]) => {

const fromTimestamp = (ts: number | null) => (ts ? Math.floor(ts * 1000) : undefined);

function extractMetadataFromRun(run?: RunFragment): IRunMetadataDict {
function extractMetadataFromRun(
run: RunFragment | null = null,
stepStats: RunStepStatsFragment['stepStats'] = [],
): IRunMetadataDict {
const metadata: IRunMetadataDict = {
firstLogAt: 0,
mostRecentLogAt: 0,
globalMarkers: [],
steps: {},
};

if (!run) {
return metadata;
}
Expand All @@ -120,7 +130,7 @@ function extractMetadataFromRun(run?: RunFragment): IRunMetadataDict {
metadata.exitedAt = fromTimestamp(run.endTime);
}

run.stepStats.forEach((stepStat) => {
stepStats.forEach((stepStat) => {
metadata.steps[stepStat.stepKey] = {
// state:
// current state
Expand Down Expand Up @@ -370,7 +380,18 @@ interface IRunMetadataProviderProps {

export const RunMetadataProvider = ({logs, children}: IRunMetadataProviderProps) => {
const run = React.useContext(RunContext);
const runMetadata = React.useMemo(() => extractMetadataFromRun(run), [run]);

// Step stats can be expensive to load, so we separate them from the main run query.
const {data} = useQuery<RunStepStatsQuery, RunStepStatsQueryVariables>(RUN_STEP_STATS_QUERY, {
variables: run ? {runId: run.id} : undefined,
skip: !run,
});

const stepStats = useMemo(() => {
return data?.pipelineRunOrError.__typename === 'Run' ? data.pipelineRunOrError.stepStats : [];
}, [data]);

const runMetadata = React.useMemo(() => extractMetadataFromRun(run, stepStats), [run, stepStats]);
const metadata = React.useMemo(
() =>
logs.loading ? runMetadata : extractMetadataFromLogs(flattenOneLevel(logs.allNodeChunks)),
Expand All @@ -379,6 +400,35 @@ export const RunMetadataProvider = ({logs, children}: IRunMetadataProviderProps)
return <>{children(metadata)}</>;
};

const RUN_STEP_STATS_QUERY = gql`
query RunStepStatsQuery($runId: ID!) {
pipelineRunOrError(runId: $runId) {
... on Run {
id
...RunStepStatsFragment
}
}
}
fragment RunStepStatsFragment on Run {
id
stepStats {
stepKey
status
startTime
endTime
attempts {
startTime
endTime
}
markers {
startTime
endTime
}
}
}
`;

export const RUN_METADATA_PROVIDER_MESSAGE_FRAGMENT = gql`
fragment RunMetadataProviderMessageFragment on DagsterRunEvent {
... on MessageEvent {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 737fa48

Please sign in to comment.