Skip to content

Commit 7c8f2df

Browse files
committed
After 500 logs we stop live reloading on the run page
1 parent fd44dab commit 7c8f2df

File tree

3 files changed

+60
-19
lines changed

3 files changed

+60
-19
lines changed

apps/webapp/app/hooks/useEventSource.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function useEventSource(
2626
const eventSource = new EventSource(url, init);
2727
eventSource.addEventListener(event ?? "message", handler);
2828

29-
// rest data if dependencies change
29+
// reset data if dependencies change
3030
setData(null);
3131

3232
function handler(event: MessageEvent) {

apps/webapp/app/presenters/v3/RunStreamPresenter.server.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,24 @@ export class RunStreamPresenter {
9494

9595
eventEmitter.removeAllListeners();
9696

97-
unsubscribe().catch((error) => {
98-
logger.error("RunStreamPresenter.abort.unsubscribe", {
99-
runFriendlyId,
100-
traceId: run.traceId,
101-
error: {
102-
name: error.name,
103-
message: error.message,
104-
stack: error.stack,
105-
},
97+
unsubscribe()
98+
.then(() => {
99+
logger.info("RunStreamPresenter.abort.unsubscribe succeeded", {
100+
runFriendlyId,
101+
traceId: run.traceId,
102+
});
103+
})
104+
.catch((error) => {
105+
logger.error("RunStreamPresenter.abort.unsubscribe failed", {
106+
runFriendlyId,
107+
traceId: run.traceId,
108+
error: {
109+
name: error.name,
110+
message: error.message,
111+
stack: error.stack,
112+
},
113+
});
106114
});
107-
});
108115
};
109116
});
110117
}

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.v3.$projectParam.runs.$runParam/route.tsx

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
BoltSlashIcon,
23
ChevronDownIcon,
34
ChevronRightIcon,
45
MagnifyingGlassMinusIcon,
@@ -69,6 +70,9 @@ import {
6970
import { SpanView } from "../resources.orgs.$organizationSlug.projects.v3.$projectParam.runs.$runParam.spans.$spanParam/route";
7071
import { AdminDebugTooltip } from "~/components/admin/debugTooltip";
7172
import { Property, PropertyTable } from "~/components/primitives/PropertyTable";
73+
import { SimpleTooltip } from "~/components/primitives/Tooltip";
74+
75+
const MAX_LIVE_RELOADING_EVENTS = 500;
7276

7377
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
7478
const userId = await requireUserId(request);
@@ -167,6 +171,7 @@ export default function Page() {
167171
}
168172

169173
const { events, parentRunFriendlyId, duration, rootSpanStatus, rootStartedAt } = trace;
174+
const shouldLiveReload = events.length <= MAX_LIVE_RELOADING_EVENTS;
170175

171176
const changeToSpan = useDebounce((selectedSpan: string) => {
172177
replaceSearchParam("span", selectedSpan);
@@ -175,6 +180,7 @@ export default function Page() {
175180
const revalidator = useRevalidator();
176181
const streamedEvents = useEventSource(v3RunStreamingPath(organization, project, run), {
177182
event: "message",
183+
disabled: !shouldLiveReload,
178184
});
179185
useEffect(() => {
180186
if (streamedEvents !== null) {
@@ -254,6 +260,7 @@ export default function Page() {
254260
rootSpanStatus={rootSpanStatus}
255261
rootStartedAt={rootStartedAt}
256262
environmentType={run.environment.type}
263+
shouldLiveReload={shouldLiveReload}
257264
/>
258265
</ResizablePanel>
259266
<ResizableHandle withHandle />
@@ -282,6 +289,7 @@ type TasksTreeViewProps = {
282289
rootSpanStatus: "executing" | "completed" | "failed";
283290
rootStartedAt: Date | undefined;
284291
environmentType: RuntimeEnvironmentType;
292+
shouldLiveReload: boolean;
285293
};
286294

287295
function TasksTreeView({
@@ -293,6 +301,7 @@ function TasksTreeView({
293301
rootSpanStatus,
294302
rootStartedAt,
295303
environmentType,
304+
shouldLiveReload,
296305
}: TasksTreeViewProps) {
297306
const [filterText, setFilterText] = useState("");
298307
const [errorsOnly, setErrorsOnly] = useState(false);
@@ -367,7 +376,10 @@ function TasksTreeView({
367376
This is the root task
368377
</Paragraph>
369378
)}
370-
<LiveReloadingStatus rootSpanCompleted={rootSpanStatus !== "executing"} />
379+
<LiveReloadingStatus
380+
rootSpanCompleted={rootSpanStatus !== "executing"}
381+
isLiveReloading={shouldLiveReload}
382+
/>
371383
</div>
372384
<TreeView
373385
parentRef={parentRef}
@@ -834,16 +846,38 @@ function ShowParentLink({ runFriendlyId }: { runFriendlyId: string }) {
834846
);
835847
}
836848

837-
function LiveReloadingStatus({ rootSpanCompleted }: { rootSpanCompleted: boolean }) {
849+
function LiveReloadingStatus({
850+
rootSpanCompleted,
851+
isLiveReloading,
852+
}: {
853+
rootSpanCompleted: boolean;
854+
isLiveReloading: boolean;
855+
}) {
838856
if (rootSpanCompleted) return null;
839857

840858
return (
841-
<div className="flex items-center gap-1">
842-
<PulsingDot />
843-
<Paragraph variant="extra-small" className="whitespace-nowrap text-blue-500">
844-
Live reloading
845-
</Paragraph>
846-
</div>
859+
<>
860+
{isLiveReloading ? (
861+
<div className="flex items-center gap-1">
862+
<PulsingDot />
863+
<Paragraph variant="extra-small" className="whitespace-nowrap text-blue-500">
864+
Live reloading
865+
</Paragraph>
866+
</div>
867+
) : (
868+
<SimpleTooltip
869+
content={`Live reloading is disabled because you've exceeded ${MAX_LIVE_RELOADING_EVENTS} logs.`}
870+
button={
871+
<div className="flex items-center gap-1">
872+
<BoltSlashIcon className="size-3.5 text-text-dimmed" />
873+
<Paragraph variant="extra-small" className="whitespace-nowrap text-text-dimmed">
874+
Live reloading disabled
875+
</Paragraph>
876+
</div>
877+
}
878+
></SimpleTooltip>
879+
)}
880+
</>
847881
);
848882
}
849883

0 commit comments

Comments
 (0)