Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): Show error message when max pods to view logs are reached #21725

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {DataLoader} from 'argo-ui';
import * as classNames from 'classnames';
import * as React from 'react';
import {useEffect, useState, useRef} from 'react';
import {bufferTime, delay, retryWhen} from 'rxjs/operators';
import {bufferTime, catchError, delay, retryWhen} from 'rxjs/operators';

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

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

const setWithQueryParams = <T extends (val: any) => void>(key: string, cb: T) => {
return (val => {
Expand Down Expand Up @@ -155,9 +157,20 @@ export const PodsLogsViewer = (props: PodLogsProps) => {
sinceSeconds,
filter,
previous
}) // accumulate log changes and render only once every 100ms to reduce CPU usage
.pipe(bufferTime(100))
.pipe(retryWhen(errors => errors.pipe(delay(500))))
})
.pipe(
bufferTime(100),
catchError((error: any) => {
const errorBody = JSON.parse(error.body);
if (errorBody.error && errorBody.error.message) {
if (errorBody.error.message.includes('max pods to view logs are reached')) {
setErrorMessage('Max pods to view logs are reached. Please provide more granular query.');
return EMPTY; // Non-retryable condition, stop the stream and display the error message.
}
}
}),
retryWhen(errors => errors.pipe(delay(500)))
)
.subscribe(log => setLogs(previousLogs => previousLogs.concat(log)));

return () => logsSource.unsubscribe();
Expand Down Expand Up @@ -268,7 +281,11 @@ export const PodsLogsViewer = (props: PodLogsProps) => {
</span>
</div>
<div className={classNames('pod-logs-viewer', {'pod-logs-viewer--inverted': prefs.appDetails.darkMode})} onWheel={handleScroll}>
<AutoSizer>{({width, height}: {width: number; height: number}) => logsContent(width, height, prefs.appDetails.wrapLines, prefs)}</AutoSizer>
{errorMessage ? (
<div>{errorMessage}</div>
) : (
<AutoSizer>{({width, height}: {width: number; height: number}) => logsContent(width, height, prefs.appDetails.wrapLines, prefs)}</AutoSizer>
)}
</div>
</React.Fragment>
);
Expand Down
13 changes: 12 additions & 1 deletion ui/src/app/shared/services/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,18 @@ export default {

loadEventSource(url: string): Observable<string> {
return Observable.create((observer: Observer<any>) => {
let eventSource = new EventSource(`${apiRoot()}${url}`);
const fullUrl = `${apiRoot()}${url}`;

// If there is an error, show it beforehand
fetch(fullUrl).then(response => {
if (!response.ok) {
return response.text().then(text => {
observer.error({status: response.status, statusText: response.statusText, body: text});
});
}
});
Comment on lines +73 to +80
Copy link
Member

Choose a reason for hiding this comment

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

Is the preflight request necessary? Wouldn't the onerror handler take care of this anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@crenshaw-dev The preflight request is needed because the onerror handler does not handle the HTTP request error (400 Bad Request) and swallows the error message.
Instead EventSource considers it a connection problem and throws the generic error('connection got closed unexpectedly')


let eventSource = new EventSource(fullUrl);
eventSource.onmessage = msg => observer.next(msg.data);
eventSource.onerror = e => () => {
observer.error(e);
Expand Down