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

Cleaning up

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2021-07-19 15:07:52 +03:00
parent 6c09bae93e
commit 524635c329
9 changed files with 20 additions and 29 deletions

View File

@ -26,30 +26,6 @@ import { KubeApi } from "../kube-api";
export class ClusterApi extends KubeApi<Cluster> {
static kind = "Cluster";
static namespaced = true;
async getMetrics(nodeNames: string[], params?: IMetricsReqParams): Promise<IClusterMetrics> {
const nodes = nodeNames.join("|");
const opts = { category: "cluster", nodes };
return metricsApi.getMetrics({
memoryUsage: opts,
workloadMemoryUsage: opts,
memoryRequests: opts,
memoryLimits: opts,
memoryCapacity: opts,
memoryAllocatableCapacity: opts,
cpuUsage: opts,
cpuRequests: opts,
cpuLimits: opts,
cpuCapacity: opts,
cpuAllocatableCapacity: opts,
podUsage: opts,
podCapacity: opts,
podAllocatableCapacity: opts,
fsSize: opts,
fsUsage: opts
}, params);
}
}
export function getMetricsByNodeNames(nodeNames: string[], params?: IMetricsReqParams): Promise<IClusterMetrics> {
@ -58,15 +34,19 @@ export function getMetricsByNodeNames(nodeNames: string[], params?: IMetricsReqP
return metricsApi.getMetrics({
memoryUsage: opts,
workloadMemoryUsage: opts,
memoryRequests: opts,
memoryLimits: opts,
memoryCapacity: opts,
memoryAllocatableCapacity: opts,
cpuUsage: opts,
cpuRequests: opts,
cpuLimits: opts,
cpuCapacity: opts,
cpuAllocatableCapacity: opts,
podUsage: opts,
podCapacity: opts,
podAllocatableCapacity: opts,
fsSize: opts,
fsUsage: opts
}, params);

View File

@ -21,7 +21,7 @@
import { action, observable, reaction, when, makeObservable } from "mobx";
import { KubeObjectStore } from "../../kube-object.store";
import { Cluster, clusterApi, IClusterMetrics } from "../../api/endpoints";
import { Cluster, clusterApi, getMetricsByNodeNames, IClusterMetrics } from "../../api/endpoints";
import { autoBind, createStorage } from "../../utils";
import { IMetricsReqParams, normalizeMetrics } from "../../api/endpoints/metrics.api";
import { nodesStore } from "../+nodes/nodes.store";
@ -101,7 +101,7 @@ export class ClusterOverviewStore extends KubeObjectStore<Cluster> implements Cl
const { masterNodes, workerNodes } = nodesStore;
const nodes = this.metricNodeRole === MetricNodeRole.MASTER && masterNodes.length ? masterNodes : workerNodes;
this.metrics = await clusterApi.getMetrics(nodes.map(node => node.getName()), params);
this.metrics = await getMetricsByNodeNames(nodes.map(node => node.getName()), params);
this.metricsLoaded = true;
}

View File

@ -32,13 +32,14 @@ import { podsStore } from "../+workloads-pods/pods.store";
import type { KubeObjectDetailsProps } from "../kube-object";
import { getMetricsByNodeNames, IClusterMetrics, Node } from "../../api/endpoints";
import { NodeCharts } from "./node-charts";
import { action, observable, reaction } from "mobx";
import { observable, reaction } from "mobx";
import { PodDetailsList } from "../+workloads-pods/pod-details-list";
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
import { ClusterMetricsResourceType } from "../../../main/cluster";
import { NodeDetailsResources } from "./node-details-resources";
import { DrawerTitle } from "../drawer/drawer-title";
import { boundMethod } from "../../utils";
interface Props extends KubeObjectDetailsProps<Node> {
}
@ -56,7 +57,7 @@ export class NodeDetails extends React.Component<Props> {
podsStore.reloadAll();
}
@action
@boundMethod
async loadMetrics() {
const { object: node } = this.props;

View File

@ -61,7 +61,7 @@ interface Props extends RouteComponentProps<NodesRouteParams> {
@observer
export class Nodes extends React.Component<Props> {
@observable metrics: Partial<INodeMetrics> = {};
private metricsWatcher = interval(30, async () => await getMetricsForAllNodes());
private metricsWatcher = interval(30, async () => this.metrics = await getMetricsForAllNodes());
componentDidMount() {
this.metricsWatcher.start(true);

View File

@ -39,6 +39,7 @@ import { PodDetailsList } from "../+workloads-pods/pod-details-list";
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
import { ClusterMetricsResourceType } from "../../../main/cluster";
import { boundMethod } from "../../utils";
interface Props extends KubeObjectDetailsProps<DaemonSet> {
}
@ -56,6 +57,7 @@ export class DaemonSetDetails extends React.Component<Props> {
podsStore.reloadAll();
}
@boundMethod
async loadMetrics() {
const { object: daemonSet } = this.props;

View File

@ -41,6 +41,7 @@ import { replicaSetStore } from "../+workloads-replicasets/replicasets.store";
import { DeploymentReplicaSets } from "./deployment-replicasets";
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
import { ClusterMetricsResourceType } from "../../../main/cluster";
import { boundMethod } from "../../utils";
interface Props extends KubeObjectDetailsProps<Deployment> {
}
@ -59,6 +60,7 @@ export class DeploymentDetails extends React.Component<Props> {
replicaSetStore.reloadAll();
}
@boundMethod
async loadMetrics() {
const { object: deployment } = this.props;

View File

@ -42,6 +42,7 @@ import { podMetricTabs, PodCharts } from "../+workloads-pods/pod-charts";
import { ClusterMetricsResourceType } from "../../../main/cluster";
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
import { ResourceMetrics } from "../resource-metrics";
import { boundMethod } from "autobind-decorator";
interface Props extends KubeObjectDetailsProps<Job> {
}
@ -54,6 +55,7 @@ export class JobDetails extends React.Component<Props> {
podsStore.reloadAll();
}
@boundMethod
async loadMetrics() {
const { object: job } = this.props;

View File

@ -38,6 +38,7 @@ import { PodDetailsList } from "../+workloads-pods/pod-details-list";
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
import { ClusterMetricsResourceType } from "../../../main/cluster";
import { boundMethod } from "../../utils";
interface Props extends KubeObjectDetailsProps<ReplicaSet> {
}
@ -55,6 +56,7 @@ export class ReplicaSetDetails extends React.Component<Props> {
podsStore.reloadAll();
}
@boundMethod
async loadMetrics() {
const { object: replicaSet } = this.props;

View File

@ -39,6 +39,7 @@ import { PodDetailsList } from "../+workloads-pods/pod-details-list";
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
import { ClusterMetricsResourceType } from "../../../main/cluster";
import { boundMethod } from "../../utils";
interface Props extends KubeObjectDetailsProps<StatefulSet> {
}
@ -56,6 +57,7 @@ export class StatefulSetDetails extends React.Component<Props> {
podsStore.reloadAll();
}
@boundMethod
async loadMetrics() {
const { object: statefulSet } = this.props;