Procházet zdrojové kódy

Fixing issue where pre-deploy logs were not populating sometimes (#3369)

Feroze Mohideen před 2 roky
rodič
revize
b96ab9d0b8

+ 9 - 7
api/server/handlers/porter_app/get_logs_within_time_range.go

@@ -50,6 +50,12 @@ func (c *GetLogsWithinTimeRangeHandler) ServeHTTP(w http.ResponseWriter, r *http
 		return
 	}
 
+	if (request.PodSelector != "" && request.ChartName != "") || (request.PodSelector == "" && request.ChartName == "") {
+		err := telemetry.Error(ctx, span, nil, "must provide either pod selector or chart name")
+		c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
+		return
+	}
+
 	agent, err := c.GetAgent(r, cluster, "")
 	if err != nil {
 		_ = telemetry.Error(ctx, span, err, "unable to get agent")
@@ -74,11 +80,6 @@ func (c *GetLogsWithinTimeRangeHandler) ServeHTTP(w http.ResponseWriter, r *http
 
 	var podSelector string
 	if request.ChartName == "" {
-		if request.PodSelector == "" {
-			err = telemetry.Error(ctx, span, nil, "must provide either chart name or pod selector")
-			c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
-			return
-		}
 		podSelector = request.PodSelector
 	} else {
 		// get the pod values which will be used to get the correct pod selector
@@ -111,13 +112,14 @@ func (c *GetLogsWithinTimeRangeHandler) ServeHTTP(w http.ResponseWriter, r *http
 				for _, pod := range pods {
 					if pod.GetCreationTimestamp().Time.After(request.StartRange) && pod.GetCreationTimestamp().Time.Before(request.EndRange) {
 						if latestPod == nil || pod.GetCreationTimestamp().Time.After(latestPod.GetCreationTimestamp().Time) {
-							latestPod = &pod
+							copyPod := pod
+							latestPod = &copyPod
 						}
 					}
 				}
 			}
 			if latestPod == nil {
-				err = telemetry.Error(ctx, span, nil, "no pods found within timerange")
+				err = telemetry.Error(ctx, span, nil, "unable to retrieve logs for latest job")
 				c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusNotFound))
 				return
 			}

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

@@ -118,7 +118,7 @@ const ExpandedApp: React.FC<Props> = ({ ...props }) => {
   const [porterApp, setPorterApp] = useState<PorterApp>();
 
   // this is the version of the porterApp that is being edited. on save, we set the real porter app to be this version
-  const [tempPorterApp, setTempPorterApp] = useState<PorterApp>();
+  const [tempPorterApp, setTempPorterApp] = useState<PorterApp>(PorterApp.empty());
   const [buildView, setBuildView] = useState<BuildMethod>("docker");
 
   const history = useHistory();
@@ -674,7 +674,6 @@ const ExpandedApp: React.FC<Props> = ({ ...props }) => {
             setTempPorterApp={(attrs: Partial<PorterApp>) => setTempPorterApp(PorterApp.setAttributes(tempPorterApp, attrs))}
             clearStatus={() => setButtonStatus("")}
             updatePorterApp={updatePorterApp}
-            setShowUnsavedChangesBanner={setShowUnsavedChangesBanner}
             buildView={buildView}
             setBuildView={setBuildView}
           />
@@ -688,7 +687,7 @@ const ExpandedApp: React.FC<Props> = ({ ...props }) => {
       case "logs":
         return <LogSection
           currentChart={appData.chart}
-          services={services.filter(svc => Service.isNonRelease(svc) && !Service.isJob(svc))}
+          services={services.filter(svc => Service.isNonRelease(svc))}
           appName={appData.app.name}
           filterOpts={queryParamOpts}
         />;

+ 34 - 56
dashboard/src/main/home/app-dashboard/expanded-app/logs/LogSection.tsx

@@ -334,65 +334,43 @@ const LogSection: React.FC<Props> = ({
     return () => clearInterval(checkForAgentInterval);
   }, [isPorterAgentInstalling]);
 
-  const checkForAgent = () => {
+  const checkForAgent = async () => {
     const project_id = currentProject?.id;
     const cluster_id = currentCluster?.id;
 
-    api
-      .detectPorterAgent("<token>", {}, { project_id, cluster_id })
-      .then((res) => {
-        if (res.data?.version != "v3") {
-          setHasPorterAgent(false);
-        } else {
-          // next, check whether logs can be queried - if they can, we're good to go
-          const filters = {
-            revision: currentChart.version.toString(),
-            match_prefix: currentChart.name,
-          };
-
-          api
-            .getLogPodValues("<TOKEN>", filters, {
-              project_id: currentProject.id,
-              cluster_id: currentCluster.id,
-            })
-            .then((res) => {
-              setHasPorterAgent(true);
-              setIsPorterAgentInstalling(false);
-              setIsLoading(false);
-            })
-            .catch((err) => {
-              // do nothing - this is expected while installing
-              setLogsError(err);
-              setIsLoading(false);
-            });
-
-          const agentImage = res.data?.image;
-          if (!isAgentVersionUpdated(agentImage)) {
-            setFilters([
-              {
-                name: "pod_name",
-                displayName: "Service",
-                default: GenericLogFilter.getDefaultOption("pod_name"),
-                options: services?.map(s => {
-                  return GenericFilterOption.of(s.name, `${s.name}-${s.type == "worker" ? "wkr" : s.type}`)
-                }) ?? [],
-                setValue: (value: string) => {
-                  setSelectedFilterValues((s) => ({
-                    ...s,
-                    pod_name: value,
-                  }));
-                }
-              },
-            ])
-          }
-        }
-      })
-      .catch((err) => {
-        if (err.response?.status === 404) {
-          setHasPorterAgent(false);
-          setIsLoading(false);
-        }
-      });
+    if (!project_id || !cluster_id) {
+      return;
+    }
+
+    try {
+      const res = await api.detectPorterAgent("<token>", {}, { project_id, cluster_id });
+
+      setHasPorterAgent(true);
+
+      const agentImage = res.data?.image;
+      if (!isAgentVersionUpdated(agentImage)) {
+        setFilters([
+          {
+            name: "pod_name",
+            displayName: "Service",
+            default: GenericLogFilter.getDefaultOption("pod_name"),
+            options: services?.map(s => {
+              return GenericFilterOption.of(s.name, `${s.name}-${s.type == "worker" ? "wkr" : s.type}`)
+            }) ?? [],
+            setValue: (value: string) => {
+              setSelectedFilterValues((s) => ({
+                ...s,
+                pod_name: value,
+              }));
+            }
+          },
+        ])
+      }
+    } catch (err) {
+      if (err.response?.status === 404) {
+        setHasPorterAgent(false);
+      }
+    }
   };
 
   const installAgent = async () => {