diff --git a/web/frontend/src/components/Run/RunningStatus/EndpointCharts/RunEndpointCharts.js b/web/frontend/src/components/Run/RunningStatus/EndpointCharts/RunEndpointCharts.js index b0a2f379..53c7dd27 100644 --- a/web/frontend/src/components/Run/RunningStatus/EndpointCharts/RunEndpointCharts.js +++ b/web/frontend/src/components/Run/RunningStatus/EndpointCharts/RunEndpointCharts.js @@ -14,45 +14,36 @@ import { import { orderBy } from "lodash"; import React, { useEffect, useState } from "react"; -import { fetchMetrics } from "../../../../lib/api/endpoints/runMetric"; import PageSpinner from "../../../layout/PageSpinner"; import HitsErrorsLabelLine from "./HitsErrorsLabelLine"; -const RunEndpointsCharts = ({ run, labelToShowGraph }) => { - const defaultTimeInterval = 5; - const showLabels = true; +const RunEndpointsCharts = ({ + run, + metrics, + isLoading, + labelToShowGraph, + setTimeInterval +}) => { const [runMetrics, setRunMetrics] = useState([]); const [copyRunMetrics, setCopyRunMetrics] = useState([]); const [labelsToShow, setLabelsToShow] = useState([labelToShowGraph]); - const [timeInterval, setTimeInterval] = useState(defaultTimeInterval); - const [isLoading, setIsLoading] = useState(false); const [excludedPrefix, setExcludedPrefix] = useState("UJ"); const [excludedPrefixes, setExcludedPrefixes] = useState([]); + const [currentTimeInterval, setCurrentTimeInterval] = useState(5); - const updateRunMetrics = async (runIdToFetch) => { - setIsLoading(true); - const metrics = await fetchMetrics(runIdToFetch, timeInterval, showLabels); - + useEffect(() => { setRunMetrics(metrics); setCopyRunMetrics(metrics); - setIsLoading(false); - }; - - useEffect(() => { - updateRunMetrics(run.id); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [run]); + }, [metrics]); const refreshChart = async () => { - let metrics = []; if (run.runStatus === "RUNNING") { - metrics = await fetchMetrics(run.id, timeInterval, showLabels); + setRunMetrics(metrics); } else { - metrics = copyRunMetrics; + setRunMetrics(copyRunMetrics); setExcludedPrefixes([]); } - - setRunMetrics(metrics); }; const labels = orderBy( @@ -112,6 +103,10 @@ const RunEndpointsCharts = ({ run, labelToShowGraph }) => { setLabelsToShow([]); }; + const handleOnTimeIntervalChange = (value) => { + setTimeInterval(value); + setCurrentTimeInterval(value); + }; return (
{isLoading ? ( @@ -127,8 +122,8 @@ const RunEndpointsCharts = ({ run, labelToShowGraph }) => { mode="single" style={{ width: "100px" }} placeholder="Choose time interval" - defaultValue={defaultTimeInterval} - onChange={(value) => setTimeInterval(value)} + defaultValue={currentTimeInterval} + onChange={handleOnTimeIntervalChange} > 1 sec 5 sec diff --git a/web/frontend/src/components/Run/RunningStatus/MetricsHandler/MetricsHandler.js b/web/frontend/src/components/Run/RunningStatus/MetricsHandler/MetricsHandler.js index 86000a08..8ef90f61 100644 --- a/web/frontend/src/components/Run/RunningStatus/MetricsHandler/MetricsHandler.js +++ b/web/frontend/src/components/Run/RunningStatus/MetricsHandler/MetricsHandler.js @@ -8,6 +8,7 @@ import { calculateErrorRate } from "../../../../lib/utils"; const MetricsHandler = ({ run, children }) => { const [runMetrics, setMetrics] = useState([]); + const [runMetricsRaw, setRawMetrics] = useState([]); const [errorCodes, setErrorCodes] = useState([]); const [isLoading, setIsLoading] = useState(false); const [totals, setTotals] = useState({ @@ -21,13 +22,19 @@ const MetricsHandler = ({ run, children }) => { totalCount: 0, totalRpm: 0 }); + const [timeInterval, setTimeInterval] = useState(5); const refreshInterval = 5000; const timerRef = useRef(null); const updateRunMetrics = async (runIdToFetch) => { setIsLoading(true); - const metricsRes = await fetchMetrics(runIdToFetch, 0, true); + const metricsZeroInterval = await fetchMetrics(runIdToFetch, 0, true); + const metricsTimeInterval = await fetchMetrics( + runIdToFetch, + timeInterval, + true + ); const getRpm = (minDatetime, maxDatetime, totalCount) => { const dateDuration = moment.duration(maxDatetime.diff(minDatetime)); @@ -37,7 +44,7 @@ const MetricsHandler = ({ run, children }) => { return parseFloat((totalCount / diffInSeconds) * 60).toFixed(0); }; - const formattedUrlMetrics = metricsRes.map( + const formattedUrlMetrics = metricsZeroInterval.map( ({ minDatetime, maxDatetime, @@ -71,6 +78,7 @@ const MetricsHandler = ({ run, children }) => { } ); + setRawMetrics(metricsTimeInterval); setMetrics(formattedUrlMetrics); setIsLoading(false); }; @@ -161,7 +169,7 @@ const MetricsHandler = ({ run, children }) => { useEffect(() => { updateRunMetrics(run.id); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [run.id]); + }, [run.id, timeInterval]); useEffect(() => { calculateTotals(); @@ -173,7 +181,14 @@ const MetricsHandler = ({ run, children }) => { // eslint-disable-next-line react-hooks/exhaustive-deps }, [runMetrics, run.runStatus]); - return children(runMetrics, isLoading, totals, errorCodes); + return children( + runMetrics, + runMetricsRaw, + isLoading, + totals, + errorCodes, + setTimeInterval + ); }; export default MetricsHandler; diff --git a/web/frontend/src/components/Run/RunningStatus/RunRunningStatus.js b/web/frontend/src/components/Run/RunningStatus/RunRunningStatus.js index b3662857..2a951158 100644 --- a/web/frontend/src/components/Run/RunningStatus/RunRunningStatus.js +++ b/web/frontend/src/components/Run/RunningStatus/RunRunningStatus.js @@ -100,7 +100,14 @@ const RunRunningStatus = ({ run }) => { return ( - {(metrics, isLoading, totals, errorCodes) => ( + {( + metrics, + rawMetrics, + isLoading, + totals, + errorCodes, + setTimeInterval + ) => ( navigate(-1)} @@ -213,7 +220,10 @@ const RunRunningStatus = ({ run }) => { > setTimeInterval(value)} /> ) : ( @@ -222,7 +232,12 @@ const RunRunningStatus = ({ run }) => { key="endpoints" disabled={!isRunMetricsAvailable} > - + setTimeInterval(value)} + /> )}