Explorar o código

chore: track logs by revision

Soham Parekh %!s(int64=3) %!d(string=hai) anos
pai
achega
ab65d110d3

+ 4 - 2
dashboard/src/main/home/cluster-dashboard/expanded-chart/logs-section/LogsSection.tsx

@@ -19,9 +19,10 @@ import DateTimePicker from "components/date-time-picker/DateTimePicker";
 import dayjs from "dayjs";
 import Loading from "components/Loading";
 import _ from "lodash";
+import { ChartType } from "shared/types";
 
 type Props = {
-  currentChart?: any;
+  currentChart?: ChartType;
   isFullscreen: boolean;
   setIsFullscreen: (x: boolean) => void;
 };
@@ -102,7 +103,8 @@ const LogsSection: React.FC<Props> = ({
     podFilter,
     currentChart.namespace,
     enteredSearchText,
-    selectedDate
+    currentChart,
+    selectedDate,
   );
 
   useEffect(() => {

+ 30 - 3
dashboard/src/main/home/cluster-dashboard/expanded-chart/logs-section/useAgentLogs.ts

@@ -5,6 +5,7 @@ import { useContext, useEffect, useRef, useState } from "react";
 import api from "shared/api";
 import { Context } from "shared/Context";
 import { useWebsockets, NewWebsocketOptions } from "shared/hooks/useWebsockets";
+import { ChartType } from "shared/types";
 import { isJSON } from "shared/util";
 
 const MAX_LOGS = 5000;
@@ -57,12 +58,15 @@ export const useLogs = (
   currentPod: string,
   namespace: string,
   searchParam: string,
+  currentChart: ChartType,
   // if setDate is set, results are not live
   setDate?: Date
 ) => {
   const isLive = !setDate;
   const logsBufferRef = useRef<Log[]>([]);
-  const { currentCluster, currentProject } = useContext(Context);
+  const { currentCluster, currentProject, setCurrentError } = useContext(
+    Context
+  );
   const [logs, setLogs] = useState<Log[]>([]);
   const [paginationInfo, setPaginationInfo] = useState<PaginationInfo>({
     previousCursor: null,
@@ -164,7 +168,16 @@ export const useLogs = (
   };
 
   const setupWebsocket = (websocketKey: string) => {
-    const endpoint = `/api/projects/${currentProject.id}/clusters/${currentCluster.id}/namespaces/${namespace}/logs/loki?pod_selector=${currentPod}&namespace=${namespace}&search_param=${searchParam}`;
+    const websocketBaseURL = `/api/projects/${currentProject.id}/clusters/${currentCluster.id}/namespaces/${namespace}/logs/loki`;
+
+    const q = new URLSearchParams({
+      pod_selector: currentPod,
+      namespace,
+      search_param: searchParam,
+      revision: currentChart.version.toString(),
+    }).toString();
+
+    const endpoint = `${websocketBaseURL}?${q}`;
 
     const config: NewWebsocketOptions = {
       onopen: () => {
@@ -196,13 +209,18 @@ export const useLogs = (
     endDate: string,
     direction: Direction,
     limit: number = QUERY_LIMIT
-  ) => {
+  ): Promise<{
+    logs: Log[];
+    previousCursor: string | null;
+    nextCursor: string | null;
+  }> => {
     return api
       .getLogs(
         "<token>",
         {
           pod_selector: currentPod,
           namespace,
+          revision: currentChart.version.toString(),
           search_param: searchParam,
           start_range: startDate,
           end_range: endDate,
@@ -232,6 +250,15 @@ export const useLogs = (
               : res.data.backward_continue_time,
           nextCursor: res.data.forward_continue_time,
         };
+      })
+      .catch((err) => {
+        setCurrentError(err);
+
+        return {
+          logs: [],
+          previousCursor: null,
+          nextCursor: null,
+        };
       });
   };
 

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

@@ -1971,6 +1971,7 @@ const getLogs = baseApi<
     limit?: number;
     start_range?: string;
     end_range?: string;
+    revision?: string;
     pod_selector: string;
     namespace: string;
     search_param?: string;

+ 1 - 0
internal/kubernetes/porter_agent/v2/agent_server.go

@@ -172,6 +172,7 @@ func GetHistoricalLogs(
 
 	vals["pod_selector"] = req.PodSelector
 	vals["namespace"] = req.Namespace
+	vals["revision"] = req.Revision
 
 	if req.SearchParam != "" {
 		vals["search_param"] = req.SearchParam