mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-14 14:43:46 +00:00
parent
ac358be877
commit
a2150b4a78
21229
ui/package-lock.json
generated
21229
ui/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -11,6 +11,7 @@
|
|||||||
"@types/node": "^12.20.10",
|
"@types/node": "^12.20.10",
|
||||||
"@types/react": "^17.0.3",
|
"@types/react": "^17.0.3",
|
||||||
"@types/react-dom": "^17.0.3",
|
"@types/react-dom": "^17.0.3",
|
||||||
|
"axios": "^0.21.1",
|
||||||
"node-sass": "^5.0.0",
|
"node-sass": "^5.0.0",
|
||||||
"numeral": "^2.0.6",
|
"numeral": "^2.0.6",
|
||||||
"protobuf-decoder": "^0.1.0",
|
"protobuf-decoder": "^0.1.0",
|
||||||
|
@ -4,6 +4,7 @@ import styles from './style/HarEntriesList.module.sass';
|
|||||||
import spinner from './assets/spinner.svg';
|
import spinner from './assets/spinner.svg';
|
||||||
import ScrollableFeed from "react-scrollable-feed";
|
import ScrollableFeed from "react-scrollable-feed";
|
||||||
import {StatusType} from "./HarFilters";
|
import {StatusType} from "./HarFilters";
|
||||||
|
import Api from "../helpers/api";
|
||||||
|
|
||||||
interface HarEntriesListProps {
|
interface HarEntriesListProps {
|
||||||
entries: any[];
|
entries: any[];
|
||||||
@ -25,6 +26,8 @@ enum FetchOperator {
|
|||||||
GT = "gt"
|
GT = "gt"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const api = new Api();
|
||||||
|
|
||||||
export const HarEntriesList: React.FC<HarEntriesListProps> = ({entries, setEntries, focusedEntryId, setFocusedEntryId, connectionOpen, noMoreDataTop, setNoMoreDataTop, noMoreDataBottom, setNoMoreDataBottom, methodsFilter, statusFilter, pathFilter}) => {
|
export const HarEntriesList: React.FC<HarEntriesListProps> = ({entries, setEntries, focusedEntryId, setFocusedEntryId, connectionOpen, noMoreDataTop, setNoMoreDataTop, noMoreDataBottom, setNoMoreDataBottom, methodsFilter, statusFilter, pathFilter}) => {
|
||||||
|
|
||||||
const [loadMoreTop, setLoadMoreTop] = useState(false);
|
const [loadMoreTop, setLoadMoreTop] = useState(false);
|
||||||
@ -54,14 +57,9 @@ export const HarEntriesList: React.FC<HarEntriesListProps> = ({entries, setEntri
|
|||||||
return entries.filter(filterEntries);
|
return entries.filter(filterEntries);
|
||||||
},[entries, filterEntries])
|
},[entries, filterEntries])
|
||||||
|
|
||||||
const fetchData = async (operator, timestamp) => {
|
|
||||||
const response = await fetch(`http://localhost:8899/api/entries?limit=50&operator=${operator}×tamp=${timestamp}`);
|
|
||||||
return await response.json();
|
|
||||||
}
|
|
||||||
|
|
||||||
const getOldEntries = useCallback(async () => {
|
const getOldEntries = useCallback(async () => {
|
||||||
setIsLoadingTop(true);
|
setIsLoadingTop(true);
|
||||||
const data = await fetchData(FetchOperator.LT, entries[0].timestamp);
|
const data = await api.fetchEntries(FetchOperator.LT, entries[0].timestamp);
|
||||||
setLoadMoreTop(false);
|
setLoadMoreTop(false);
|
||||||
|
|
||||||
let scrollTo;
|
let scrollTo;
|
||||||
@ -89,7 +87,7 @@ export const HarEntriesList: React.FC<HarEntriesListProps> = ({entries, setEntri
|
|||||||
}, [loadMoreTop, connectionOpen, noMoreDataTop, getOldEntries]);
|
}, [loadMoreTop, connectionOpen, noMoreDataTop, getOldEntries]);
|
||||||
|
|
||||||
const getNewEntries = async () => {
|
const getNewEntries = async () => {
|
||||||
const data = await fetchData(FetchOperator.GT, entries[entries.length - 1].timestamp);
|
const data = await api.fetchEntries(FetchOperator.GT, entries[entries.length - 1].timestamp);
|
||||||
let scrollTo;
|
let scrollTo;
|
||||||
if(data.length === 0) {
|
if(data.length === 0) {
|
||||||
setNoMoreDataBottom(true);
|
setNoMoreDataBottom(true);
|
||||||
|
@ -9,6 +9,7 @@ import playIcon from './assets/run.svg';
|
|||||||
import pauseIcon from './assets/pause.svg';
|
import pauseIcon from './assets/pause.svg';
|
||||||
import variables from './style/variables.module.scss';
|
import variables from './style/variables.module.scss';
|
||||||
import {StatusBar} from "./StatusBar";
|
import {StatusBar} from "./StatusBar";
|
||||||
|
import Api, {MizuWebsocketURL} from "../helpers/api";
|
||||||
|
|
||||||
const useLayoutStyles = makeStyles(() => ({
|
const useLayoutStyles = makeStyles(() => ({
|
||||||
details: {
|
details: {
|
||||||
@ -39,21 +40,7 @@ interface HarPageProps {
|
|||||||
setAnalyzeStatus: (status: any) => void;
|
setAnalyzeStatus: (status: any) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const mizuAPIPathPrefix = "/mizu";
|
const api = new Api();
|
||||||
|
|
||||||
|
|
||||||
// When working locally (with npm run start) we need to change the PORT
|
|
||||||
const getMizuApiUrl = () => {
|
|
||||||
return `${window.location.origin}${mizuAPIPathPrefix}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getMizuWebsocketUrl = () => {
|
|
||||||
return `ws://${window.location.host}${mizuAPIPathPrefix}/ws`;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const mizuApiUrl = getMizuApiUrl();
|
|
||||||
const mizuWebsocketUrl = getMizuWebsocketUrl();
|
|
||||||
|
|
||||||
export const HarPage: React.FC<HarPageProps> = ({setAnalyzeStatus}) => {
|
export const HarPage: React.FC<HarPageProps> = ({setAnalyzeStatus}) => {
|
||||||
|
|
||||||
@ -75,7 +62,7 @@ export const HarPage: React.FC<HarPageProps> = ({setAnalyzeStatus}) => {
|
|||||||
const ws = useRef(null);
|
const ws = useRef(null);
|
||||||
|
|
||||||
const openWebSocket = () => {
|
const openWebSocket = () => {
|
||||||
ws.current = new WebSocket(mizuWebsocketUrl);
|
ws.current = new WebSocket(MizuWebsocketURL);
|
||||||
ws.current.onopen = () => setConnection(ConnectionStatus.Connected);
|
ws.current.onopen = () => setConnection(ConnectionStatus.Connected);
|
||||||
ws.current.onclose = () => setConnection(ConnectionStatus.Closed);
|
ws.current.onclose = () => setConnection(ConnectionStatus.Closed);
|
||||||
}
|
}
|
||||||
@ -113,24 +100,32 @@ export const HarPage: React.FC<HarPageProps> = ({setAnalyzeStatus}) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
openWebSocket();
|
(async () => {
|
||||||
fetch(`${mizuApiUrl}/api/tapStatus`)
|
openWebSocket();
|
||||||
.then(response => response.json())
|
try{
|
||||||
.then(data => setTappingStatus(data));
|
const tapStatusResponse = await api.tapStatus();
|
||||||
|
setTappingStatus(tapStatusResponse);
|
||||||
fetch(`${mizuApiUrl}/api/analyzeStatus`)
|
const analyzeStatusResponse = await api.analyzeStatus();
|
||||||
.then(response => response.json())
|
setAnalyzeStatus(analyzeStatusResponse);
|
||||||
.then(data => setAnalyzeStatus(data));
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
})()
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!focusedEntryId) return;
|
if (!focusedEntryId) return;
|
||||||
setSelectedHarEntry(null)
|
setSelectedHarEntry(null);
|
||||||
fetch(`${mizuApiUrl}/api/entries/${focusedEntryId}`)
|
(async () => {
|
||||||
.then(response => response.json())
|
try {
|
||||||
.then(data => setSelectedHarEntry(data));
|
const entryData = await api.getEntry(focusedEntryId);
|
||||||
|
setSelectedHarEntry(entryData);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
})()
|
||||||
}, [focusedEntryId])
|
}, [focusedEntryId])
|
||||||
|
|
||||||
const toggleConnection = () => {
|
const toggleConnection = () => {
|
||||||
|
@ -29,12 +29,14 @@ export const StatusBar: React.FC<Props> = ({tappingStatus}) => {
|
|||||||
<div className="podsCount">{`Tapping ${amountOfPods} ${pluralize('pod', amountOfPods)} in ${pluralize('namespace', uniqueNamespaces.length)} ${uniqueNamespaces.join(", ")}`}</div>
|
<div className="podsCount">{`Tapping ${amountOfPods} ${pluralize('pod', amountOfPods)} in ${pluralize('namespace', uniqueNamespaces.length)} ${uniqueNamespaces.join(", ")}`}</div>
|
||||||
{expandedBar && <div style={{marginTop: 20}}>
|
{expandedBar && <div style={{marginTop: 20}}>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<thead>
|
||||||
<th>Pod name</th>
|
<tr>
|
||||||
<th>Namespace</th>
|
<th>Pod name</th>
|
||||||
</tr>
|
<th>Namespace</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{tappingStatus.pods.map(pod => <tr>
|
{tappingStatus.pods.map(pod => <tr key={pod.name}>
|
||||||
<td>{pod.name}</td>
|
<td>{pod.name}</td>
|
||||||
<td>{pod.namespace}</td>
|
<td>{pod.namespace}</td>
|
||||||
</tr>)}
|
</tr>)}
|
||||||
|
45
ui/src/helpers/api.js
Normal file
45
ui/src/helpers/api.js
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import * as axios from "axios";
|
||||||
|
|
||||||
|
const mizuAPIPathPrefix = "/mizu";
|
||||||
|
|
||||||
|
// When working locally (with npm run start) change to:
|
||||||
|
// export const MizuWebsocketURL = `ws://localhost:8899${mizuAPIPathPrefix}/ws`;
|
||||||
|
export const MizuWebsocketURL = `ws://${window.location.host}${mizuAPIPathPrefix}/ws`;
|
||||||
|
|
||||||
|
export default class Api {
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
|
||||||
|
// When working locally (with npm run start) change to:
|
||||||
|
// const apiURL = `http://localhost:8899/${mizuAPIPathPrefix}/api/`;
|
||||||
|
const apiURL = `${window.location.origin}${mizuAPIPathPrefix}/api/`;
|
||||||
|
|
||||||
|
this.client = axios.create({
|
||||||
|
baseURL: apiURL,
|
||||||
|
timeout: 31000,
|
||||||
|
headers: {
|
||||||
|
Accept: "application/json",
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
tapStatus = async () => {
|
||||||
|
const response = await this.client.get("/tapStatus");
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
analyzeStatus = async () => {
|
||||||
|
const response = await this.client.get("/analyzeStatus");
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
getEntry = async (entryId) => {
|
||||||
|
const response = await this.client.get(`/entries/${entryId}`);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchEntries = async (operator, timestamp) => {
|
||||||
|
const response = await this.client.get(`/entries?limit=50&operator=${operator}×tamp=${timestamp}`);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user