Forráskód Böngészése

committing changes so far

Feroze Mohideen 2 éve
szülő
commit
2bfad4e96d

+ 11 - 2
api/types/incident.go

@@ -140,8 +140,17 @@ type GetRevisionValuesRequest struct {
 }
 
 type LogLine struct {
-	Timestamp *time.Time `json:"timestamp"`
-	Line      string     `json:"line"`
+	Timestamp *time.Time  `json:"timestamp"`
+	Line      string      `json:"line"`
+	Metadata  LogMetadata `json:"metadata"`
+}
+
+type LogMetadata struct {
+	PodName      string `json:"pod_name"`
+	PodNamespace string `json:"pod_namespace"`
+	Revision     string `json:"revision"`
+	OutputStream string `json:"output_stream"`
+	AppName      string `json:"app_name"`
 }
 
 type GetLogResponse struct {

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

@@ -14,7 +14,7 @@ import TitleSection from "components/TitleSection";
 import api from "shared/api";
 import Modal from "main/home/modals/Modal";
 import time from "assets/time.svg";
-import { Direction, Log, parseLogs } from "./logs/useAgentLogs";
+import { Direction, PorterLog, parseLogs } from "./useAgentLogs";
 import { Context } from "shared/Context";
 import dayjs from "dayjs";
 import Anser from "anser";
@@ -25,7 +25,7 @@ type Props = {
 };
 
 interface ExpandedIncidentLogsProps {
-  logs: Log[];
+  logs: PorterLog[];
 }
 
 const ExpandedIncidentLogs = ({ logs }: ExpandedIncidentLogsProps) => {
@@ -74,7 +74,7 @@ const ExpandedIncidentLogs = ({ logs }: ExpandedIncidentLogsProps) => {
 const EventList: React.FC<Props> = ({ filters, namespace }) => {
   const { currentProject, currentCluster } = useContext(Context);
   const [events, setEvents] = useState([]);
-  const [logs, setLogs] = useState<Log[]>([]);
+  const [logs, setLogs] = useState<PorterLog[]>([]);
   const [expandedEvent, setExpandedEvent] = useState(null);
   const [expandedIncidentEvents, setExpandedIncidentEvents] = useState(null);
   const [isLoading, setIsLoading] = useState(true);

+ 1 - 1
dashboard/src/main/home/app-dashboard/expanded-app/activity-feed/events/focus-views/BuildFailureEventFocusView.tsx

@@ -6,7 +6,7 @@ import styled from "styled-components";
 import Anser, { AnserJsonEntry } from "anser";
 import JSZip from "jszip";
 import dayjs from "dayjs";
-import { Log as LogType } from "../../../logs/useAgentLogs";
+import { PorterLog as LogType } from "../../../useAgentLogs";
 import { PorterAppEvent } from "shared/types";
 import Text from "components/porter/Text";
 import { readableDate } from "shared/string_utils";

+ 33 - 28
dashboard/src/main/home/app-dashboard/expanded-app/logs/useAgentLogs.ts

@@ -18,23 +18,31 @@ export enum Direction {
   backward = "backward",
 }
 
-export interface Log {
+export interface PorterLog {
   line: AnserJsonEntry[];
   lineNumber: number;
   timestamp?: string;
 }
 
-const LogSchema = z.object({
+const AgentLogMetadataSchema = z.object({
+  pod_name: z.string(),
+  pod_namespace: z.string(),
+  revision: z.string(),
+  output_stream: z.string(),
+  app_name: z.string(),
+});
+
+const AgentLogSchema = z.object({
   line: z.string(),
   timestamp: z.string(),
+  metadata: AgentLogMetadataSchema.optional(),
 });
+type AgentLog = z.infer<typeof AgentLogSchema>;
 
-type LogLine = z.infer<typeof LogSchema>;
-
-export const parseLogs = (logs: any[] = []): Log[] => {
-  return logs.filter(Boolean).map((log: any, idx) => {
+export const parseLogs = (logs: any[] = []): PorterLog[] => {
+  return logs.map((log: any, idx) => {
     try {
-      const parsed: LogLine = LogSchema.parse(log);
+      const parsed: AgentLog = AgentLogSchema.parse(log);
 
       // TODO Move log parsing to the render method
       const ansiLog = Anser.ansiToJson(parsed.line);
@@ -44,14 +52,8 @@ export const parseLogs = (logs: any[] = []): Log[] => {
         timestamp: parsed.timestamp,
       };
     } catch (err) {
-      console.log(err)
-      // return {
-      //   line: Anser.ansiToJson(log),
-      //   lineNumber: idx + 1,
-      //   timestamp: undefined,
-      // };
       return {
-        line: log,
+        line: Anser.ansiToJson(log),
         lineNumber: idx + 1,
         timestamp: undefined,
       }
@@ -76,11 +78,11 @@ export const useLogs = (
   setDate?: Date
 ) => {
   const isLive = !setDate;
-  const logsBufferRef = useRef<Log[]>([]);
+  const logsBufferRef = useRef<PorterLog[]>([]);
   const { currentCluster, currentProject, setCurrentError } = useContext(
     Context
   );
-  const [logs, setLogs] = useState<Log[]>([]);
+  const [logs, setLogs] = useState<PorterLog[]>([]);
   const [paginationInfo, setPaginationInfo] = useState<PaginationInfo>({
     previousCursor: null,
     nextCursor: null,
@@ -110,7 +112,7 @@ export const useLogs = (
   } = useWebsockets();
 
   const updateLogs = (
-    newLogs: Log[],
+    newLogs: PorterLog[],
     direction: Direction = Direction.forward
   ) => {
     // Nothing to update here
@@ -176,7 +178,7 @@ export const useLogs = (
     logsBufferRef.current = [];
   };
 
-  const pushLogs = (newLogs: Log[]) => {
+  const pushLogs = (newLogs: PorterLog[]) => {
     logsBufferRef.current.push(...newLogs);
 
     if (logsBufferRef.current.length >= MAX_BUFFER_LOGS) {
@@ -209,15 +211,18 @@ export const useLogs = (
         if (evt.data == null) {
           return;
         }
-        console.log("here is the data", evt)
-        const newLogs = parseLogs(
-          [{
-            line: evt.data,
-            timestamp: evt.timeStamp.toString(),
-          }]
-        );
-
-        pushLogs(newLogs);
+        const jsonData = evt.data.trim().split("\n")
+        const newLogs: any[] = [];
+        jsonData.forEach((data: string) => {
+          try {
+            const jsonLog = JSON.parse(data);
+            newLogs.push(jsonLog)
+          } catch (err) {
+            console.log(err)
+            console.log(evt.data)
+          }
+        });
+        pushLogs(parseLogs(newLogs));
       },
       onclose: () => {
         console.log("Closed websocket:", websocketKey);
@@ -234,7 +239,7 @@ export const useLogs = (
     direction: Direction,
     limit: number = QUERY_LIMIT
   ): Promise<{
-    logs: Log[];
+    logs: PorterLog[];
     previousCursor: string | null;
     nextCursor: string | null;
   }> => {

+ 2 - 2
dashboard/src/main/home/app-dashboard/expanded-app/status/AppEventModal.tsx

@@ -1,7 +1,7 @@
 import React, { useEffect, useRef } from "react";
 import Modal from "components/porter/Modal";
 import TitleSection from "components/TitleSection";
-import { Log } from "../logs/useAgentLogs";
+import { PorterLog } from "../useAgentLogs";
 import Text from "components/porter/Text";
 import danger from "assets/danger.svg";
 
@@ -13,7 +13,7 @@ import styled from "styled-components";
 import time from "assets/time.svg";
 
 interface AppEventModalProps {
-    logs: Log[];
+    logs: PorterLog[];
     setModalVisible: (x: boolean) => void;
     porterAppName: string;
     timestamp: string;

+ 2 - 2
dashboard/src/main/home/app-dashboard/expanded-app/status/ExpandedIncidentLogs.tsx

@@ -1,5 +1,5 @@
 import { useEffect, useRef, useState } from "react";
-import { Log } from "../logs/useAgentLogs";
+import { PorterLog } from "../useAgentLogs";
 import React from "react";
 import styled from "styled-components";
 import Loading from "components/Loading";
@@ -7,7 +7,7 @@ import dayjs from "dayjs";
 import Anser from "anser";
 
 interface ExpandedIncidentLogsProps {
-  logs: Log[];
+  logs: PorterLog[];
 }
 
 const ExpandedIncidentLogs: React.FC<ExpandedIncidentLogsProps> = ({ logs }: ExpandedIncidentLogsProps) => {

+ 3 - 3
dashboard/src/main/home/app-dashboard/expanded-app/status/GHALogsModal.tsx

@@ -2,7 +2,7 @@ import React, { useEffect, useRef, useState } from "react";
 import styled from "styled-components";
 import Modal from "components/porter/Modal";
 import TitleSection from "components/TitleSection";
-import { Log } from "../logs/useAgentLogs";
+import { PorterLog } from "../useAgentLogs";
 import Loading from "components/Loading";
 import Text from "components/porter/Text";
 import danger from "assets/danger.svg";
@@ -14,14 +14,14 @@ import Spacer from "components/porter/Spacer";
 import Checkbox from "components/porter/Checkbox";
 type Props = {
   appData: any;
-  logs: Log[];
+  logs: PorterLog[];
   modalVisible: boolean;
   setModalVisible: (x: boolean) => void;
   actionRunId?: string;
 };
 
 interface ExpandedIncidentLogsProps {
-  logs: Log[];
+  logs: PorterLog[];
 }
 
 const GHALogsModal: React.FC<Props> = ({

+ 2 - 2
dashboard/src/main/home/app-dashboard/expanded-app/status/LogsModal.tsx

@@ -1,14 +1,14 @@
 import React, { useEffect, useRef } from "react";
 import Modal from "components/porter/Modal";
 import TitleSection from "components/TitleSection";
-import { Log } from "../logs/useAgentLogs";
+import { PorterLog } from "../useAgentLogs";
 import Text from "components/porter/Text";
 import danger from "assets/danger.svg";
 
 import ExpandedIncidentLogs from "./ExpandedIncidentLogs";
 
 interface LogsModalProps {
-    logs: Log[];
+    logs: PorterLog[];
     setModalVisible: (x: boolean) => void;
     logsName: string;
 }