mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Merge branch 'master' into back-to-catalog-button
This commit is contained in:
commit
d88cf3bc51
104 files changed
+1353
-1484
No files matched your search
@@ -27,7 +27,7 @@ import type { KubeJsonApiData } from "../kube-json-api";
|
||||
|
||||
export class IngressApi extends KubeApi<Ingress> {
|
||||
getMetrics(ingress: string, namespace: string): Promise<IIngressMetrics> {
|
||||
const opts = { category: "ingress", ingress };
|
||||
const opts = { category: "ingress", ingress, namespace };
|
||||
|
||||
return metricsApi.getMetrics({
|
||||
bytesSentSuccess: opts,
|
||||
|
||||
@@ -46,6 +46,12 @@ export interface IMetricsResult {
|
||||
values: [number, string][];
|
||||
}
|
||||
|
||||
export interface MetricProviderInfo {
|
||||
name: string;
|
||||
id: string;
|
||||
isConfigurable: boolean;
|
||||
}
|
||||
|
||||
export interface IMetricsReqParams {
|
||||
start?: number | string; // timestamp in seconds or valid date-string
|
||||
end?: number | string;
|
||||
@@ -75,6 +81,10 @@ export const metricsApi = {
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
async getMetricProviders(): Promise<MetricProviderInfo[]> {
|
||||
return apiBase.get("/metrics/providers");
|
||||
}
|
||||
};
|
||||
|
||||
export function normalizeMetrics(metrics: IMetrics, frames = 60): IMetrics {
|
||||
|
||||
@@ -52,39 +52,56 @@ export interface INodeMetrics<T = IMetrics> {
|
||||
|
||||
export interface Node {
|
||||
spec: {
|
||||
podCIDR: string;
|
||||
externalID: string;
|
||||
podCIDR?: string;
|
||||
podCIDRs?: string[];
|
||||
providerID?: string;
|
||||
/**
|
||||
* @deprecated see https://issues.k8s.io/61966
|
||||
*/
|
||||
externalID?: string;
|
||||
taints?: {
|
||||
key: string;
|
||||
value: string;
|
||||
effect: string;
|
||||
timeAdded: string;
|
||||
}[];
|
||||
unschedulable?: boolean;
|
||||
};
|
||||
status: {
|
||||
capacity: {
|
||||
capacity?: {
|
||||
cpu: string;
|
||||
["ephemeral-storage"]: string;
|
||||
["hugepages-1Gi"]: string;
|
||||
["hugepages-2Mi"]: string;
|
||||
memory: string;
|
||||
pods: string;
|
||||
};
|
||||
allocatable: {
|
||||
allocatable?: {
|
||||
cpu: string;
|
||||
["ephemeral-storage"]: string;
|
||||
["hugepages-1Gi"]: string;
|
||||
["hugepages-2Mi"]: string;
|
||||
memory: string;
|
||||
pods: string;
|
||||
};
|
||||
conditions: {
|
||||
conditions?: {
|
||||
type: string;
|
||||
status?: string;
|
||||
status: string;
|
||||
lastHeartbeatTime?: string;
|
||||
lastTransitionTime?: string;
|
||||
reason?: string;
|
||||
message?: string;
|
||||
}[];
|
||||
addresses: {
|
||||
addresses?: {
|
||||
type: string;
|
||||
address: string;
|
||||
}[];
|
||||
nodeInfo: {
|
||||
daemonEndpoints?: {
|
||||
kubeletEndpoint: {
|
||||
Port: number; //it must be uppercase for backwards compatibility
|
||||
}
|
||||
}
|
||||
nodeInfo?: {
|
||||
machineID: string;
|
||||
systemUUID: string;
|
||||
bootID: string;
|
||||
@@ -96,9 +113,14 @@ export interface Node {
|
||||
operatingSystem: string;
|
||||
architecture: string;
|
||||
};
|
||||
images: {
|
||||
images?: {
|
||||
names: string[];
|
||||
sizeBytes: number;
|
||||
sizeBytes?: number;
|
||||
}[];
|
||||
volumesInUse?: string[];
|
||||
volumesAttached?: {
|
||||
name: string;
|
||||
devicePath: string;
|
||||
}[];
|
||||
};
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ import type { KubeJsonApiData } from "../kube-json-api";
|
||||
export class PersistentVolumeClaimsApi extends KubeApi<PersistentVolumeClaim> {
|
||||
getMetrics(pvcName: string, namespace: string): Promise<IPvcMetrics> {
|
||||
return metricsApi.getMetrics({
|
||||
diskUsage: { category: "pvc", pvc: pvcName },
|
||||
diskCapacity: { category: "pvc", pvc: pvcName }
|
||||
diskUsage: { category: "pvc", pvc: pvcName, namespace },
|
||||
diskCapacity: { category: "pvc", pvc: pvcName, namespace }
|
||||
}, {
|
||||
namespace
|
||||
});
|
||||
|
||||
@@ -26,7 +26,7 @@ import * as Mobx from "mobx";
|
||||
import * as MobxReact from "mobx-react";
|
||||
import * as ReactRouter from "react-router";
|
||||
import * as ReactRouterDom from "react-router-dom";
|
||||
import * as LensExtensionsCoreApi from "../extensions/core-api";
|
||||
import * as LensExtensionsCommonApi from "../extensions/common-api";
|
||||
import * as LensExtensionsRendererApi from "../extensions/renderer-api";
|
||||
import { render, unmountComponentAtNode } from "react-dom";
|
||||
import { delay } from "../common/utils";
|
||||
@@ -123,8 +123,8 @@ bootstrap(process.isMainFrame ? LensApp : App);
|
||||
* e.g. Devtools -> Console -> window.LensExtensions (renderer)
|
||||
*/
|
||||
const LensExtensions = {
|
||||
...LensExtensionsCoreApi,
|
||||
...LensExtensionsRendererApi,
|
||||
Common: LensExtensionsCommonApi,
|
||||
Renderer: LensExtensionsRendererApi,
|
||||
};
|
||||
|
||||
export {
|
||||
|
||||
@@ -46,6 +46,7 @@ enum columnId {
|
||||
count = "count",
|
||||
source = "source",
|
||||
age = "age",
|
||||
lastSeen = "last-seen",
|
||||
}
|
||||
|
||||
interface Props extends Partial<KubeObjectListLayoutProps> {
|
||||
@@ -61,6 +62,7 @@ const defaultProps: Partial<Props> = {
|
||||
@observer
|
||||
export class Events extends React.Component<Props> {
|
||||
static defaultProps = defaultProps as object;
|
||||
now = Date.now();
|
||||
|
||||
@observable sorting: TableSortParams = {
|
||||
sortBy: columnId.age,
|
||||
@@ -73,6 +75,7 @@ export class Events extends React.Component<Props> {
|
||||
[columnId.object]: (event: KubeEvent) => event.involvedObject.name,
|
||||
[columnId.count]: (event: KubeEvent) => event.count,
|
||||
[columnId.age]: (event: KubeEvent) => event.getTimeDiffFromNow(),
|
||||
[columnId.lastSeen]: (event: KubeEvent) => this.now - new Date(event.lastTimestamp).getTime(),
|
||||
};
|
||||
|
||||
private tableConfiguration: TableProps = {
|
||||
@@ -168,7 +171,8 @@ export class Events extends React.Component<Props> {
|
||||
{ title: "Involved Object", className: "object", sortBy: columnId.object, id: columnId.object },
|
||||
{ title: "Source", className: "source", id: columnId.source },
|
||||
{ title: "Count", className: "count", sortBy: columnId.count, id: columnId.count },
|
||||
{ title: "Last Seen", className: "age", sortBy: columnId.age, id: columnId.age },
|
||||
{ title: "Age", className: "age", sortBy: columnId.age, id: columnId.age },
|
||||
{ title: "Last Seen", className: "last-seen", sortBy: columnId.lastSeen, id: columnId.lastSeen },
|
||||
]}
|
||||
renderTableContents={(event: KubeEvent) => {
|
||||
const { involvedObject, type, message } = event;
|
||||
@@ -195,6 +199,7 @@ export class Events extends React.Component<Props> {
|
||||
event.getSource(),
|
||||
event.count,
|
||||
event.getAge(),
|
||||
event.getLastSeenTime(),
|
||||
];
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
.icon {
|
||||
@apply h-5 w-5 mr-3 cursor-pointer;
|
||||
background-color: transparent!important;
|
||||
}
|
||||
|
||||
.icon:hover {
|
||||
|
||||
@@ -29,6 +29,7 @@ import { SubTitle } from "../layout/sub-title";
|
||||
import { TooltipPosition } from "../tooltip";
|
||||
import { ExtensionInstallationStateStore } from "./extension-install.store";
|
||||
import { observer } from "mobx-react";
|
||||
import { MaterialTooltip } from "../material-tooltip/material-tooltip";
|
||||
|
||||
interface Props {
|
||||
installPath: string;
|
||||
@@ -70,13 +71,13 @@ export const Install = observer((props: Props) => {
|
||||
onChange={onChange}
|
||||
onSubmit={installFromInput}
|
||||
iconRight={
|
||||
<Icon
|
||||
interactive={false}
|
||||
className={styles.icon}
|
||||
material="folder_open"
|
||||
onClick={prevDefault(installFromSelectFileDialog)}
|
||||
tooltip="Browse"
|
||||
/>
|
||||
<MaterialTooltip title="Browse">
|
||||
<Icon
|
||||
className={styles.icon}
|
||||
material="folder_open"
|
||||
onClick={prevDefault(installFromSelectFileDialog)}
|
||||
/>
|
||||
</MaterialTooltip>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
.NodeDetailsResources {
|
||||
.Table {
|
||||
margin: 0 (-$margin * 3);
|
||||
}
|
||||
|
||||
.TableCell {
|
||||
&:first-child {
|
||||
margin-left: $margin;
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
margin-right: $margin;
|
||||
}
|
||||
|
||||
&.pods {
|
||||
flex-grow: 0.5;
|
||||
}
|
||||
|
||||
&.memory {
|
||||
flex-grow: 0.5;
|
||||
}
|
||||
|
||||
&.cpu {
|
||||
flex-grow:0.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import "./node-details-resources.scss";
|
||||
|
||||
import { Table } from "../table/table";
|
||||
import { TableHead } from "../table/table-head";
|
||||
import { TableRow } from "../table/table-row";
|
||||
import React from "react";
|
||||
import type { Node } from "../../api/endpoints";
|
||||
import { TableCell } from "../table/table-cell";
|
||||
|
||||
interface Props {
|
||||
node: Node;
|
||||
type: "allocatable" | "capacity";
|
||||
}
|
||||
|
||||
export class NodeDetailsResources extends React.Component<Props> {
|
||||
toMi(resource: string) {
|
||||
if (resource.endsWith("Ki")) {
|
||||
return `${(parseInt(resource) / 1024).toFixed(1)}Mi`;
|
||||
}
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
render() {
|
||||
const status = this.props.node.status;
|
||||
const type = this.props.type;
|
||||
|
||||
if (!status) return null;
|
||||
|
||||
return (
|
||||
<div className="NodeDetailsResources flex column">
|
||||
<Table
|
||||
selectable
|
||||
scrollable={false}
|
||||
>
|
||||
<TableHead>
|
||||
<TableCell className="cpu">CPU</TableCell>
|
||||
<TableCell className="memory">Memory</TableCell>
|
||||
<TableCell className="ephemeral-storage">Ephemeral Storage</TableCell>
|
||||
<TableCell className="hugepages-1Gi">Hugepages-1Gi</TableCell>
|
||||
<TableCell className="hugepages-2Mi">Hugepages-2Mi</TableCell>
|
||||
<TableCell className="pods">Pods</TableCell>
|
||||
</TableHead>
|
||||
<TableRow>
|
||||
<TableCell className="cpu">{status[type].cpu}</TableCell>
|
||||
<TableCell className="memory">{this.toMi(status[type].memory)}</TableCell>
|
||||
<TableCell
|
||||
className="ephemeral-storage">{this.toMi(status[type]["ephemeral-storage"])}</TableCell>
|
||||
<TableCell className="hugepages-1Gi">{status[type]["hugepages-1Gi"]}</TableCell>
|
||||
<TableCell className="hugepages-2Mi">{status[type]["hugepages-2Mi"]}</TableCell>
|
||||
<TableCell className="pods">{status[type].pods}</TableCell>
|
||||
</TableRow>
|
||||
</Table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,8 @@ import { KubeEventDetails } from "../+events/kube-event-details";
|
||||
import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry";
|
||||
import { ResourceType } from "../cluster-settings/components/cluster-metrics-setting";
|
||||
import { ClusterStore } from "../../../common/cluster-store";
|
||||
import { NodeDetailsResources } from "./node-details-resources";
|
||||
import { DrawerTitle } from "../drawer/drawer-title";
|
||||
|
||||
interface Props extends KubeObjectDetailsProps<Node> {
|
||||
}
|
||||
@@ -64,7 +66,7 @@ export class NodeDetails extends React.Component<Props> {
|
||||
|
||||
if (!node) return null;
|
||||
const { status } = node;
|
||||
const { nodeInfo, addresses, capacity, allocatable } = status;
|
||||
const { nodeInfo, addresses } = status;
|
||||
const conditions = node.getActiveConditions();
|
||||
const taints = node.getTaints();
|
||||
const childPods = podsStore.getPodsByNode(node.getName());
|
||||
@@ -88,16 +90,6 @@ export class NodeDetails extends React.Component<Props> {
|
||||
</ResourceMetrics>
|
||||
)}
|
||||
<KubeObjectMeta object={node} hideFields={["labels", "annotations", "uid", "resourceVersion", "selfLink"]}/>
|
||||
<DrawerItem name="Capacity">
|
||||
CPU: {capacity.cpu},{" "}
|
||||
Memory: {Math.floor(parseInt(capacity.memory) / 1024)}Mi,{" "}
|
||||
Pods: {capacity.pods}
|
||||
</DrawerItem>
|
||||
<DrawerItem name="Allocatable">
|
||||
CPU: {allocatable.cpu},{" "}
|
||||
Memory: {Math.floor(parseInt(allocatable.memory) / 1024)}Mi,{" "}
|
||||
Pods: {allocatable.pods}
|
||||
</DrawerItem>
|
||||
{addresses &&
|
||||
<DrawerItem name="Addresses">
|
||||
{
|
||||
@@ -167,6 +159,10 @@ export class NodeDetails extends React.Component<Props> {
|
||||
}
|
||||
</DrawerItem>
|
||||
}
|
||||
<DrawerTitle title="Capacity"/>
|
||||
<NodeDetailsResources node={node} type={"capacity"}/>
|
||||
<DrawerTitle title="Allocatable"/>
|
||||
<NodeDetailsResources node={node} type={"allocatable"}/>
|
||||
<PodDetailsList
|
||||
pods={childPods}
|
||||
owner={node}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
import "./nodes.scss";
|
||||
import React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import type { RouteComponentProps } from "react-router";
|
||||
import { cssNames, interval } from "../../utils";
|
||||
import { TabLayout } from "../layout/tab-layout";
|
||||
@@ -37,6 +37,8 @@ import kebabCase from "lodash/kebabCase";
|
||||
import upperFirst from "lodash/upperFirst";
|
||||
import { KubeObjectStatusIcon } from "../kube-object-status-icon";
|
||||
import { Badge } from "../badge/badge";
|
||||
import { kubeWatchApi } from "../../api/kube-watch-api";
|
||||
import { eventStore } from "../+events/event.store";
|
||||
|
||||
enum columnId {
|
||||
name = "name",
|
||||
@@ -60,6 +62,11 @@ export class Nodes extends React.Component<Props> {
|
||||
|
||||
componentDidMount() {
|
||||
this.metricsWatcher.start(true);
|
||||
disposeOnUnmount(this, [
|
||||
kubeWatchApi.subscribeStores([nodesStore, podsStore, eventStore], {
|
||||
preload: true,
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
|
||||
+42
-19
@@ -21,18 +21,14 @@
|
||||
|
||||
import React from "react";
|
||||
import { observer, disposeOnUnmount } from "mobx-react";
|
||||
import { prometheusProviders } from "../../../../common/prometheus-providers";
|
||||
import type { Cluster } from "../../../../main/cluster";
|
||||
import { SubTitle } from "../../layout/sub-title";
|
||||
import { Select, SelectOption } from "../../select";
|
||||
import { Input } from "../../input";
|
||||
import { observable, computed, autorun, makeObservable } from "mobx";
|
||||
import { productName } from "../../../../common/vars";
|
||||
|
||||
const options: SelectOption<string>[] = [
|
||||
{ value: "", label: "Auto detect" },
|
||||
...prometheusProviders.map(pp => ({value: pp.id, label: pp.name}))
|
||||
];
|
||||
import { MetricProviderInfo, metricsApi } from "../../../api/endpoints/metrics.api";
|
||||
import { Spinner } from "../../spinner";
|
||||
|
||||
interface Props {
|
||||
cluster: Cluster;
|
||||
@@ -42,16 +38,27 @@ interface Props {
|
||||
export class ClusterPrometheusSetting extends React.Component<Props> {
|
||||
@observable path = "";
|
||||
@observable provider = "";
|
||||
@observable loading = true;
|
||||
@observable loadedOptions: MetricProviderInfo[] = [];
|
||||
|
||||
@computed get options(): SelectOption<string>[] {
|
||||
return [
|
||||
{ value: "", label: "Auto detect" },
|
||||
...this.loadedOptions.map(({ name, id }) => ({ value: id, label: name }))
|
||||
];
|
||||
}
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
makeObservable(this);
|
||||
}
|
||||
|
||||
@computed get canEditPrometheusPath() {
|
||||
if (this.provider === "" || this.provider === "lens") return false;
|
||||
|
||||
return true;
|
||||
@computed get canEditPrometheusPath(): boolean {
|
||||
return Boolean(
|
||||
this.loadedOptions
|
||||
.find(opt => opt.id === this.provider)
|
||||
?.isConfigurable
|
||||
);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
@@ -74,6 +81,16 @@ export class ClusterPrometheusSetting extends React.Component<Props> {
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
metricsApi
|
||||
.getMetricProviders()
|
||||
.then(values => {
|
||||
this.loading = false;
|
||||
|
||||
if (values) {
|
||||
this.loadedOptions = values;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
parsePrometheusPath = () => {
|
||||
@@ -110,15 +127,21 @@ export class ClusterPrometheusSetting extends React.Component<Props> {
|
||||
<>
|
||||
<section>
|
||||
<SubTitle title="Prometheus"/>
|
||||
<Select
|
||||
value={this.provider}
|
||||
onChange={({value}) => {
|
||||
this.provider = value;
|
||||
this.onSaveProvider();
|
||||
}}
|
||||
options={options}
|
||||
/>
|
||||
<small className="hint">What query format is used to fetch metrics from Prometheus</small>
|
||||
{
|
||||
this.loading
|
||||
? <Spinner />
|
||||
: <>
|
||||
<Select
|
||||
value={this.provider}
|
||||
onChange={({ value }) => {
|
||||
this.provider = value;
|
||||
this.onSaveProvider();
|
||||
}}
|
||||
options={this.options}
|
||||
/>
|
||||
<small className="hint">What query format is used to fetch metrics from Prometheus</small>
|
||||
</>
|
||||
}
|
||||
</section>
|
||||
{this.canEditPrometheusPath && (
|
||||
<section>
|
||||
|
||||
@@ -55,6 +55,20 @@ export class LogStore {
|
||||
}, { delay: 500 });
|
||||
}
|
||||
|
||||
handlerError(tabId: TabId, error: any): void {
|
||||
if (error.error && !(error.message || error.reason || error.code)) {
|
||||
error = error.error;
|
||||
}
|
||||
|
||||
const message = [
|
||||
`Failed to load logs: ${error.message}`,
|
||||
`Reason: ${error.reason} (${error.code})`
|
||||
];
|
||||
|
||||
this.refresher.stop();
|
||||
this.podLogs.set(tabId, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function prepares tailLines param for passing to API request
|
||||
* Each time it increasing it's number, caused to fetch more logs.
|
||||
@@ -70,14 +84,8 @@ export class LogStore {
|
||||
|
||||
this.refresher.start();
|
||||
this.podLogs.set(tabId, logs);
|
||||
} catch ({error}) {
|
||||
const message = [
|
||||
`Failed to load logs: ${error.message}`,
|
||||
`Reason: ${error.reason} (${error.code})`
|
||||
];
|
||||
|
||||
this.refresher.stop();
|
||||
this.podLogs.set(tabId, message);
|
||||
} catch (error) {
|
||||
this.handlerError(tabId, error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -88,14 +96,21 @@ export class LogStore {
|
||||
* @param tabId
|
||||
*/
|
||||
loadMore = async (tabId: TabId) => {
|
||||
if (!this.podLogs.get(tabId).length) return;
|
||||
const oldLogs = this.podLogs.get(tabId);
|
||||
const logs = await this.loadLogs(tabId, {
|
||||
sinceTime: this.getLastSinceTime(tabId)
|
||||
});
|
||||
if (!this.podLogs.get(tabId).length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add newly received logs to bottom
|
||||
this.podLogs.set(tabId, [...oldLogs, ...logs]);
|
||||
try {
|
||||
const oldLogs = this.podLogs.get(tabId);
|
||||
const logs = await this.loadLogs(tabId, {
|
||||
sinceTime: this.getLastSinceTime(tabId)
|
||||
});
|
||||
|
||||
// Add newly received logs to bottom
|
||||
this.podLogs.set(tabId, [...oldLogs, ...logs]);
|
||||
} catch (error) {
|
||||
this.handlerError(tabId, error);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -103,45 +118,39 @@ export class LogStore {
|
||||
* an API request
|
||||
* @param tabId
|
||||
* @param params request parameters described in IPodLogsQuery interface
|
||||
* @returns {Promise} A fetch request promise
|
||||
* @returns A fetch request promise
|
||||
*/
|
||||
loadLogs = async (tabId: TabId, params: Partial<IPodLogsQuery>) => {
|
||||
async loadLogs(tabId: TabId, params: Partial<IPodLogsQuery>): Promise<string[]> {
|
||||
const data = logTabStore.getData(tabId);
|
||||
const { selectedContainer, previous } = data;
|
||||
const pod = new Pod(data.selectedPod);
|
||||
const namespace = pod.getNs();
|
||||
const name = pod.getName();
|
||||
|
||||
return podsApi.getLogs({ namespace, name }, {
|
||||
const result = await podsApi.getLogs({ namespace, name }, {
|
||||
...params,
|
||||
timestamps: true, // Always setting timestamp to separate old logs from new ones
|
||||
container: selectedContainer.name,
|
||||
previous
|
||||
}).then(result => {
|
||||
const logs = [...result.split("\n")]; // Transform them into array
|
||||
|
||||
logs.pop(); // Remove last empty element
|
||||
|
||||
return logs;
|
||||
});
|
||||
};
|
||||
|
||||
return result.trimEnd().split("\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts logs into a string array
|
||||
* @returns {number} Length of log lines
|
||||
* @returns Length of log lines
|
||||
*/
|
||||
@computed
|
||||
get lines() {
|
||||
const id = dockStore.selectedTabId;
|
||||
const logs = this.podLogs.get(id);
|
||||
|
||||
return logs ? logs.length : 0;
|
||||
get lines(): number {
|
||||
return this.logs.length;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns logs with timestamps for selected tab
|
||||
*/
|
||||
@computed
|
||||
get logs() {
|
||||
return this.podLogs.get(dockStore.selectedTabId) ?? [];
|
||||
}
|
||||
@@ -150,6 +159,7 @@ export class LogStore {
|
||||
* Removes timestamps from each log line and returns changed logs
|
||||
* @returns Logs without timestamps
|
||||
*/
|
||||
@computed
|
||||
get logsWithoutTimestamps() {
|
||||
return this.logs.map(item => this.removeTimestamps(item));
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import type { CatalogEntityContextMenu } from "../../../common/catalog";
|
||||
import { cssNames, IClassName } from "../../utils";
|
||||
import { ConfirmDialog } from "../confirm-dialog";
|
||||
import { Menu, MenuItem } from "../menu";
|
||||
import { MaterialTooltip } from "../+catalog/material-tooltip/material-tooltip";
|
||||
import { MaterialTooltip } from "../material-tooltip/material-tooltip";
|
||||
import { observer } from "mobx-react";
|
||||
import { Avatar } from "../avatar/avatar";
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import { Hotbar, HotbarStore } from "../../../common/hotbar-store";
|
||||
import { CommandOverlay } from "../command-palette";
|
||||
import { HotbarSwitchCommand } from "./hotbar-switch-command";
|
||||
import { hotbarDisplayIndex } from "./hotbar-display-label";
|
||||
import { MaterialTooltip } from "../+catalog/material-tooltip/material-tooltip";
|
||||
import { MaterialTooltip } from "../material-tooltip/material-tooltip";
|
||||
|
||||
interface Props {
|
||||
hotbar: Hotbar;
|
||||
|
||||
File renamed without changes.
@@ -20,17 +20,20 @@
|
||||
*/
|
||||
|
||||
import type { LocationDescriptor } from "history";
|
||||
import { createPath } from "history";
|
||||
import { matchPath, RouteProps } from "react-router";
|
||||
import { PageParam, PageParamInit } from "./page-param";
|
||||
import { clusterViewRoute, IClusterViewRouteParams } from "../components/cluster-manager/cluster-view.route";
|
||||
import { navigation } from "./history";
|
||||
|
||||
export function navigate(location: LocationDescriptor) {
|
||||
const currentLocation = navigation.location.pathname;
|
||||
const currentLocation = createPath(navigation.location);
|
||||
|
||||
navigation.push(location);
|
||||
|
||||
if (currentLocation === navigation.location.pathname) {
|
||||
const newLocation = createPath(navigation.location);
|
||||
|
||||
if (currentLocation === newLocation) {
|
||||
navigation.goBack(); // prevent sequences of same url in history
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user