Ivan Galakhov 4 سال پیش
والد
کامیت
a12bc0d8a0

+ 0 - 7
cli/cmd/api/api.go

@@ -99,8 +99,6 @@ func (c *Client) sendRequest(req *http.Request, v interface{}, useCookie bool) (
 		req.AddCookie(c.Cookie)
 	}
 
-	fmt.Printf("%+v\n", req.Header)
-
 	res, err := c.HTTPClient.Do(req)
 
 	if err != nil {
@@ -119,11 +117,6 @@ func (c *Client) sendRequest(req *http.Request, v interface{}, useCookie bool) (
 			return &errRes, nil
 		}
 
-		fmt.Println("error request")
-		fmt.Printf("%+v\n", req)
-		fmt.Println(errRes)
-		fmt.Println(res.StatusCode)
-
 		return nil, fmt.Errorf("unknown error, status code: %d", res.StatusCode)
 	}
 

+ 17 - 6
cli/cmd/deploy.go

@@ -403,8 +403,6 @@ func updateBuildWithAgent(updateAgent *deploy.DeployAgent, client *api.Client) e
 
 	// minor thought: this ends up happening four times when upgrade is ran, when it should really only happen once
 	// maybe some way to only do this once?
-	fmt.Println(app)
-	fmt.Println(namespace)
 
 	release, err := client.GetReleaseWebhook(context.Background(), config.Project, config.Cluster, app, namespace)
 
@@ -431,7 +429,7 @@ func updateBuildWithAgent(updateAgent *deploy.DeployAgent, client *api.Client) e
 				ID:     "build",
 				Name:   "Build",
 				Index:  110,
-				Status: api.EventStatusInProgress,
+				Status: api.EventStatusFailed,
 				Info:   err.Error(),
 			}, release.WebhookToken)
 		}
@@ -447,7 +445,20 @@ func updateBuildWithAgent(updateAgent *deploy.DeployAgent, client *api.Client) e
 				ID:     "build",
 				Name:   "Build",
 				Index:  120,
-				Status: api.EventStatusInProgress,
+				Status: api.EventStatusFailed,
+				Info:   err.Error(),
+			}, release.WebhookToken)
+		}
+		return err
+	}
+
+	if err := updateAgent.Build(); err != nil {
+		if stream {
+			updateAgent.StreamEvent(api.Event{
+				ID:     "build",
+				Name:   "Build",
+				Index:  130,
+				Status: api.EventStatusFailed,
 				Info:   err.Error(),
 			}, release.WebhookToken)
 		}
@@ -458,13 +469,13 @@ func updateBuildWithAgent(updateAgent *deploy.DeployAgent, client *api.Client) e
 		updateAgent.StreamEvent(api.Event{
 			ID:     "build",
 			Name:   "Build",
-			Index:  130,
+			Index:  140,
 			Status: api.EventStatusSuccess,
 			Info:   "",
 		}, release.WebhookToken)
 	}
 
-	return updateAgent.Build()
+	return nil
 }
 
 func updatePushWithAgent(updateAgent *deploy.DeployAgent) error {

+ 3 - 0
dashboard/src/main/home/cluster-dashboard/expanded-chart/ExpandedChart.tsx

@@ -33,6 +33,7 @@ import useAuth from "shared/auth/useAuth";
 import TitleSection from "components/TitleSection";
 import { integrationList } from "shared/common";
 import DeploymentType from "./DeploymentType";
+import DeployStatus from "./status/DeployStatus";
 
 type Props = {
   namespace: string;
@@ -367,6 +368,7 @@ const ExpandedChart: React.FC<Props> = (props) => {
                   <Spinner src={loadingSrc} />
                 </Header>
               </TextWrap>
+              <DeployStatus chart={chart} />
             </Placeholder>
           );
         }
@@ -381,6 +383,7 @@ const ExpandedChart: React.FC<Props> = (props) => {
                 Navigate to the "Actions" tab of your GitHub repo to view live
                 build logs.
               </TextWrap>
+              <DeployStatus chart={chart} />
             </Placeholder>
           );
         } else {

+ 125 - 0
dashboard/src/main/home/cluster-dashboard/expanded-chart/status/DeployStatus.tsx

@@ -0,0 +1,125 @@
+import React, { useEffect, useState, useContext } from "react";
+import api from "shared/api";
+import { Context } from "shared/Context";
+import { ChartType } from "../../../../../shared/types";
+import { filter } from "d3-array";
+import { render } from "react-dom";
+
+const REFRESH_TIME = 1000; // SHOULD BE MADE HIGHER!
+
+interface Event {
+  event_id: string;
+  index: number;
+  info: string;
+  name: string;
+  status: number;
+  time: number;
+}
+
+interface Props {
+  chart: ChartType;
+}
+
+const DeployStatus: React.FC<Props> = (props) => {
+  const [shouldRequest, setShouldRequest] = useState(true);
+  const [eventData, setEventData] = useState([]);
+  const { currentCluster, currentProject } = useContext(Context);
+
+  // sort by index, ensure sequence is monotonically increasing by time, collapse by id
+  const filterData = (data: Event[]) => {
+    data = data.sort((a, b) => a.index - b.index);
+
+    let pref = 1;
+    while (pref < data.length) {
+      if (data[pref].time < data[pref - 1].time) {
+        break;
+      }
+      pref += 1;
+    }
+    if (data.length == 0) pref = 0;
+
+    data = data.slice(0, pref);
+
+    data.push({
+      event_id: "",
+      index: 0,
+      info: "",
+      name: "",
+      status: 0,
+      time: 0,
+    });
+
+    const fin: Event[] = [];
+    for (let i = 0; i < data.length - 1; ++i) {
+      if (data[i].event_id != data[i + 1].event_id) {
+        fin.push(data[i]);
+      }
+    }
+
+    setEventData(fin);
+  };
+
+  useEffect(() => {
+    const id = window.setInterval(() => {
+      if (!shouldRequest) return;
+      setShouldRequest(false);
+      api
+        .getReleaseSteps(
+          "<token>",
+          {
+            cluster_id: currentCluster.id,
+            namespace: props.chart.namespace,
+          },
+          {
+            id: currentProject.id,
+            name: props.chart.name,
+          }
+        )
+        .then((data) => {
+          filterData(data.data);
+        })
+        .catch((err) => {})
+        .finally(() => {
+          setShouldRequest(true);
+        });
+    }, REFRESH_TIME);
+    return () => {
+      window.clearInterval(id);
+    };
+  }, []);
+
+  const renderEvent = (ev: Event) => {
+    return (
+      <tr>
+        <td>{ev.name}</td>
+        <td>{ev.time}</td>
+        <td>
+          {ev.status == 1
+            ? "Success"
+            : ev.status == 2
+            ? "In Progress"
+            : "Failed"}
+        </td>
+      </tr>
+    );
+  };
+
+  return eventData.length ? (
+    <table>
+      <thead>
+        <td>Name</td>
+        <td>Time</td>
+        <td>Status</td>
+      </thead>
+      <tbody>
+        {eventData.map((ev) => (
+          <React.Fragment key={ev.index}>{renderEvent(ev)}</React.Fragment>
+        ))}
+      </tbody>
+    </table>
+  ) : (
+    <React.Fragment />
+  );
+};
+
+export default DeployStatus;

+ 11 - 0
dashboard/src/shared/api.tsx

@@ -678,6 +678,16 @@ const getReleaseToken = baseApi<
   return `/api/projects/${pathParams.id}/releases/${pathParams.name}/webhook_token`;
 });
 
+const getReleaseSteps = baseApi<
+  {
+    namespace: string;
+    cluster_id: number;
+  },
+  { name: string; id: number }
+>("GET", (pathParams) => {
+  return `/api/projects/${pathParams.id}/releases/${pathParams.name}/steps`;
+});
+
 const destroyEKS = baseApi<
   {
     eks_name: string;
@@ -1109,6 +1119,7 @@ export default {
   getPrometheusIsInstalled,
   getRegistryIntegrations,
   getReleaseToken,
+  getReleaseSteps,
   getRepoIntegrations,
   getSlackIntegrations,
   getRepos,

+ 2 - 3
internal/models/event.go

@@ -2,7 +2,6 @@ package models
 
 import (
 	"gorm.io/gorm"
-	"time"
 )
 
 type EventStatus int64
@@ -37,7 +36,7 @@ type SubEventExternal struct {
 	Index   int64       `json:"index"`
 	Status  EventStatus `json:"status"`
 	Info    string      `json:"info"`
-	Time    time.Time   `json:"time""`
+	Time    int64       `json:"time""`
 }
 
 func (event *SubEvent) Externalize() SubEventExternal {
@@ -47,6 +46,6 @@ func (event *SubEvent) Externalize() SubEventExternal {
 		Index:   event.Index,
 		Status:  event.Status,
 		Info:    event.Info,
-		Time:    event.UpdatedAt,
+		Time:    event.UpdatedAt.Unix(),
 	}
 }

+ 0 - 1
internal/repository/gorm/event.go

@@ -1,7 +1,6 @@
 package gorm
 
 import (
-	"fmt"
 	"github.com/porter-dev/porter/internal/models"
 	"github.com/porter-dev/porter/internal/repository"
 	"gorm.io/gorm"