mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Improving metric queries (#3424)
This commit is contained in:
1 parent
84c767a3d2
commit
c6a4d55d86
33 files changed
+452
-357
No files matched your search
@@ -21,7 +21,7 @@
|
||||
|
||||
import "./replicaset-details.scss";
|
||||
import React from "react";
|
||||
import { reaction } from "mobx";
|
||||
import { makeObservable, observable, reaction } from "mobx";
|
||||
import { DrawerItem } from "../drawer";
|
||||
import { Badge } from "../badge";
|
||||
import { replicaSetStore } from "./replicasets.store";
|
||||
@@ -31,37 +31,48 @@ import { PodDetailsAffinities } from "../+workloads-pods/pod-details-affinities"
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import { podsStore } from "../+workloads-pods/pods.store";
|
||||
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 { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts";
|
||||
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> {
|
||||
}
|
||||
|
||||
@observer
|
||||
export class ReplicaSetDetails extends React.Component<Props> {
|
||||
@observable metrics: IPodMetrics = null;
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
makeObservable(this);
|
||||
}
|
||||
|
||||
@disposeOnUnmount
|
||||
clean = reaction(() => this.props.object, () => {
|
||||
replicaSetStore.reset();
|
||||
this.metrics = null;
|
||||
});
|
||||
|
||||
async componentDidMount() {
|
||||
podsStore.reloadAll();
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
replicaSetStore.reset();
|
||||
@boundMethod
|
||||
async loadMetrics() {
|
||||
const { object: replicaSet } = this.props;
|
||||
|
||||
this.metrics = await getMetricsForReplicaSets([replicaSet], replicaSet.getNs(), "");
|
||||
}
|
||||
|
||||
render() {
|
||||
const { object: replicaSet } = this.props;
|
||||
|
||||
if (!replicaSet) return null;
|
||||
const { metrics } = replicaSetStore;
|
||||
const { metrics } = this;
|
||||
const { status } = replicaSet;
|
||||
const { availableReplicas, replicas } = status;
|
||||
const selectors = replicaSet.getSelectors();
|
||||
@@ -74,7 +85,7 @@ export class ReplicaSetDetails extends React.Component<Props> {
|
||||
<div className="ReplicaSetDetails">
|
||||
{!isMetricHidden && podsStore.isLoaded && (
|
||||
<ResourceMetrics
|
||||
loader={() => replicaSetStore.loadMetrics(replicaSet)}
|
||||
loader={this.loadMetrics}
|
||||
tabs={podMetricTabs} object={replicaSet} params={{ metrics }}
|
||||
>
|
||||
<PodCharts/>
|
||||
|
||||
@@ -18,18 +18,17 @@
|
||||
* 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 { 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 { apiManager } from "../../api/api-manager";
|
||||
import { Deployment, ReplicaSet, replicaSetApi } from "../../api/endpoints";
|
||||
import { PodStatus } from "../../api/endpoints/pods.api";
|
||||
import { KubeObjectStore } from "../../kube-object.store";
|
||||
import { autoBind } from "../../utils";
|
||||
|
||||
export class ReplicaSetStore extends KubeObjectStore<ReplicaSet> {
|
||||
api = replicaSetApi;
|
||||
@observable metrics: IPodMetrics = null;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
@@ -38,12 +37,6 @@ export class ReplicaSetStore extends KubeObjectStore<ReplicaSet> {
|
||||
autoBind(this);
|
||||
}
|
||||
|
||||
async loadMetrics(replicaSet: ReplicaSet) {
|
||||
const pods = this.getChildPods(replicaSet);
|
||||
|
||||
this.metrics = await podsApi.getMetrics(pods, replicaSet.getNs(), "");
|
||||
}
|
||||
|
||||
getChildPods(replicaSet: ReplicaSet) {
|
||||
return podsStore.getPodsByOwnerId(replicaSet.getId());
|
||||
}
|
||||
@@ -73,10 +66,6 @@ export class ReplicaSetStore extends KubeObjectStore<ReplicaSet> {
|
||||
!!replicaSet.getOwnerRefs().find(owner => owner.uid === deployment.getId())
|
||||
);
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.metrics = null;
|
||||
}
|
||||
}
|
||||
|
||||
export const replicaSetStore = new ReplicaSetStore();
|
||||
|
||||
Reference in new issue
Block a user