Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1f0dd19

Browse files
committedFeb 1, 2025··
Catch max pod render error and display it
Signed-off-by: Peter Jiang <peterjiang823@gmail.com>
1 parent 85c6d26 commit 1f0dd19

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed
 

‎ui/src/app/applications/components/pod-logs-viewer/pod-logs-viewer.tsx

+22-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {DataLoader} from 'argo-ui';
22
import * as classNames from 'classnames';
33
import * as React from 'react';
44
import {useEffect, useState, useRef} from 'react';
5-
import {bufferTime, delay, retryWhen} from 'rxjs/operators';
5+
import {bufferTime, catchError, delay, retryWhen} from 'rxjs/operators';
66

77
import {LogEntry} from '../../../shared/models';
88
import {services, ViewPreferences} from '../../../shared/services';
@@ -27,6 +27,7 @@ import {PodNamesToggleButton} from './pod-names-toggle-button';
2727
import {AutoScrollButton} from './auto-scroll-button';
2828
import {WrapLinesButton} from './wrap-lines-button';
2929
import Ansi from 'ansi-to-react';
30+
import {EMPTY} from 'rxjs';
3031

3132
export interface PodLogsProps {
3233
namespace: string;
@@ -95,6 +96,7 @@ export const PodsLogsViewer = (props: PodLogsProps) => {
9596
const [logs, setLogs] = useState<LogEntry[]>([]);
9697
const logsContainerRef = useRef(null);
9798
const uniquePods = Array.from(new Set(logs.map(log => log.podName)));
99+
const [errorMessage, setErrorMessage] = useState<string | null>(null);
98100

99101
const setWithQueryParams = <T extends (val: any) => void>(key: string, cb: T) => {
100102
return (val => {
@@ -155,9 +157,20 @@ export const PodsLogsViewer = (props: PodLogsProps) => {
155157
sinceSeconds,
156158
filter,
157159
previous
158-
}) // accumulate log changes and render only once every 100ms to reduce CPU usage
159-
.pipe(bufferTime(100))
160-
.pipe(retryWhen(errors => errors.pipe(delay(500))))
160+
})
161+
.pipe(
162+
bufferTime(100),
163+
catchError((error: any) => {
164+
const errorBody = JSON.parse(error.body);
165+
if (errorBody.error && errorBody.error.message) {
166+
if (errorBody.error.message.includes('max pods to view logs are reached')) {
167+
setErrorMessage('Max pods to view logs are reached. Please provide more granular query.');
168+
return EMPTY; // Non-retryable condition, stop the stream and display the error message.
169+
}
170+
}
171+
}),
172+
retryWhen(errors => errors.pipe(delay(500)))
173+
)
161174
.subscribe(log => setLogs(previousLogs => previousLogs.concat(log)));
162175

163176
return () => logsSource.unsubscribe();
@@ -268,7 +281,11 @@ export const PodsLogsViewer = (props: PodLogsProps) => {
268281
</span>
269282
</div>
270283
<div className={classNames('pod-logs-viewer', {'pod-logs-viewer--inverted': prefs.appDetails.darkMode})} onWheel={handleScroll}>
271-
<AutoSizer>{({width, height}: {width: number; height: number}) => logsContent(width, height, prefs.appDetails.wrapLines, prefs)}</AutoSizer>
284+
{errorMessage ? (
285+
<div>{errorMessage}</div>
286+
) : (
287+
<AutoSizer>{({width, height}: {width: number; height: number}) => logsContent(width, height, prefs.appDetails.wrapLines, prefs)}</AutoSizer>
288+
)}
272289
</div>
273290
</React.Fragment>
274291
);

‎ui/src/app/shared/services/requests.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,18 @@ export default {
6868

6969
loadEventSource(url: string): Observable<string> {
7070
return Observable.create((observer: Observer<any>) => {
71-
let eventSource = new EventSource(`${apiRoot()}${url}`);
71+
const fullUrl = `${apiRoot()}${url}`;
72+
73+
// If there is an error, show it beforehand
74+
fetch(fullUrl).then(response => {
75+
if (!response.ok) {
76+
return response.text().then(text => {
77+
observer.error({status: response.status, statusText: response.statusText, body: text});
78+
});
79+
}
80+
});
81+
82+
let eventSource = new EventSource(fullUrl);
7283
eventSource.onmessage = msg => observer.next(msg.data);
7384
eventSource.onerror = e => () => {
7485
observer.error(e);

0 commit comments

Comments
 (0)
Please sign in to comment.