From 26dfdd6eed94ec3f22f65967273f6f3971697b36 Mon Sep 17 00:00:00 2001 From: Indra Date: Thu, 12 Dec 2024 15:18:06 +0530 Subject: [PATCH] DBZ-8502: Fix pipeline log URL (#35) --- src/pages/Pipeline/PipelineLog.tsx | 23 ++++++++--------------- src/pages/Pipeline/PipelineLogView.tsx | 0 src/pages/Pipeline/Pipelines.tsx | 4 ++-- src/utils/constants.ts | 2 -- 4 files changed, 10 insertions(+), 19 deletions(-) delete mode 100644 src/pages/Pipeline/PipelineLogView.tsx diff --git a/src/pages/Pipeline/PipelineLog.tsx b/src/pages/Pipeline/PipelineLog.tsx index 6c7b3a000..d927a886c 100644 --- a/src/pages/Pipeline/PipelineLog.tsx +++ b/src/pages/Pipeline/PipelineLog.tsx @@ -8,7 +8,7 @@ import { } from "@patternfly/react-core"; import { DownloadIcon, ExpandIcon } from "@patternfly/react-icons"; import { LogViewer, LogViewerSearch } from "@patternfly/react-log-viewer"; -import { LOG_URL } from "@utils/constants"; +import { API_URL } from "@utils/constants"; import { FC, useEffect, useState } from "react"; import "./PipelineLog.css"; import { useNotification } from "@appContext/AppNotificationContext"; @@ -48,17 +48,14 @@ const PipelineLog: FC = ({ // Set to track unique logs const logSet = new Set(); - const [isLogLoading, setIsLogLoading] = useState(false); const [isFullScreen, setIsFullScreen] = useState(false); // useEffect(() => { // const ws = new WebSocket("ws://localhost:8080/api/pipelines/1/logs/stream"); - // ws.onopen = () => { // console.log("WebSocket connection opened"); // }; - // ws.onmessage = (event) => { // setLogs((prevLogs) => prevLogs + "\n" + event.data); // Append new logs // }; @@ -68,7 +65,6 @@ const PipelineLog: FC = ({ // ws.onclose = () => { // console.log("WebSocket connection closed"); // }; - // return () => { // if (ws.readyState === WebSocket.OPEN) { // ws.close(); @@ -78,10 +74,8 @@ const PipelineLog: FC = ({ useEffect(() => { let ws: WebSocket; - - // Fetch initial logs via HTTP - fetch("http://localhost:8080/api/pipelines/1/logs") + fetch(`${API_URL}/api/pipelines/${pipelineId}/logs`) .then((response) => response.text()) .then((initialLogs) => { const initialLogLines = initialLogs.split("\n"); @@ -94,9 +88,10 @@ const PipelineLog: FC = ({ }); setLogs((prevLogs) => [...prevLogs, ...initialLogLines]); - + // open WebSocket for real-time updates - ws = new WebSocket("ws://localhost:8080/api/pipelines/1/logs/stream"); + const webSocketURL = API_URL.replace(/^https?/, "ws") + ws = new WebSocket(`${webSocketURL}/api/pipelines/${pipelineId}/logs/stream`); ws.onmessage = (event) => { const newLogs = event.data.split("\n"); @@ -126,8 +121,7 @@ const PipelineLog: FC = ({ }) .catch((error) => console.error("Error fetching initial logs:", error)); - - // Cleanup + // Cleanup return () => { if (ws && ws.readyState === WebSocket.OPEN) { ws.close(); @@ -135,8 +129,6 @@ const PipelineLog: FC = ({ }; }, []); - - const downloadLogFile = async ( pipelineId: string | undefined, pipelineName: string @@ -155,7 +147,7 @@ const PipelineLog: FC = ({ // Fetch the file as a Blob const response = await fetchFile( - `${LOG_URL}/api/pipelines/${pipelineId}/logs` + `${API_URL}/api/pipelines/${pipelineId}/logs` ); if ("error" in response) { @@ -214,6 +206,7 @@ const PipelineLog: FC = ({ }; }, []); + // eslint-disable-next-line @typescript-eslint/no-unused-vars const onExpandClick = (_event: React.MouseEvent) => { const element = document.querySelector( "#pipeline-log-view" diff --git a/src/pages/Pipeline/PipelineLogView.tsx b/src/pages/Pipeline/PipelineLogView.tsx deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/pages/Pipeline/Pipelines.tsx b/src/pages/Pipeline/Pipelines.tsx index 4d19ac584..e3c801295 100644 --- a/src/pages/Pipeline/Pipelines.tsx +++ b/src/pages/Pipeline/Pipelines.tsx @@ -46,7 +46,7 @@ import { } from "@patternfly/react-table"; import _ from "lodash"; import { useQuery } from "react-query"; -import { API_URL, LOG_URL } from "../../utils/constants"; +import { API_URL } from "../../utils/constants"; import { ReactNode, useCallback, useState } from "react"; import SourceField from "../../components/SourceField"; import DestinationField from "../../components/DestinationField"; @@ -124,7 +124,7 @@ const Pipelines: React.FunctionComponent = () => { // Fetch the file as a Blob const response = await fetchFile( - `${LOG_URL}/api/pipelines/${pipelineId}/logs` + `${API_URL}/api/pipelines/${pipelineId}/logs` ); if ("error" in response) { diff --git a/src/utils/constants.ts b/src/utils/constants.ts index e9f76423e..e4c614b2d 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -4,10 +4,8 @@ import { getBackendUrl } from "src/config"; export const AppBranding = "Stage"; const backendBaseUrl = getBackendUrl(); -const pipelineLogUrl = "http://localhost:8080"; export const API_URL = backendBaseUrl; -export const LOG_URL = pipelineLogUrl; export const MAX_RESULTS = 10; export const DEFAULT_TIMEOUT = 5000;