Skip to content

Commit

Permalink
DBZ-8502: Fix pipeline log URL (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
indraraj authored Dec 12, 2024
1 parent 5a24d95 commit 26dfdd6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
23 changes: 8 additions & 15 deletions src/pages/Pipeline/PipelineLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -48,17 +48,14 @@ const PipelineLog: FC<PipelineLogProps> = ({
// Set to track unique logs
const logSet = new Set<string>();


const [isLogLoading, setIsLogLoading] = useState<boolean>(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
// };
Expand All @@ -68,7 +65,6 @@ const PipelineLog: FC<PipelineLogProps> = ({
// ws.onclose = () => {
// console.log("WebSocket connection closed");
// };

// return () => {
// if (ws.readyState === WebSocket.OPEN) {
// ws.close();
Expand All @@ -78,10 +74,8 @@ const PipelineLog: FC<PipelineLogProps> = ({

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");
Expand All @@ -94,9 +88,10 @@ const PipelineLog: FC<PipelineLogProps> = ({
});

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");
Expand Down Expand Up @@ -126,17 +121,14 @@ const PipelineLog: FC<PipelineLogProps> = ({
})
.catch((error) => console.error("Error fetching initial logs:", error));


// Cleanup
// Cleanup
return () => {
if (ws && ws.readyState === WebSocket.OPEN) {
ws.close();
}
};
}, []);



const downloadLogFile = async (
pipelineId: string | undefined,
pipelineName: string
Expand All @@ -155,7 +147,7 @@ const PipelineLog: FC<PipelineLogProps> = ({

// 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) {
Expand Down Expand Up @@ -214,6 +206,7 @@ const PipelineLog: FC<PipelineLogProps> = ({
};
}, []);

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const onExpandClick = (_event: React.MouseEvent<HTMLElement>) => {
const element = document.querySelector(
"#pipeline-log-view"
Expand Down
Empty file.
4 changes: 2 additions & 2 deletions src/pages/Pipeline/Pipelines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 26dfdd6

Please sign in to comment.