Skip to content

Commit

Permalink
[ui] Move stepStats out of RunRootQuery (#26610)
Browse files Browse the repository at this point in the history
## Summary & Motivation

Move `stepStats` out of the root Run query, since it can be expensive. Instead, query for it at the `RunMetadataProvider`.

This should allow the header, Gantt chart, and logs to load even while the step stats panel of the page continues to load.

## How I Tested These Changes

View a very long-running run. Verify that the Run header, Gantt chart, and logs appear fairly quickly, and the right panel takes a bit longer to load.

## Changelog

[ui] Improve performance of Run page for very long-running runs.
  • Loading branch information
hellendag authored Dec 19, 2024
1 parent 5a4dc5d commit d9ddad4
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.

1 comment on commit d9ddad4

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for dagit-core-storybook ready!

✅ Preview
https://dagit-core-storybook-p6wt3dwg8-elementl.vercel.app

Built with commit d9ddad4.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.