Ver Fonte

fix long named pod logs (#3445)

Feroze Mohideen há 2 anos atrás
pai
commit
c86b517fff

+ 20 - 1
api/server/handlers/porter_app/get_logs_within_time_range.go

@@ -80,7 +80,7 @@ func (c *GetLogsWithinTimeRangeHandler) ServeHTTP(w http.ResponseWriter, r *http
 
 	var podSelector string
 	if request.ChartName == "" {
-		podSelector = request.PodSelector
+		podSelector = trimPodSelector(request.PodSelector)
 	} else {
 		// get the pod values which will be used to get the correct pod selector
 		podVals, err := porter_agent.GetPodValues(agent.Clientset, agentSvc, podValuesRequest)
@@ -153,3 +153,22 @@ func (c *GetLogsWithinTimeRangeHandler) ServeHTTP(w http.ResponseWriter, r *http
 
 	c.WriteResult(w, r, logs)
 }
+
+/**
+ * Application pods are of the format <app-name>-<service-name>-<random-4-char-string>
+ * The max length of a pod name is 63 characters
+ * Therefore if the podSelector we try to use is longer than 58 characters (63 characters minus 4 characters for the random string minus 1 character for the last hyphen), then it won't match any pods
+ * e.g. podSelector "postgres-snowflake-connector-postgres-snowflake-service-wkr-" (60 chars) won't work because the pod is actually named "postgres-snowflake-connector-postgres-snowflake-service-wkqcpz2"
+ * so we trim the podSelector to "postgres-snowflake-connector-postgres-snowflake-service-wk" (58 characters) to ensure we match the pod
+ * This is only to fix current pods; new pods will be named correctly because we imposed service name limits in https://github.com/porter-dev/porter/pull/3439
+ * */
+func trimPodSelector(podSelector string) string {
+	if !strings.HasSuffix(podSelector, ".*") {
+		return podSelector
+	}
+	podSelector = strings.TrimSuffix(podSelector, ".*")
+	if len(podSelector) <= 58 {
+		return podSelector
+	}
+	return fmt.Sprintf("%s.*", podSelector[:58])
+}

+ 8 - 0
dashboard/src/main/home/app-dashboard/expanded-app/logs/utils.ts

@@ -500,6 +500,14 @@ export const getServiceNameFromPodNameAndAppName = (podName: string, porterAppNa
     return podName.substring(0, index);
   }
 
+  // if the suffix wasn't found, it's possible that the service name was too long to keep the entire suffix. example: postgres-snowflake-connector-postgres-snowflake-service-wk8gnst
+  // if this is the case, find the service name by removing everything after the last dash
+  // This is only to fix current pods; new pods will be named correctly because we imposed service name limits in https://github.com/porter-dev/porter/pull/3439
+  index = podName.lastIndexOf("-");
+  if (index !== -1) {
+    return podName.substring(0, index)
+  }
+
   return "";
 }