Przeglądaj źródła

integrate show logs

Alexander Belanger 3 lat temu
rodzic
commit
cdfd2ddd21

+ 1 - 0
api/types/incident.go

@@ -41,6 +41,7 @@ type IncidentMeta struct {
 	InvolvedObjectKind      InvolvedObjectKind `json:"involved_object_kind" form:"required"`
 	InvolvedObjectKind      InvolvedObjectKind `json:"involved_object_kind" form:"required"`
 	InvolvedObjectName      string             `json:"involved_object_name" form:"required"`
 	InvolvedObjectName      string             `json:"involved_object_name" form:"required"`
 	InvolvedObjectNamespace string             `json:"involved_object_namespace" form:"required"`
 	InvolvedObjectNamespace string             `json:"involved_object_namespace" form:"required"`
+	ShouldViewLogs          bool               `json:"should_view_logs"`
 }
 }
 
 
 type PaginationRequest struct {
 type PaginationRequest struct {

+ 29 - 4
dashboard/src/main/home/cluster-dashboard/expanded-chart/events/EventList.tsx

@@ -63,6 +63,30 @@ const EventList: React.FC<Props> = ({ filters, setLogData }) => {
       });
       });
   }, [expandedEvent]);
   }, [expandedEvent]);
 
 
+  const redirectToLogs = (incident: any) => {
+    api
+      .getIncidentEvents(
+        "<token>",
+        {},
+        {
+          project_id: currentProject.id,
+          cluster_id: currentCluster.id,
+          incident_id: incident.id,
+        }
+      )
+      .then((res) => {
+        let podName = res.data?.events[0]?.pod_name;
+        let timestamp = res.data?.events[0]?.last_seen;
+        let revision = res.data?.events[0]?.revision;
+
+        setLogData({
+          podName,
+          timestamp,
+          revision,
+        });
+      });
+  };
+
   const renderExpandedEventMessage = () => {
   const renderExpandedEventMessage = () => {
     if (!expandedIncidentEvents) {
     if (!expandedIncidentEvents) {
       return <Loading />;
       return <Loading />;
@@ -134,14 +158,15 @@ const EventList: React.FC<Props> = ({ filters, setLogData }) => {
             accessor: "",
             accessor: "",
             width: 30,
             width: 30,
             Cell: ({ row }: CellProps<any>) => {
             Cell: ({ row }: CellProps<any>) => {
+              if (!row.original.should_view_logs) {
+                return null;
+              }
+
               return (
               return (
                 <TableButton
                 <TableButton
                   width="102px"
                   width="102px"
                   onClick={() => {
                   onClick={() => {
-                    setLogData({
-                      podName: "hello",
-                      timestamp: row.original.last_seen,
-                    });
+                    redirectToLogs(row.original);
                   }}
                   }}
                 >
                 >
                   <Icon src={document} />
                   <Icon src={document} />

+ 6 - 1
dashboard/src/main/home/cluster-dashboard/expanded-chart/logs-section/LogsSection.tsx

@@ -23,6 +23,7 @@ import _ from "lodash";
 export type InitLogData = {
 export type InitLogData = {
   podName: string;
   podName: string;
   timestamp: string;
   timestamp: string;
+  revision: string;
 };
 };
 
 
 type Props = {
 type Props = {
@@ -130,7 +131,11 @@ const LogsSection: React.FC<Props> = ({
       )
       )
       .then((res) => {
       .then((res) => {
         setPodFilterOpts(_.uniq(res.data ?? []));
         setPodFilterOpts(_.uniq(res.data ?? []));
-        setPodFilter(res.data[0]);
+
+        // only set pod filter if the current pod is not found in the resulting data
+        if (!res.data?.contains(podFilter)) {
+          setPodFilter(res.data[0]);
+        }
       });
       });
   }, []);
   }, []);