1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Ability to show previous terminated container logs (#1074)

* Show previous terminated container logs

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Fix for parsing error object

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2020-10-12 15:58:18 +03:00 committed by GitHub
parent 4fcac6b0d0
commit 83b8fa9d98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 4 deletions

View File

@ -42,12 +42,14 @@ export interface IPodMetrics<T = IMetrics> {
networkTransmit: T; networkTransmit: T;
} }
// Reference: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/#read-log-pod-v1-core
export interface IPodLogsQuery { export interface IPodLogsQuery {
container?: string; container?: string;
tailLines?: number; tailLines?: number;
timestamps?: boolean; timestamps?: boolean;
sinceTime?: string; // Date.toISOString()-format sinceTime?: string; // Date.toISOString()-format
follow?: boolean; follow?: boolean;
previous?: boolean;
} }
export enum PodStatus { export enum PodStatus {

View File

@ -50,6 +50,7 @@ export class PodMenu extends React.Component<Props> {
initContainers: pod.getInitContainers(), initContainers: pod.getInitContainers(),
selectedContainer: container, selectedContainer: container,
showTimestamps: false, showTimestamps: false,
previous: false,
tailLines: 1000 tailLines: 1000
}); });
} }

View File

@ -13,6 +13,7 @@ export interface IPodLogsData {
initContainers: IPodContainer[] initContainers: IPodContainer[]
showTimestamps: boolean showTimestamps: boolean
tailLines: number tailLines: number
previous: boolean
} }
type TabId = string; type TabId = string;
@ -48,7 +49,7 @@ export class PodLogsStore extends DockTabStore<IPodLogsData> {
} }
const data = this.getData(tabId); const data = this.getData(tabId);
const { oldLogs, newLogs } = this.logs.get(tabId); const { oldLogs, newLogs } = this.logs.get(tabId);
const { selectedContainer, tailLines } = data; const { selectedContainer, tailLines, previous } = data;
const pod = new Pod(data.pod); const pod = new Pod(data.pod);
try { try {
// if logs already loaded, check the latest timestamp for getting updates only from this point // if logs already loaded, check the latest timestamp for getting updates only from this point
@ -64,14 +65,15 @@ export class PodLogsStore extends DockTabStore<IPodLogsData> {
sinceTime: lastLogDate.toISOString(), sinceTime: lastLogDate.toISOString(),
timestamps: true, // Always setting timestampt to separate old logs from new ones timestamps: true, // Always setting timestampt to separate old logs from new ones
container: selectedContainer.name, container: selectedContainer.name,
tailLines: tailLines, tailLines,
previous
}); });
if (!oldLogs) { if (!oldLogs) {
this.logs.set(tabId, { oldLogs: loadedLogs, newLogs }); this.logs.set(tabId, { oldLogs: loadedLogs, newLogs });
} else { } else {
this.logs.set(tabId, { oldLogs, newLogs: loadedLogs }); this.logs.set(tabId, { oldLogs, newLogs: loadedLogs });
} }
} catch (error) { } catch ({error}) {
this.logs.set(tabId, { this.logs.set(tabId, {
oldLogs: [ oldLogs: [
_i18n._(t`Failed to load logs: ${error.message}`), _i18n._(t`Failed to load logs: ${error.message}`),

View File

@ -94,6 +94,11 @@ export class PodLogs extends React.Component<Props> {
this.save({ showTimestamps: !this.tabData.showTimestamps }); this.save({ showTimestamps: !this.tabData.showTimestamps });
} }
togglePrevious = () => {
this.save({ previous: !this.tabData.previous });
this.reload();
}
onScroll = (evt: React.UIEvent<HTMLDivElement>) => { onScroll = (evt: React.UIEvent<HTMLDivElement>) => {
const logsArea = evt.currentTarget; const logsArea = evt.currentTarget;
const { scrollHeight, clientHeight, scrollTop } = logsArea; const { scrollHeight, clientHeight, scrollTop } = logsArea;
@ -148,7 +153,7 @@ export class PodLogs extends React.Component<Props> {
renderControls() { renderControls() {
if (!this.ready) return null; if (!this.ready) return null;
const { selectedContainer, showTimestamps, tailLines } = this.tabData; const { selectedContainer, showTimestamps, tailLines, previous } = this.tabData;
const timestamps = podLogsStore.getTimestamps(podLogsStore.logs.get(this.tabId).oldLogs); const timestamps = podLogsStore.getTimestamps(podLogsStore.logs.get(this.tabId).oldLogs);
return ( return (
<div className="controls flex gaps align-center"> <div className="controls flex gaps align-center">
@ -181,6 +186,12 @@ export class PodLogs extends React.Component<Props> {
className={cssNames("timestamps-icon", { active: showTimestamps })} className={cssNames("timestamps-icon", { active: showTimestamps })}
tooltip={(showTimestamps ? _i18n._(t`Hide`) : _i18n._(t`Show`)) + " " + _i18n._(t`timestamps`)} tooltip={(showTimestamps ? _i18n._(t`Hide`) : _i18n._(t`Show`)) + " " + _i18n._(t`timestamps`)}
/> />
<Icon
material="undo"
onClick={this.togglePrevious}
className={cssNames("undo-icon", { active: previous })}
tooltip={(previous ? _i18n._(t`Show current logs`) : _i18n._(t`Show previous terminated container logs`))}
/>
<Icon <Icon
material="get_app" material="get_app"
onClick={this.downloadLogs} onClick={this.downloadLogs}