mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Extracting metrics out of stores
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
1d09251a70
commit
3772c82542
@ -27,13 +27,12 @@ import kebabCase from "lodash/kebabCase";
|
|||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { DrawerItem, DrawerItemLabels } from "../drawer";
|
import { DrawerItem, DrawerItemLabels } from "../drawer";
|
||||||
import { Badge } from "../badge";
|
import { Badge } from "../badge";
|
||||||
import { nodesStore } from "./nodes.store";
|
|
||||||
import { ResourceMetrics } from "../resource-metrics";
|
import { ResourceMetrics } from "../resource-metrics";
|
||||||
import { podsStore } from "../+workloads-pods/pods.store";
|
import { podsStore } from "../+workloads-pods/pods.store";
|
||||||
import type { KubeObjectDetailsProps } from "../kube-object";
|
import type { KubeObjectDetailsProps } from "../kube-object";
|
||||||
import type { Node } from "../../api/endpoints";
|
import { getMetricsByNodeNames, IClusterMetrics, Node } from "../../api/endpoints";
|
||||||
import { NodeCharts } from "./node-charts";
|
import { NodeCharts } from "./node-charts";
|
||||||
import { reaction } from "mobx";
|
import { action, observable, reaction } from "mobx";
|
||||||
import { PodDetailsList } from "../+workloads-pods/pod-details-list";
|
import { PodDetailsList } from "../+workloads-pods/pod-details-list";
|
||||||
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
|
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
|
||||||
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
||||||
@ -46,17 +45,22 @@ interface Props extends KubeObjectDetailsProps<Node> {
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class NodeDetails extends React.Component<Props> {
|
export class NodeDetails extends React.Component<Props> {
|
||||||
|
@observable metrics: Partial<IClusterMetrics>;
|
||||||
|
|
||||||
@disposeOnUnmount
|
@disposeOnUnmount
|
||||||
clean = reaction(() => this.props.object.getName(), () => {
|
clean = reaction(() => this.props.object.getName(), () => {
|
||||||
nodesStore.nodeMetrics = null;
|
this.metrics = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
podsStore.reloadAll();
|
podsStore.reloadAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
@action
|
||||||
nodesStore.nodeMetrics = null;
|
async loadMetrics() {
|
||||||
|
const { object: node } = this.props;
|
||||||
|
|
||||||
|
this.metrics = await getMetricsByNodeNames([node.getName()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -68,7 +72,7 @@ export class NodeDetails extends React.Component<Props> {
|
|||||||
const conditions = node.getActiveConditions();
|
const conditions = node.getActiveConditions();
|
||||||
const taints = node.getTaints();
|
const taints = node.getTaints();
|
||||||
const childPods = podsStore.getPodsByNode(node.getName());
|
const childPods = podsStore.getPodsByNode(node.getName());
|
||||||
const metrics = nodesStore.nodeMetrics;
|
const { metrics } = this;
|
||||||
const metricTabs = [
|
const metricTabs = [
|
||||||
"CPU",
|
"CPU",
|
||||||
"Memory",
|
"Memory",
|
||||||
@ -81,7 +85,7 @@ export class NodeDetails extends React.Component<Props> {
|
|||||||
<div className="NodeDetails">
|
<div className="NodeDetails">
|
||||||
{!isMetricHidden && podsStore.isLoaded && (
|
{!isMetricHidden && podsStore.isLoaded && (
|
||||||
<ResourceMetrics
|
<ResourceMetrics
|
||||||
loader={() => nodesStore.loadMetrics(node.getName())}
|
loader={this.loadMetrics}
|
||||||
tabs={metricTabs} object={node} params={{ metrics }}
|
tabs={metricTabs} object={node} params={{ metrics }}
|
||||||
>
|
>
|
||||||
<NodeCharts/>
|
<NodeCharts/>
|
||||||
|
|||||||
@ -18,22 +18,17 @@
|
|||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* 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.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { sum } from "lodash";
|
import { sum } from "lodash";
|
||||||
import { action, computed, observable, makeObservable } from "mobx";
|
import { computed, makeObservable } from "mobx";
|
||||||
import { clusterApi, IClusterMetrics, INodeMetrics, Node, nodesApi } from "../../api/endpoints";
|
|
||||||
import { autoBind } from "../../utils";
|
|
||||||
import { KubeObjectStore } from "../../kube-object.store";
|
|
||||||
import { apiManager } from "../../api/api-manager";
|
import { apiManager } from "../../api/api-manager";
|
||||||
|
import { Node, nodesApi } from "../../api/endpoints";
|
||||||
|
import { KubeObjectStore } from "../../kube-object.store";
|
||||||
|
import { autoBind } from "../../utils";
|
||||||
|
|
||||||
export class NodesStore extends KubeObjectStore<Node> {
|
export class NodesStore extends KubeObjectStore<Node> {
|
||||||
api = nodesApi;
|
api = nodesApi;
|
||||||
|
|
||||||
@observable metrics: Partial<INodeMetrics> = {};
|
|
||||||
@observable nodeMetrics: Partial<IClusterMetrics> = null;
|
|
||||||
@observable metricsLoading = false;
|
|
||||||
@observable metricsLoaded = false;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@ -41,23 +36,6 @@ export class NodesStore extends KubeObjectStore<Node> {
|
|||||||
autoBind(this);
|
autoBind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
|
||||||
async loadUsageMetrics() {
|
|
||||||
this.metricsLoading = true;
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.metrics = await nodesApi.getMetrics();
|
|
||||||
this.metricsLoaded = true;
|
|
||||||
} finally {
|
|
||||||
this.metricsLoading = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
|
||||||
async loadMetrics(nodeName: string) {
|
|
||||||
this.nodeMetrics = await clusterApi.getMetrics([nodeName]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@computed get masterNodes() {
|
@computed get masterNodes() {
|
||||||
return this.items.filter(node => node.getRoleLabels().includes("master"));
|
return this.items.filter(node => node.getRoleLabels().includes("master"));
|
||||||
}
|
}
|
||||||
@ -66,41 +44,9 @@ export class NodesStore extends KubeObjectStore<Node> {
|
|||||||
return this.items.filter(node => !node.getRoleLabels().includes("master"));
|
return this.items.filter(node => !node.getRoleLabels().includes("master"));
|
||||||
}
|
}
|
||||||
|
|
||||||
getLastMetricValues(node: Node, metricNames: string[]): number[] {
|
|
||||||
if (!this.metricsLoaded) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
const nodeName = node.getName();
|
|
||||||
|
|
||||||
return metricNames.map(metricName => {
|
|
||||||
try {
|
|
||||||
const metric = this.metrics[metricName];
|
|
||||||
const result = metric.data.result.find(result => {
|
|
||||||
return [
|
|
||||||
result.metric.node,
|
|
||||||
result.metric.instance,
|
|
||||||
result.metric.kubernetes_node,
|
|
||||||
].includes(nodeName);
|
|
||||||
});
|
|
||||||
|
|
||||||
return result ? parseFloat(result.values.slice(-1)[0][1]) : 0;
|
|
||||||
} catch (e) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
getWarningsCount(): number {
|
getWarningsCount(): number {
|
||||||
return sum(this.items.map((node: Node) => node.getWarningConditions().length));
|
return sum(this.items.map((node: Node) => node.getWarningConditions().length));
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
|
||||||
super.reset();
|
|
||||||
this.metrics = {};
|
|
||||||
this.nodeMetrics = null;
|
|
||||||
this.metricsLoading = false;
|
|
||||||
this.metricsLoaded = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const nodesStore = new NodesStore();
|
export const nodesStore = new NodesStore();
|
||||||
|
|||||||
@ -28,7 +28,7 @@ import { TabLayout } from "../layout/tab-layout";
|
|||||||
import { nodesStore } from "./nodes.store";
|
import { nodesStore } from "./nodes.store";
|
||||||
import { podsStore } from "../+workloads-pods/pods.store";
|
import { podsStore } from "../+workloads-pods/pods.store";
|
||||||
import { KubeObjectListLayout } from "../kube-object";
|
import { KubeObjectListLayout } from "../kube-object";
|
||||||
import type { Node } from "../../api/endpoints/nodes.api";
|
import { getMetricsForAllNodes, INodeMetrics, Node } from "../../api/endpoints/nodes.api";
|
||||||
import { LineProgress } from "../line-progress";
|
import { LineProgress } from "../line-progress";
|
||||||
import { bytesToUnits } from "../../utils/convertMemory";
|
import { bytesToUnits } from "../../utils/convertMemory";
|
||||||
import { Tooltip, TooltipPosition } from "../tooltip";
|
import { Tooltip, TooltipPosition } from "../tooltip";
|
||||||
@ -39,6 +39,8 @@ import { Badge } from "../badge/badge";
|
|||||||
import { kubeWatchApi } from "../../api/kube-watch-api";
|
import { kubeWatchApi } from "../../api/kube-watch-api";
|
||||||
import { eventStore } from "../+events/event.store";
|
import { eventStore } from "../+events/event.store";
|
||||||
import type { NodesRouteParams } from "../../../common/routes";
|
import type { NodesRouteParams } from "../../../common/routes";
|
||||||
|
import { observable } from "mobx";
|
||||||
|
import isEmpty from "lodash/isEmpty";
|
||||||
|
|
||||||
enum columnId {
|
enum columnId {
|
||||||
name = "name",
|
name = "name",
|
||||||
@ -58,7 +60,8 @@ interface Props extends RouteComponentProps<NodesRouteParams> {
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class Nodes extends React.Component<Props> {
|
export class Nodes extends React.Component<Props> {
|
||||||
private metricsWatcher = interval(30, () => nodesStore.loadUsageMetrics());
|
@observable metrics: Partial<INodeMetrics> = {};
|
||||||
|
private metricsWatcher = interval(30, async () => await getMetricsForAllNodes());
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.metricsWatcher.start(true);
|
this.metricsWatcher.start(true);
|
||||||
@ -73,8 +76,32 @@ export class Nodes extends React.Component<Props> {
|
|||||||
this.metricsWatcher.stop();
|
this.metricsWatcher.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLastMetricValues(node: Node, metricNames: string[]): number[] {
|
||||||
|
if (isEmpty(this.metrics)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const nodeName = node.getName();
|
||||||
|
|
||||||
|
return metricNames.map(metricName => {
|
||||||
|
try {
|
||||||
|
const metric = this.metrics[metricName];
|
||||||
|
const result = metric.data.result.find(result => {
|
||||||
|
return [
|
||||||
|
result.metric.node,
|
||||||
|
result.metric.instance,
|
||||||
|
result.metric.kubernetes_node,
|
||||||
|
].includes(nodeName);
|
||||||
|
});
|
||||||
|
|
||||||
|
return result ? parseFloat(result.values.slice(-1)[0][1]) : 0;
|
||||||
|
} catch (e) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
renderCpuUsage(node: Node) {
|
renderCpuUsage(node: Node) {
|
||||||
const metrics = nodesStore.getLastMetricValues(node, ["cpuUsage", "cpuCapacity"]);
|
const metrics = this.getLastMetricValues(node, ["cpuUsage", "cpuCapacity"]);
|
||||||
|
|
||||||
if (!metrics || !metrics[1]) return <LineProgress value={0}/>;
|
if (!metrics || !metrics[1]) return <LineProgress value={0}/>;
|
||||||
const usage = metrics[0];
|
const usage = metrics[0];
|
||||||
@ -97,7 +124,7 @@ export class Nodes extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderMemoryUsage(node: Node) {
|
renderMemoryUsage(node: Node) {
|
||||||
const metrics = nodesStore.getLastMetricValues(node, ["workloadMemoryUsage", "memoryAllocatableCapacity"]);
|
const metrics = this.getLastMetricValues(node, ["workloadMemoryUsage", "memoryAllocatableCapacity"]);
|
||||||
|
|
||||||
if (!metrics || !metrics[1]) return <LineProgress value={0}/>;
|
if (!metrics || !metrics[1]) return <LineProgress value={0}/>;
|
||||||
const usage = metrics[0];
|
const usage = metrics[0];
|
||||||
@ -116,7 +143,7 @@ export class Nodes extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderDiskUsage(node: Node): any {
|
renderDiskUsage(node: Node): any {
|
||||||
const metrics = nodesStore.getLastMetricValues(node, ["fsUsage", "fsSize"]);
|
const metrics = this.getLastMetricValues(node, ["fsUsage", "fsSize"]);
|
||||||
|
|
||||||
if (!metrics || !metrics[1]) return <LineProgress value={0}/>;
|
if (!metrics || !metrics[1]) return <LineProgress value={0}/>;
|
||||||
const usage = metrics[0];
|
const usage = metrics[0];
|
||||||
@ -172,9 +199,9 @@ export class Nodes extends React.Component<Props> {
|
|||||||
isSelectable={false}
|
isSelectable={false}
|
||||||
sortingCallbacks={{
|
sortingCallbacks={{
|
||||||
[columnId.name]: (node: Node) => node.getName(),
|
[columnId.name]: (node: Node) => node.getName(),
|
||||||
[columnId.cpu]: (node: Node) => nodesStore.getLastMetricValues(node, ["cpuUsage"]),
|
[columnId.cpu]: (node: Node) => this.getLastMetricValues(node, ["cpuUsage"]),
|
||||||
[columnId.memory]: (node: Node) => nodesStore.getLastMetricValues(node, ["memoryUsage"]),
|
[columnId.memory]: (node: Node) => this.getLastMetricValues(node, ["memoryUsage"]),
|
||||||
[columnId.disk]: (node: Node) => nodesStore.getLastMetricValues(node, ["fsUsage"]),
|
[columnId.disk]: (node: Node) => this.getLastMetricValues(node, ["fsUsage"]),
|
||||||
[columnId.conditions]: (node: Node) => node.getNodeConditionText(),
|
[columnId.conditions]: (node: Node) => node.getNodeConditionText(),
|
||||||
[columnId.taints]: (node: Node) => node.getTaints().length,
|
[columnId.taints]: (node: Node) => node.getTaints().length,
|
||||||
[columnId.roles]: (node: Node) => node.getRoleLabels(),
|
[columnId.roles]: (node: Node) => node.getRoleLabels(),
|
||||||
|
|||||||
@ -22,17 +22,16 @@
|
|||||||
import "./volume-claim-details.scss";
|
import "./volume-claim-details.scss";
|
||||||
|
|
||||||
import React, { Fragment } from "react";
|
import React, { Fragment } from "react";
|
||||||
import { reaction } from "mobx";
|
import { action, observable, reaction } from "mobx";
|
||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { DrawerItem, DrawerTitle } from "../drawer";
|
import { DrawerItem, DrawerTitle } from "../drawer";
|
||||||
import { Badge } from "../badge";
|
import { Badge } from "../badge";
|
||||||
import { podsStore } from "../+workloads-pods/pods.store";
|
import { podsStore } from "../+workloads-pods/pods.store";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { volumeClaimStore } from "./volume-claim.store";
|
|
||||||
import { ResourceMetrics } from "../resource-metrics";
|
import { ResourceMetrics } from "../resource-metrics";
|
||||||
import { VolumeClaimDiskChart } from "./volume-claim-disk-chart";
|
import { VolumeClaimDiskChart } from "./volume-claim-disk-chart";
|
||||||
import { getDetailsUrl, KubeObjectDetailsProps, KubeObjectMeta } from "../kube-object";
|
import { getDetailsUrl, KubeObjectDetailsProps, KubeObjectMeta } from "../kube-object";
|
||||||
import type { PersistentVolumeClaim } from "../../api/endpoints";
|
import { getMetricsForPvc, IPvcMetrics, PersistentVolumeClaim } from "../../api/endpoints";
|
||||||
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
||||||
import { ClusterMetricsResourceType } from "../../../main/cluster";
|
import { ClusterMetricsResourceType } from "../../../main/cluster";
|
||||||
|
|
||||||
@ -41,13 +40,18 @@ interface Props extends KubeObjectDetailsProps<PersistentVolumeClaim> {
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class PersistentVolumeClaimDetails extends React.Component<Props> {
|
export class PersistentVolumeClaimDetails extends React.Component<Props> {
|
||||||
|
@observable metrics: IPvcMetrics = null;
|
||||||
|
|
||||||
@disposeOnUnmount
|
@disposeOnUnmount
|
||||||
clean = reaction(() => this.props.object, () => {
|
clean = reaction(() => this.props.object, () => {
|
||||||
volumeClaimStore.reset();
|
this.metrics = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
componentWillUnmount() {
|
@action
|
||||||
volumeClaimStore.reset();
|
async loadMetrics() {
|
||||||
|
const { object: volumeClaim } = this.props;
|
||||||
|
|
||||||
|
this.metrics = await getMetricsForPvc(volumeClaim);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -57,7 +61,7 @@ export class PersistentVolumeClaimDetails extends React.Component<Props> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const { storageClassName, accessModes } = volumeClaim.spec;
|
const { storageClassName, accessModes } = volumeClaim.spec;
|
||||||
const { metrics } = volumeClaimStore;
|
const { metrics } = this;
|
||||||
const pods = volumeClaim.getPods(podsStore.items);
|
const pods = volumeClaim.getPods(podsStore.items);
|
||||||
const metricTabs = [
|
const metricTabs = [
|
||||||
"Disk"
|
"Disk"
|
||||||
@ -68,7 +72,7 @@ export class PersistentVolumeClaimDetails extends React.Component<Props> {
|
|||||||
<div className="PersistentVolumeClaimDetails">
|
<div className="PersistentVolumeClaimDetails">
|
||||||
{!isMetricHidden && (
|
{!isMetricHidden && (
|
||||||
<ResourceMetrics
|
<ResourceMetrics
|
||||||
loader={() => volumeClaimStore.loadMetrics(volumeClaim)}
|
loader={this.loadMetrics}
|
||||||
tabs={metricTabs} object={volumeClaim} params={{ metrics }}
|
tabs={metricTabs} object={volumeClaim} params={{ metrics }}
|
||||||
>
|
>
|
||||||
<VolumeClaimDiskChart/>
|
<VolumeClaimDiskChart/>
|
||||||
|
|||||||
@ -18,32 +18,12 @@
|
|||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* 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.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { action, observable, makeObservable } from "mobx";
|
|
||||||
import { KubeObjectStore } from "../../kube-object.store";
|
|
||||||
import { autoBind } from "../../utils";
|
|
||||||
import { IPvcMetrics, PersistentVolumeClaim, pvcApi } from "../../api/endpoints";
|
|
||||||
import { apiManager } from "../../api/api-manager";
|
import { apiManager } from "../../api/api-manager";
|
||||||
|
import { PersistentVolumeClaim, pvcApi } from "../../api/endpoints";
|
||||||
|
import { KubeObjectStore } from "../../kube-object.store";
|
||||||
|
|
||||||
export class VolumeClaimStore extends KubeObjectStore<PersistentVolumeClaim> {
|
export class VolumeClaimStore extends KubeObjectStore<PersistentVolumeClaim> {
|
||||||
api = pvcApi;
|
api = pvcApi;
|
||||||
@observable metrics: IPvcMetrics = null;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
makeObservable(this);
|
|
||||||
autoBind(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
|
||||||
async loadMetrics(pvc: PersistentVolumeClaim) {
|
|
||||||
this.metrics = await pvcApi.getMetrics(pvc.getName(), pvc.getNs());
|
|
||||||
}
|
|
||||||
|
|
||||||
reset() {
|
|
||||||
this.metrics = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const volumeClaimStore = new VolumeClaimStore();
|
export const volumeClaimStore = new VolumeClaimStore();
|
||||||
|
|||||||
@ -31,10 +31,10 @@ import { PodDetailsAffinities } from "../+workloads-pods/pod-details-affinities"
|
|||||||
import { daemonSetStore } from "./daemonsets.store";
|
import { daemonSetStore } from "./daemonsets.store";
|
||||||
import { podsStore } from "../+workloads-pods/pods.store";
|
import { podsStore } from "../+workloads-pods/pods.store";
|
||||||
import type { KubeObjectDetailsProps } from "../kube-object";
|
import type { KubeObjectDetailsProps } from "../kube-object";
|
||||||
import type { DaemonSet } from "../../api/endpoints";
|
import { DaemonSet, getMetricsForDaemonSets, IPodMetrics } from "../../api/endpoints";
|
||||||
import { ResourceMetrics, ResourceMetricsText } from "../resource-metrics";
|
import { ResourceMetrics, ResourceMetricsText } from "../resource-metrics";
|
||||||
import { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts";
|
import { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts";
|
||||||
import { reaction } from "mobx";
|
import { observable, reaction } from "mobx";
|
||||||
import { PodDetailsList } from "../+workloads-pods/pod-details-list";
|
import { PodDetailsList } from "../+workloads-pods/pod-details-list";
|
||||||
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
|
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
|
||||||
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
||||||
@ -45,17 +45,21 @@ interface Props extends KubeObjectDetailsProps<DaemonSet> {
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class DaemonSetDetails extends React.Component<Props> {
|
export class DaemonSetDetails extends React.Component<Props> {
|
||||||
|
@observable metrics: IPodMetrics = null;
|
||||||
|
|
||||||
@disposeOnUnmount
|
@disposeOnUnmount
|
||||||
clean = reaction(() => this.props.object, () => {
|
clean = reaction(() => this.props.object, () => {
|
||||||
daemonSetStore.reset();
|
this.metrics = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
podsStore.reloadAll();
|
podsStore.reloadAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
async loadMetrics() {
|
||||||
daemonSetStore.reset();
|
const { object: daemonSet } = this.props;
|
||||||
|
|
||||||
|
this.metrics = await getMetricsForDaemonSets([daemonSet], daemonSet.getNs(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -67,15 +71,14 @@ export class DaemonSetDetails extends React.Component<Props> {
|
|||||||
const images = daemonSet.getImages();
|
const images = daemonSet.getImages();
|
||||||
const nodeSelector = daemonSet.getNodeSelectors();
|
const nodeSelector = daemonSet.getNodeSelectors();
|
||||||
const childPods = daemonSetStore.getChildPods(daemonSet);
|
const childPods = daemonSetStore.getChildPods(daemonSet);
|
||||||
const metrics = daemonSetStore.metrics;
|
|
||||||
const isMetricHidden = getActiveClusterEntity()?.isMetricHidden(ClusterMetricsResourceType.DaemonSet);
|
const isMetricHidden = getActiveClusterEntity()?.isMetricHidden(ClusterMetricsResourceType.DaemonSet);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="DaemonSetDetails">
|
<div className="DaemonSetDetails">
|
||||||
{!isMetricHidden && podsStore.isLoaded && (
|
{!isMetricHidden && podsStore.isLoaded && (
|
||||||
<ResourceMetrics
|
<ResourceMetrics
|
||||||
loader={() => daemonSetStore.loadMetrics(daemonSet)}
|
loader={this.loadMetrics}
|
||||||
tabs={podMetricTabs} object={daemonSet} params={{ metrics }}
|
tabs={podMetricTabs} object={daemonSet} params={{ metrics: this.metrics }}
|
||||||
>
|
>
|
||||||
<PodCharts/>
|
<PodCharts/>
|
||||||
</ResourceMetrics>
|
</ResourceMetrics>
|
||||||
@ -110,7 +113,7 @@ export class DaemonSetDetails extends React.Component<Props> {
|
|||||||
<DrawerItem name="Pod Status" className="pod-status">
|
<DrawerItem name="Pod Status" className="pod-status">
|
||||||
<PodDetailsStatuses pods={childPods}/>
|
<PodDetailsStatuses pods={childPods}/>
|
||||||
</DrawerItem>
|
</DrawerItem>
|
||||||
<ResourceMetricsText metrics={metrics}/>
|
<ResourceMetricsText metrics={this.metrics}/>
|
||||||
<PodDetailsList pods={childPods} owner={daemonSet}/>
|
<PodDetailsList pods={childPods} owner={daemonSet}/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -18,19 +18,17 @@
|
|||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* 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.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
import { makeObservable } from "mobx";
|
||||||
|
|
||||||
import { observable, makeObservable } from "mobx";
|
|
||||||
import { KubeObjectStore } from "../../kube-object.store";
|
|
||||||
import { autoBind } from "../../utils";
|
|
||||||
import { DaemonSet, daemonSetApi, IPodMetrics, Pod, podsApi, PodStatus } from "../../api/endpoints";
|
|
||||||
import { podsStore } from "../+workloads-pods/pods.store";
|
import { podsStore } from "../+workloads-pods/pods.store";
|
||||||
import { apiManager } from "../../api/api-manager";
|
import { apiManager } from "../../api/api-manager";
|
||||||
|
import { DaemonSet, daemonSetApi, Pod, PodStatus } from "../../api/endpoints";
|
||||||
|
import { KubeObjectStore } from "../../kube-object.store";
|
||||||
|
import { autoBind } from "../../utils";
|
||||||
|
|
||||||
export class DaemonSetStore extends KubeObjectStore<DaemonSet> {
|
export class DaemonSetStore extends KubeObjectStore<DaemonSet> {
|
||||||
api = daemonSetApi;
|
api = daemonSetApi;
|
||||||
|
|
||||||
@observable metrics: IPodMetrics = null;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@ -38,12 +36,6 @@ export class DaemonSetStore extends KubeObjectStore<DaemonSet> {
|
|||||||
autoBind(this);
|
autoBind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadMetrics(daemonSet: DaemonSet) {
|
|
||||||
const pods = this.getChildPods(daemonSet);
|
|
||||||
|
|
||||||
this.metrics = await podsApi.getMetrics(pods, daemonSet.getNs(), "");
|
|
||||||
}
|
|
||||||
|
|
||||||
getChildPods(daemonSet: DaemonSet): Pod[] {
|
getChildPods(daemonSet: DaemonSet): Pod[] {
|
||||||
return podsStore.getPodsByOwnerId(daemonSet.getId());
|
return podsStore.getPodsByOwnerId(daemonSet.getId());
|
||||||
}
|
}
|
||||||
@ -67,10 +59,6 @@ export class DaemonSetStore extends KubeObjectStore<DaemonSet> {
|
|||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
|
||||||
this.metrics = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const daemonSetStore = new DaemonSetStore();
|
export const daemonSetStore = new DaemonSetStore();
|
||||||
|
|||||||
@ -26,7 +26,7 @@ import kebabCase from "lodash/kebabCase";
|
|||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { DrawerItem } from "../drawer";
|
import { DrawerItem } from "../drawer";
|
||||||
import { Badge } from "../badge";
|
import { Badge } from "../badge";
|
||||||
import type { Deployment } from "../../api/endpoints";
|
import { Deployment, getMetricsForDeployments, IPodMetrics } from "../../api/endpoints";
|
||||||
import { PodDetailsTolerations } from "../+workloads-pods/pod-details-tolerations";
|
import { PodDetailsTolerations } from "../+workloads-pods/pod-details-tolerations";
|
||||||
import { PodDetailsAffinities } from "../+workloads-pods/pod-details-affinities";
|
import { PodDetailsAffinities } from "../+workloads-pods/pod-details-affinities";
|
||||||
import { podsStore } from "../+workloads-pods/pods.store";
|
import { podsStore } from "../+workloads-pods/pods.store";
|
||||||
@ -34,7 +34,7 @@ import type { KubeObjectDetailsProps } from "../kube-object";
|
|||||||
import { ResourceMetrics, ResourceMetricsText } from "../resource-metrics";
|
import { ResourceMetrics, ResourceMetricsText } from "../resource-metrics";
|
||||||
import { deploymentStore } from "./deployments.store";
|
import { deploymentStore } from "./deployments.store";
|
||||||
import { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts";
|
import { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts";
|
||||||
import { reaction } from "mobx";
|
import { observable, reaction } from "mobx";
|
||||||
import { PodDetailsList } from "../+workloads-pods/pod-details-list";
|
import { PodDetailsList } from "../+workloads-pods/pod-details-list";
|
||||||
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
|
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
|
||||||
import { replicaSetStore } from "../+workloads-replicasets/replicasets.store";
|
import { replicaSetStore } from "../+workloads-replicasets/replicasets.store";
|
||||||
@ -47,9 +47,11 @@ interface Props extends KubeObjectDetailsProps<Deployment> {
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class DeploymentDetails extends React.Component<Props> {
|
export class DeploymentDetails extends React.Component<Props> {
|
||||||
|
@observable metrics: IPodMetrics = null;
|
||||||
|
|
||||||
@disposeOnUnmount
|
@disposeOnUnmount
|
||||||
clean = reaction(() => this.props.object, () => {
|
clean = reaction(() => this.props.object, () => {
|
||||||
deploymentStore.reset();
|
this.metrics = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -57,8 +59,10 @@ export class DeploymentDetails extends React.Component<Props> {
|
|||||||
replicaSetStore.reloadAll();
|
replicaSetStore.reloadAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
async loadMetrics() {
|
||||||
deploymentStore.reset();
|
const { object: deployment } = this.props;
|
||||||
|
|
||||||
|
this.metrics = await getMetricsForDeployments([deployment], deployment.getNs(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -70,15 +74,14 @@ export class DeploymentDetails extends React.Component<Props> {
|
|||||||
const selectors = deployment.getSelectors();
|
const selectors = deployment.getSelectors();
|
||||||
const childPods = deploymentStore.getChildPods(deployment);
|
const childPods = deploymentStore.getChildPods(deployment);
|
||||||
const replicaSets = replicaSetStore.getReplicaSetsByOwner(deployment);
|
const replicaSets = replicaSetStore.getReplicaSetsByOwner(deployment);
|
||||||
const metrics = deploymentStore.metrics;
|
|
||||||
const isMetricHidden = getActiveClusterEntity()?.isMetricHidden(ClusterMetricsResourceType.Deployment);
|
const isMetricHidden = getActiveClusterEntity()?.isMetricHidden(ClusterMetricsResourceType.Deployment);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="DeploymentDetails">
|
<div className="DeploymentDetails">
|
||||||
{!isMetricHidden && podsStore.isLoaded && (
|
{!isMetricHidden && podsStore.isLoaded && (
|
||||||
<ResourceMetrics
|
<ResourceMetrics
|
||||||
loader={() => deploymentStore.loadMetrics(deployment)}
|
loader={this.loadMetrics}
|
||||||
tabs={podMetricTabs} object={deployment} params={{ metrics }}
|
tabs={podMetricTabs} object={deployment} params={{ metrics: this.metrics }}
|
||||||
>
|
>
|
||||||
<PodCharts/>
|
<PodCharts/>
|
||||||
</ResourceMetrics>
|
</ResourceMetrics>
|
||||||
@ -132,7 +135,7 @@ export class DeploymentDetails extends React.Component<Props> {
|
|||||||
</DrawerItem>
|
</DrawerItem>
|
||||||
<PodDetailsTolerations workload={deployment}/>
|
<PodDetailsTolerations workload={deployment}/>
|
||||||
<PodDetailsAffinities workload={deployment}/>
|
<PodDetailsAffinities workload={deployment}/>
|
||||||
<ResourceMetricsText metrics={metrics}/>
|
<ResourceMetricsText metrics={this.metrics}/>
|
||||||
<DeploymentReplicaSets replicaSets={replicaSets}/>
|
<DeploymentReplicaSets replicaSets={replicaSets}/>
|
||||||
<PodDetailsList pods={childPods} owner={deployment}/>
|
<PodDetailsList pods={childPods} owner={deployment}/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -18,17 +18,16 @@
|
|||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* 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.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
import { makeObservable } from "mobx";
|
||||||
|
|
||||||
import { observable, makeObservable } from "mobx";
|
|
||||||
import { Deployment, deploymentApi, IPodMetrics, podsApi, PodStatus } from "../../api/endpoints";
|
|
||||||
import { KubeObjectStore } from "../../kube-object.store";
|
|
||||||
import { autoBind } from "../../utils";
|
|
||||||
import { podsStore } from "../+workloads-pods/pods.store";
|
import { podsStore } from "../+workloads-pods/pods.store";
|
||||||
import { apiManager } from "../../api/api-manager";
|
import { apiManager } from "../../api/api-manager";
|
||||||
|
import { Deployment, deploymentApi, PodStatus } from "../../api/endpoints";
|
||||||
|
import { KubeObjectStore } from "../../kube-object.store";
|
||||||
|
import { autoBind } from "../../utils";
|
||||||
|
|
||||||
export class DeploymentStore extends KubeObjectStore<Deployment> {
|
export class DeploymentStore extends KubeObjectStore<Deployment> {
|
||||||
api = deploymentApi;
|
api = deploymentApi;
|
||||||
@observable metrics: IPodMetrics = null;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -43,12 +42,6 @@ export class DeploymentStore extends KubeObjectStore<Deployment> {
|
|||||||
], "desc");
|
], "desc");
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadMetrics(deployment: Deployment) {
|
|
||||||
const pods = this.getChildPods(deployment);
|
|
||||||
|
|
||||||
this.metrics = await podsApi.getMetrics(pods, deployment.getNs(), "");
|
|
||||||
}
|
|
||||||
|
|
||||||
getStatuses(deployments?: Deployment[]) {
|
getStatuses(deployments?: Deployment[]) {
|
||||||
const status = { failed: 0, pending: 0, running: 0 };
|
const status = { failed: 0, pending: 0, running: 0 };
|
||||||
|
|
||||||
@ -74,10 +67,6 @@ export class DeploymentStore extends KubeObjectStore<Deployment> {
|
|||||||
.getByLabel(deployment.getTemplateLabels())
|
.getByLabel(deployment.getTemplateLabels())
|
||||||
.filter(pod => pod.getNs() === deployment.getNs());
|
.filter(pod => pod.getNs() === deployment.getNs());
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
|
||||||
this.metrics = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const deploymentStore = new DeploymentStore();
|
export const deploymentStore = new DeploymentStore();
|
||||||
|
|||||||
@ -25,18 +25,17 @@ import React from "react";
|
|||||||
import kebabCase from "lodash/kebabCase";
|
import kebabCase from "lodash/kebabCase";
|
||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { autorun, observable, reaction, makeObservable } from "mobx";
|
import { observable, reaction, makeObservable } from "mobx";
|
||||||
import { IPodMetrics, nodesApi, Pod, pvcApi, configMapApi } from "../../api/endpoints";
|
import { IPodMetrics, nodesApi, Pod, pvcApi, configMapApi, getMetricsForPods } from "../../api/endpoints";
|
||||||
import { DrawerItem, DrawerTitle } from "../drawer";
|
import { DrawerItem, DrawerTitle } from "../drawer";
|
||||||
import { Badge } from "../badge";
|
import { Badge } from "../badge";
|
||||||
import { boundMethod, cssNames, interval, toJS } from "../../utils";
|
import { boundMethod, cssNames, toJS } from "../../utils";
|
||||||
import { PodDetailsContainer } from "./pod-details-container";
|
import { PodDetailsContainer } from "./pod-details-container";
|
||||||
import { PodDetailsAffinities } from "./pod-details-affinities";
|
import { PodDetailsAffinities } from "./pod-details-affinities";
|
||||||
import { PodDetailsTolerations } from "./pod-details-tolerations";
|
import { PodDetailsTolerations } from "./pod-details-tolerations";
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
import { PodDetailsSecrets } from "./pod-details-secrets";
|
import { PodDetailsSecrets } from "./pod-details-secrets";
|
||||||
import { ResourceMetrics } from "../resource-metrics";
|
import { ResourceMetrics } from "../resource-metrics";
|
||||||
import { podsStore } from "./pods.store";
|
|
||||||
import { getDetailsUrl, KubeObjectDetailsProps } from "../kube-object";
|
import { getDetailsUrl, KubeObjectDetailsProps } from "../kube-object";
|
||||||
import { getItemMetrics } from "../../api/endpoints/metrics.api";
|
import { getItemMetrics } from "../../api/endpoints/metrics.api";
|
||||||
import { PodCharts, podMetricTabs } from "./pod-charts";
|
import { PodCharts, podMetricTabs } from "./pod-charts";
|
||||||
@ -49,10 +48,9 @@ interface Props extends KubeObjectDetailsProps<Pod> {
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class PodDetails extends React.Component<Props> {
|
export class PodDetails extends React.Component<Props> {
|
||||||
|
@observable metrics: IPodMetrics;
|
||||||
@observable containerMetrics: IPodMetrics;
|
@observable containerMetrics: IPodMetrics;
|
||||||
|
|
||||||
private watcher = interval(60, () => this.loadMetrics());
|
|
||||||
|
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
@ -60,26 +58,19 @@ export class PodDetails extends React.Component<Props> {
|
|||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
disposeOnUnmount(this, [
|
disposeOnUnmount(this, [
|
||||||
autorun(() => {
|
|
||||||
this.containerMetrics = null;
|
|
||||||
this.loadMetrics();
|
|
||||||
}),
|
|
||||||
reaction(() => this.props.object, () => {
|
reaction(() => this.props.object, () => {
|
||||||
podsStore.reset();
|
this.metrics = null;
|
||||||
|
this.containerMetrics = null;
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
this.watcher.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
podsStore.reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@boundMethod
|
@boundMethod
|
||||||
async loadMetrics() {
|
async loadMetrics() {
|
||||||
const { object: pod } = this.props;
|
const { object: pod } = this.props;
|
||||||
|
|
||||||
this.containerMetrics = await podsStore.loadContainerMetrics(pod);
|
this.metrics = await getMetricsForPods([pod], pod.getNs());
|
||||||
|
this.containerMetrics = await getMetricsForPods([pod], pod.getNs(), "container, namespace");
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -92,15 +83,14 @@ export class PodDetails extends React.Component<Props> {
|
|||||||
const { nodeName } = spec;
|
const { nodeName } = spec;
|
||||||
const nodeSelector = pod.getNodeSelectors();
|
const nodeSelector = pod.getNodeSelectors();
|
||||||
const volumes = pod.getVolumes();
|
const volumes = pod.getVolumes();
|
||||||
const metrics = podsStore.metrics;
|
|
||||||
const isMetricHidden = getActiveClusterEntity()?.isMetricHidden(ClusterMetricsResourceType.Pod);
|
const isMetricHidden = getActiveClusterEntity()?.isMetricHidden(ClusterMetricsResourceType.Pod);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="PodDetails">
|
<div className="PodDetails">
|
||||||
{!isMetricHidden && (
|
{!isMetricHidden && (
|
||||||
<ResourceMetrics
|
<ResourceMetrics
|
||||||
loader={() => podsStore.loadMetrics(pod)}
|
loader={this.loadMetrics}
|
||||||
tabs={podMetricTabs} object={pod} params={{ metrics }}
|
tabs={podMetricTabs} object={pod} params={{ metrics: this.metrics }}
|
||||||
>
|
>
|
||||||
<PodCharts/>
|
<PodCharts/>
|
||||||
</ResourceMetrics>
|
</ResourceMetrics>
|
||||||
|
|||||||
@ -20,17 +20,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import countBy from "lodash/countBy";
|
import countBy from "lodash/countBy";
|
||||||
import { action, observable, makeObservable } from "mobx";
|
import { observable, makeObservable } from "mobx";
|
||||||
import { KubeObjectStore } from "../../kube-object.store";
|
import { KubeObjectStore } from "../../kube-object.store";
|
||||||
import { autoBind, cpuUnitsToNumber, unitsToBytes } from "../../utils";
|
import { autoBind, cpuUnitsToNumber, unitsToBytes } from "../../utils";
|
||||||
import { IPodMetrics, Pod, PodMetrics, podMetricsApi, podsApi } from "../../api/endpoints";
|
import { Pod, PodMetrics, podMetricsApi, podsApi } from "../../api/endpoints";
|
||||||
import { apiManager } from "../../api/api-manager";
|
import { apiManager } from "../../api/api-manager";
|
||||||
import type { WorkloadKubeObject } from "../../api/workload-kube-object";
|
import type { WorkloadKubeObject } from "../../api/workload-kube-object";
|
||||||
|
|
||||||
export class PodsStore extends KubeObjectStore<Pod> {
|
export class PodsStore extends KubeObjectStore<Pod> {
|
||||||
api = podsApi;
|
api = podsApi;
|
||||||
|
|
||||||
@observable metrics: IPodMetrics = null;
|
|
||||||
@observable kubeMetrics = observable.array<PodMetrics>([]);
|
@observable kubeMetrics = observable.array<PodMetrics>([]);
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -40,15 +39,6 @@ export class PodsStore extends KubeObjectStore<Pod> {
|
|||||||
autoBind(this);
|
autoBind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
|
||||||
async loadMetrics(pod: Pod) {
|
|
||||||
this.metrics = await podsApi.getMetrics([pod], pod.getNs());
|
|
||||||
}
|
|
||||||
|
|
||||||
loadContainerMetrics(pod: Pod) {
|
|
||||||
return podsApi.getMetrics([pod], pod.getNs(), "container, namespace");
|
|
||||||
}
|
|
||||||
|
|
||||||
async loadKubeMetrics(namespace?: string) {
|
async loadKubeMetrics(namespace?: string) {
|
||||||
try {
|
try {
|
||||||
const metrics = await podMetricsApi.list({ namespace });
|
const metrics = await podMetricsApi.list({ namespace });
|
||||||
@ -113,10 +103,6 @@ export class PodsStore extends KubeObjectStore<Pod> {
|
|||||||
};
|
};
|
||||||
}, empty);
|
}, empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
|
||||||
this.metrics = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const podsStore = new PodsStore();
|
export const podsStore = new PodsStore();
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
import "./replicaset-details.scss";
|
import "./replicaset-details.scss";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { reaction } from "mobx";
|
import { observable, reaction } from "mobx";
|
||||||
import { DrawerItem } from "../drawer";
|
import { DrawerItem } from "../drawer";
|
||||||
import { Badge } from "../badge";
|
import { Badge } from "../badge";
|
||||||
import { replicaSetStore } from "./replicasets.store";
|
import { replicaSetStore } from "./replicasets.store";
|
||||||
@ -31,7 +31,7 @@ import { PodDetailsAffinities } from "../+workloads-pods/pod-details-affinities"
|
|||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { podsStore } from "../+workloads-pods/pods.store";
|
import { podsStore } from "../+workloads-pods/pods.store";
|
||||||
import type { KubeObjectDetailsProps } from "../kube-object";
|
import type { KubeObjectDetailsProps } from "../kube-object";
|
||||||
import type { ReplicaSet } from "../../api/endpoints";
|
import { getMetricsForReplicaSets, IPodMetrics, ReplicaSet } from "../../api/endpoints";
|
||||||
import { ResourceMetrics, ResourceMetricsText } from "../resource-metrics";
|
import { ResourceMetrics, ResourceMetricsText } from "../resource-metrics";
|
||||||
import { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts";
|
import { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts";
|
||||||
import { PodDetailsList } from "../+workloads-pods/pod-details-list";
|
import { PodDetailsList } from "../+workloads-pods/pod-details-list";
|
||||||
@ -44,24 +44,28 @@ interface Props extends KubeObjectDetailsProps<ReplicaSet> {
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class ReplicaSetDetails extends React.Component<Props> {
|
export class ReplicaSetDetails extends React.Component<Props> {
|
||||||
|
@observable metrics: IPodMetrics = null;
|
||||||
|
|
||||||
@disposeOnUnmount
|
@disposeOnUnmount
|
||||||
clean = reaction(() => this.props.object, () => {
|
clean = reaction(() => this.props.object, () => {
|
||||||
replicaSetStore.reset();
|
this.metrics = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
podsStore.reloadAll();
|
podsStore.reloadAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
async loadMetrics() {
|
||||||
replicaSetStore.reset();
|
const { object: replicaSet } = this.props;
|
||||||
|
|
||||||
|
this.metrics = await getMetricsForReplicaSets([replicaSet], replicaSet.getNs(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { object: replicaSet } = this.props;
|
const { object: replicaSet } = this.props;
|
||||||
|
|
||||||
if (!replicaSet) return null;
|
if (!replicaSet) return null;
|
||||||
const { metrics } = replicaSetStore;
|
const { metrics } = this;
|
||||||
const { status } = replicaSet;
|
const { status } = replicaSet;
|
||||||
const { availableReplicas, replicas } = status;
|
const { availableReplicas, replicas } = status;
|
||||||
const selectors = replicaSet.getSelectors();
|
const selectors = replicaSet.getSelectors();
|
||||||
@ -74,7 +78,7 @@ export class ReplicaSetDetails extends React.Component<Props> {
|
|||||||
<div className="ReplicaSetDetails">
|
<div className="ReplicaSetDetails">
|
||||||
{!isMetricHidden && podsStore.isLoaded && (
|
{!isMetricHidden && podsStore.isLoaded && (
|
||||||
<ResourceMetrics
|
<ResourceMetrics
|
||||||
loader={() => replicaSetStore.loadMetrics(replicaSet)}
|
loader={this.loadMetrics}
|
||||||
tabs={podMetricTabs} object={replicaSet} params={{ metrics }}
|
tabs={podMetricTabs} object={replicaSet} params={{ metrics }}
|
||||||
>
|
>
|
||||||
<PodCharts/>
|
<PodCharts/>
|
||||||
|
|||||||
@ -18,18 +18,17 @@
|
|||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* 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.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
import { makeObservable } from "mobx";
|
||||||
|
|
||||||
import { observable, makeObservable } from "mobx";
|
|
||||||
import { autoBind } from "../../utils";
|
|
||||||
import { KubeObjectStore } from "../../kube-object.store";
|
|
||||||
import { Deployment, IPodMetrics, podsApi, ReplicaSet, replicaSetApi } from "../../api/endpoints";
|
|
||||||
import { podsStore } from "../+workloads-pods/pods.store";
|
import { podsStore } from "../+workloads-pods/pods.store";
|
||||||
import { apiManager } from "../../api/api-manager";
|
import { apiManager } from "../../api/api-manager";
|
||||||
|
import { Deployment, ReplicaSet, replicaSetApi } from "../../api/endpoints";
|
||||||
import { PodStatus } from "../../api/endpoints/pods.api";
|
import { PodStatus } from "../../api/endpoints/pods.api";
|
||||||
|
import { KubeObjectStore } from "../../kube-object.store";
|
||||||
|
import { autoBind } from "../../utils";
|
||||||
|
|
||||||
export class ReplicaSetStore extends KubeObjectStore<ReplicaSet> {
|
export class ReplicaSetStore extends KubeObjectStore<ReplicaSet> {
|
||||||
api = replicaSetApi;
|
api = replicaSetApi;
|
||||||
@observable metrics: IPodMetrics = null;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -38,12 +37,6 @@ export class ReplicaSetStore extends KubeObjectStore<ReplicaSet> {
|
|||||||
autoBind(this);
|
autoBind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadMetrics(replicaSet: ReplicaSet) {
|
|
||||||
const pods = this.getChildPods(replicaSet);
|
|
||||||
|
|
||||||
this.metrics = await podsApi.getMetrics(pods, replicaSet.getNs(), "");
|
|
||||||
}
|
|
||||||
|
|
||||||
getChildPods(replicaSet: ReplicaSet) {
|
getChildPods(replicaSet: ReplicaSet) {
|
||||||
return podsStore.getPodsByOwnerId(replicaSet.getId());
|
return podsStore.getPodsByOwnerId(replicaSet.getId());
|
||||||
}
|
}
|
||||||
@ -73,10 +66,6 @@ export class ReplicaSetStore extends KubeObjectStore<ReplicaSet> {
|
|||||||
!!replicaSet.getOwnerRefs().find(owner => owner.uid === deployment.getId())
|
!!replicaSet.getOwnerRefs().find(owner => owner.uid === deployment.getId())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
|
||||||
this.metrics = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const replicaSetStore = new ReplicaSetStore();
|
export const replicaSetStore = new ReplicaSetStore();
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import "./statefulset-details.scss";
|
|||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { reaction } from "mobx";
|
import { observable, reaction } from "mobx";
|
||||||
import { Badge } from "../badge";
|
import { Badge } from "../badge";
|
||||||
import { DrawerItem } from "../drawer";
|
import { DrawerItem } from "../drawer";
|
||||||
import { PodDetailsStatuses } from "../+workloads-pods/pod-details-statuses";
|
import { PodDetailsStatuses } from "../+workloads-pods/pod-details-statuses";
|
||||||
@ -32,7 +32,7 @@ import { PodDetailsAffinities } from "../+workloads-pods/pod-details-affinities"
|
|||||||
import { podsStore } from "../+workloads-pods/pods.store";
|
import { podsStore } from "../+workloads-pods/pods.store";
|
||||||
import { statefulSetStore } from "./statefulset.store";
|
import { statefulSetStore } from "./statefulset.store";
|
||||||
import type { KubeObjectDetailsProps } from "../kube-object";
|
import type { KubeObjectDetailsProps } from "../kube-object";
|
||||||
import type { StatefulSet } from "../../api/endpoints";
|
import { getMetricsForStatefulSets, IPodMetrics, StatefulSet } from "../../api/endpoints";
|
||||||
import { ResourceMetrics, ResourceMetricsText } from "../resource-metrics";
|
import { ResourceMetrics, ResourceMetricsText } from "../resource-metrics";
|
||||||
import { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts";
|
import { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts";
|
||||||
import { PodDetailsList } from "../+workloads-pods/pod-details-list";
|
import { PodDetailsList } from "../+workloads-pods/pod-details-list";
|
||||||
@ -45,17 +45,21 @@ interface Props extends KubeObjectDetailsProps<StatefulSet> {
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class StatefulSetDetails extends React.Component<Props> {
|
export class StatefulSetDetails extends React.Component<Props> {
|
||||||
|
@observable metrics: IPodMetrics = null;
|
||||||
|
|
||||||
@disposeOnUnmount
|
@disposeOnUnmount
|
||||||
clean = reaction(() => this.props.object, () => {
|
clean = reaction(() => this.props.object, () => {
|
||||||
statefulSetStore.reset();
|
this.metrics = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
podsStore.reloadAll();
|
podsStore.reloadAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
async loadMetrics() {
|
||||||
statefulSetStore.reset();
|
const { object: statefulSet } = this.props;
|
||||||
|
|
||||||
|
this.metrics = await getMetricsForStatefulSets([statefulSet], statefulSet.getNs(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -66,15 +70,14 @@ export class StatefulSetDetails extends React.Component<Props> {
|
|||||||
const selectors = statefulSet.getSelectors();
|
const selectors = statefulSet.getSelectors();
|
||||||
const nodeSelector = statefulSet.getNodeSelectors();
|
const nodeSelector = statefulSet.getNodeSelectors();
|
||||||
const childPods = statefulSetStore.getChildPods(statefulSet);
|
const childPods = statefulSetStore.getChildPods(statefulSet);
|
||||||
const metrics = statefulSetStore.metrics;
|
|
||||||
const isMetricHidden = getActiveClusterEntity()?.isMetricHidden(ClusterMetricsResourceType.StatefulSet);
|
const isMetricHidden = getActiveClusterEntity()?.isMetricHidden(ClusterMetricsResourceType.StatefulSet);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="StatefulSetDetails">
|
<div className="StatefulSetDetails">
|
||||||
{!isMetricHidden && podsStore.isLoaded && (
|
{!isMetricHidden && podsStore.isLoaded && (
|
||||||
<ResourceMetrics
|
<ResourceMetrics
|
||||||
loader={() => statefulSetStore.loadMetrics(statefulSet)}
|
loader={() => this.loadMetrics}
|
||||||
tabs={podMetricTabs} object={statefulSet} params={{ metrics }}
|
tabs={podMetricTabs} object={statefulSet} params={{ metrics: this.metrics }}
|
||||||
>
|
>
|
||||||
<PodCharts/>
|
<PodCharts/>
|
||||||
</ResourceMetrics>
|
</ResourceMetrics>
|
||||||
@ -108,7 +111,7 @@ export class StatefulSetDetails extends React.Component<Props> {
|
|||||||
<DrawerItem name="Pod Status" className="pod-status">
|
<DrawerItem name="Pod Status" className="pod-status">
|
||||||
<PodDetailsStatuses pods={childPods}/>
|
<PodDetailsStatuses pods={childPods}/>
|
||||||
</DrawerItem>
|
</DrawerItem>
|
||||||
<ResourceMetricsText metrics={metrics}/>
|
<ResourceMetricsText metrics={this.metrics}/>
|
||||||
<PodDetailsList pods={childPods} owner={statefulSet}/>
|
<PodDetailsList pods={childPods} owner={statefulSet}/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -18,17 +18,16 @@
|
|||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* 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.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
import { makeObservable } from "mobx";
|
||||||
|
|
||||||
import { observable, makeObservable } from "mobx";
|
|
||||||
import { autoBind } from "../../utils";
|
|
||||||
import { KubeObjectStore } from "../../kube-object.store";
|
|
||||||
import { IPodMetrics, podsApi, PodStatus, StatefulSet, statefulSetApi } from "../../api/endpoints";
|
|
||||||
import { podsStore } from "../+workloads-pods/pods.store";
|
import { podsStore } from "../+workloads-pods/pods.store";
|
||||||
import { apiManager } from "../../api/api-manager";
|
import { apiManager } from "../../api/api-manager";
|
||||||
|
import { PodStatus, StatefulSet, statefulSetApi } from "../../api/endpoints";
|
||||||
|
import { KubeObjectStore } from "../../kube-object.store";
|
||||||
|
import { autoBind } from "../../utils";
|
||||||
|
|
||||||
export class StatefulSetStore extends KubeObjectStore<StatefulSet> {
|
export class StatefulSetStore extends KubeObjectStore<StatefulSet> {
|
||||||
api = statefulSetApi;
|
api = statefulSetApi;
|
||||||
@observable metrics: IPodMetrics = null;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -37,13 +36,6 @@ export class StatefulSetStore extends KubeObjectStore<StatefulSet> {
|
|||||||
autoBind(this);
|
autoBind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async loadMetrics(statefulSet: StatefulSet) {
|
|
||||||
const pods = this.getChildPods(statefulSet);
|
|
||||||
|
|
||||||
this.metrics = await podsApi.getMetrics(pods, statefulSet.getNs(), "");
|
|
||||||
}
|
|
||||||
|
|
||||||
getChildPods(statefulSet: StatefulSet) {
|
getChildPods(statefulSet: StatefulSet) {
|
||||||
return podsStore.getPodsByOwnerId(statefulSet.getId());
|
return podsStore.getPodsByOwnerId(statefulSet.getId());
|
||||||
}
|
}
|
||||||
@ -67,10 +59,6 @@ export class StatefulSetStore extends KubeObjectStore<StatefulSet> {
|
|||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
|
||||||
this.metrics = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const statefulSetStore = new StatefulSetStore();
|
export const statefulSetStore = new StatefulSetStore();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user