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:
parent
4fcac6b0d0
commit
83b8fa9d98
@ -42,12 +42,14 @@ export interface IPodMetrics<T = IMetrics> {
|
||||
networkTransmit: T;
|
||||
}
|
||||
|
||||
// Reference: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/#read-log-pod-v1-core
|
||||
export interface IPodLogsQuery {
|
||||
container?: string;
|
||||
tailLines?: number;
|
||||
timestamps?: boolean;
|
||||
sinceTime?: string; // Date.toISOString()-format
|
||||
follow?: boolean;
|
||||
previous?: boolean;
|
||||
}
|
||||
|
||||
export enum PodStatus {
|
||||
|
||||
@ -50,6 +50,7 @@ export class PodMenu extends React.Component<Props> {
|
||||
initContainers: pod.getInitContainers(),
|
||||
selectedContainer: container,
|
||||
showTimestamps: false,
|
||||
previous: false,
|
||||
tailLines: 1000
|
||||
});
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ export interface IPodLogsData {
|
||||
initContainers: IPodContainer[]
|
||||
showTimestamps: boolean
|
||||
tailLines: number
|
||||
previous: boolean
|
||||
}
|
||||
|
||||
type TabId = string;
|
||||
@ -48,7 +49,7 @@ export class PodLogsStore extends DockTabStore<IPodLogsData> {
|
||||
}
|
||||
const data = this.getData(tabId);
|
||||
const { oldLogs, newLogs } = this.logs.get(tabId);
|
||||
const { selectedContainer, tailLines } = data;
|
||||
const { selectedContainer, tailLines, previous } = data;
|
||||
const pod = new Pod(data.pod);
|
||||
try {
|
||||
// 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(),
|
||||
timestamps: true, // Always setting timestampt to separate old logs from new ones
|
||||
container: selectedContainer.name,
|
||||
tailLines: tailLines,
|
||||
tailLines,
|
||||
previous
|
||||
});
|
||||
if (!oldLogs) {
|
||||
this.logs.set(tabId, { oldLogs: loadedLogs, newLogs });
|
||||
} else {
|
||||
this.logs.set(tabId, { oldLogs, newLogs: loadedLogs });
|
||||
}
|
||||
} catch (error) {
|
||||
} catch ({error}) {
|
||||
this.logs.set(tabId, {
|
||||
oldLogs: [
|
||||
_i18n._(t`Failed to load logs: ${error.message}`),
|
||||
|
||||
@ -94,6 +94,11 @@ export class PodLogs extends React.Component<Props> {
|
||||
this.save({ showTimestamps: !this.tabData.showTimestamps });
|
||||
}
|
||||
|
||||
togglePrevious = () => {
|
||||
this.save({ previous: !this.tabData.previous });
|
||||
this.reload();
|
||||
}
|
||||
|
||||
onScroll = (evt: React.UIEvent<HTMLDivElement>) => {
|
||||
const logsArea = evt.currentTarget;
|
||||
const { scrollHeight, clientHeight, scrollTop } = logsArea;
|
||||
@ -148,7 +153,7 @@ export class PodLogs extends React.Component<Props> {
|
||||
|
||||
renderControls() {
|
||||
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);
|
||||
return (
|
||||
<div className="controls flex gaps align-center">
|
||||
@ -181,6 +186,12 @@ export class PodLogs extends React.Component<Props> {
|
||||
className={cssNames("timestamps-icon", { active: showTimestamps })}
|
||||
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
|
||||
material="get_app"
|
||||
onClick={this.downloadLogs}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user