فهرست منبع

fix: hide network metric if the service is not of type web (#3437)

jose-fully-ported 2 سال پیش
والد
کامیت
cc18b6ee86

+ 1 - 1
dashboard/src/main/home/app-dashboard/expanded-app/ExpandedApp.tsx

@@ -692,7 +692,7 @@ const ExpandedApp: React.FC<Props> = ({ ...props }) => {
           filterOpts={queryParamOpts}
         />;
       case "metrics":
-        return <MetricsSection currentChart={appData.chart} appName={appData.app.name} serviceName={queryParamOpts.service} />;
+        return <MetricsSection currentChart={appData.chart} appName={appData.app.name} serviceName={queryParamOpts.service} services={services} />;
       case "debug":
         return <StatusSectionFC currentChart={appData.chart} />;
       case "environment":

+ 9 - 1
dashboard/src/main/home/app-dashboard/expanded-app/metrics/MetricsSection.tsx

@@ -4,6 +4,7 @@ import styled from "styled-components";
 import api from "shared/api";
 import { Context } from "shared/Context";
 import { ChartType } from "shared/types";
+import { Service } from "../../new-app-flow/serviceTypes";
 
 import TabSelector from "components/TabSelector";
 import SelectRow from "components/form-components/SelectRow";
@@ -20,12 +21,14 @@ type PropsType = {
   currentChart: ChartType;
   appName: string;
   serviceName?: string;
+  services: Service[];
 };
 
 const MetricsSection: React.FunctionComponent<PropsType> = ({
   currentChart,
   appName,
   serviceName,
+  services,
 }) => {
   const [selectedController, setSelectedController] = useState<any>(null);
   const [selectedRange, setSelectedRange] = useState("1H");
@@ -84,11 +87,16 @@ const MetricsSection: React.FunctionComponent<PropsType> = ({
         return;
       }
       const metrics: Metric[] = [];
-      const metricTypes: MetricType[] = ["cpu", "memory", "network"];
+      const metricTypes: MetricType[] = ["cpu", "memory"];
 
       const serviceName: string = selectedController?.metadata.labels["app.kubernetes.io/name"]
       const isHpaEnabled: boolean = currentChart?.config?.[serviceName]?.autoscaling?.enabled
 
+      const shortServiceName: string = getServiceNameFromControllerName(selectedController?.metadata?.name, appName)
+      if (services.some(svc => svc.name === shortServiceName && svc.type === "web")) {
+         metricTypes.push("network");
+      }
+
       if (isHpaEnabled) {
         metricTypes.push("hpa_replicas");
       }