Skip to content

Commit

Permalink
fix: upgrade argo-ui version (fixes stuck logs viewer); properly retr…
Browse files Browse the repository at this point in the history
…y loading logs if network connection broke (argoproj#5615)

Signed-off-by: Alexander Matyushentsev <[email protected]>
  • Loading branch information
Alexander Matyushentsev authored Feb 25, 2021
1 parent 7ad79e5 commit 7433a99
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 30 deletions.
2 changes: 1 addition & 1 deletion server/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ func (s *Server) PodLogs(q *application.ApplicationPodLogsQuery, ws application.
return ws.Send(&application.LogEntry{Last: true})
}
if entry.err != nil {
return err
return entry.err
} else {
if q.Filter != nil {
lineContainsFilter := strings.Contains(entry.line, literal)
Expand Down
4 changes: 4 additions & 0 deletions server/application/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func parseLogsStream(podName string, stream io.ReadCloser, ch chan logEntry) {
line, err := bufReader.ReadString('\n')
if err == io.EOF {
eof = true
// stop if we reached end of stream and the next line is empty
if line == "" {
break
}
} else if err != nil && err != io.EOF {
ch <- logEntry{err: err}
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,32 +160,39 @@ export const PodsLogsViewer = (props: PodLogsProps & {fullscreen?: boolean}) =>
)}
input={props.containerName}
load={() => {
return (
services.applications
.getContainerLogs(
props.applicationName,
props.namespace,
props.podName,
{group: props.group, kind: props.kind, name: props.name},
props.containerName,
maxLines * (page.number + 1),
prefs.appDetails.followLogs && page.number === 0,
page.untilTimes[page.untilTimes.length - 1],
filterQuery()
)
// show only current page lines
.scan((lines, logEntry) => {
let logsSource = services.applications
.getContainerLogs(
props.applicationName,
props.namespace,
props.podName,
{group: props.group, kind: props.kind, name: props.name},
props.containerName,
maxLines * (page.number + 1),
prefs.appDetails.followLogs && page.number === 0,
page.untilTimes[page.untilTimes.length - 1],
filterQuery()
)
// show only current page lines
.scan((lines, logEntry) => {
// first equal true means retry attempt so we should clear accumulated log entries
if (logEntry.first) {
lines = [logEntry];
} else {
lines.push(logEntry);
if (lines.length > maxLines) {
lines.splice(0, lines.length - maxLines);
}
return lines;
}, new Array<models.LogEntry>())
// accumulate log changes and render only once every 100ms to reduce CPU usage
.bufferTime(100)
.filter(batch => batch.length > 0)
.map(batch => batch[batch.length - 1])
);
}
if (lines.length > maxLines) {
lines.splice(0, lines.length - maxLines);
}
return lines;
}, new Array<models.LogEntry>())
// accumulate log changes and render only once every 100ms to reduce CPU usage
.bufferTime(100)
.filter(batch => batch.length > 0)
.map(batch => batch[batch.length - 1]);
if (prefs.appDetails.followLogs) {
logsSource = logsSource.repeat().retryWhen(errors => errors.delay(500));
}
return logsSource;
}}>
{logs => {
logs = logs || [];
Expand Down
2 changes: 2 additions & 0 deletions ui/src/app/shared/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ export interface AppProjectStatus {
export interface LogEntry {
content: string;
timeStamp: models.Time;
// first field is inferred on the fly and indicats first log line received from backend
first?: boolean;
last: boolean;
timeStampStr: string;
podName: string;
Expand Down
14 changes: 11 additions & 3 deletions ui/src/app/shared/services/applications-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,26 @@ export class ApplicationsService {
search.set('filter', filter);
}
const entries = requests.loadEventSource(`/applications/${applicationName}/logs?${search.toString()}`).map(data => JSON.parse(data).result as models.LogEntry);
let first = true;
return new Observable(observer => {
const subscription = entries.subscribe(
entry => {
if (entry.last) {
observer.complete();
subscription.unsubscribe();
} else {
observer.next(entry);
observer.next({...entry, first});
first = false;
}
},
err => observer.error(err),
() => observer.complete()
err => {
first = true;
observer.error(err);
},
() => {
first = true;
observer.complete();
}
);
return () => subscription.unsubscribe();
});
Expand Down
2 changes: 1 addition & 1 deletion ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1824,7 +1824,7 @@ are-we-there-yet@~1.1.2:

"argo-ui@https://github.com/argoproj/argo-ui.git":
version "1.0.0"
resolved "https://github.com/argoproj/argo-ui.git#a7404f5ab9654b6c941c655759fb6556cb7fe676"
resolved "https://github.com/argoproj/argo-ui.git#967c28a377aeef4861b2b97ccf6693d64abef725"
dependencies:
"@fortawesome/fontawesome-free" "^5.8.1"
"@tippy.js/react" "^2.1.2"
Expand Down

0 comments on commit 7433a99

Please sign in to comment.