diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/step_details_page/hooks/use_prev_object_metrics.ts b/x-pack/plugins/synthetics/public/apps/synthetics/components/step_details_page/hooks/use_prev_object_metrics.ts index 18f81936aa557..1a5d31415decb 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/step_details_page/hooks/use_prev_object_metrics.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/step_details_page/hooks/use_prev_object_metrics.ts @@ -6,6 +6,8 @@ */ import { useParams } from 'react-router-dom'; +import moment from 'moment'; +import { useJourneySteps } from '../../monitor_details/hooks/use_journey_steps'; import { useReduxEsSearch } from '../../../hooks/use_redux_es_search'; import { SYNTHETICS_INDEX_PATTERN } from '../../../../../../common/constants'; @@ -27,6 +29,10 @@ export const usePreviousObjectMetrics = () => { checkGroupId: string; }>(); + const { data } = useJourneySteps(); + + const timestamp = data?.details?.timestamp; + const { data: prevObjectMetrics } = useReduxEsSearch( { index: SYNTHETICS_INDEX_PATTERN, @@ -48,6 +54,14 @@ export const usePreviousObjectMetrics = () => { query: { bool: { filter: [ + { + range: { + '@timestamp': { + lte: timestamp ?? 'now', + gte: moment(timestamp).subtract(1, 'day').toISOString(), + }, + }, + }, { term: { config_id: monitorId, @@ -107,7 +121,8 @@ export const usePreviousObjectMetrics = () => { }, [stepIndex, monitorId, checkGroupId], { - name: 'previousObjectMetrics', + name: `previousObjectMetrics/${monitorId}/${checkGroupId}/${stepIndex}/`, + isRequestReady: !!timestamp, } ); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/step_details_page/step_objects/color_palette.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/step_details_page/step_objects/color_palette.tsx index 274d0ecbc6d0d..8bc892c254e27 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/step_details_page/step_objects/color_palette.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/step_details_page/step_objects/color_palette.tsx @@ -42,7 +42,7 @@ export const ColorPalette = ({ }) => { const getToolTipContent = () => { return i18n.translate('xpack.synthetics.stepDetails.palette.tooltip', { - defaultMessage: 'Value is {deltaLabel} compared to previous steps in last 24 hours.', + defaultMessage: 'Value is {deltaLabel} compared to steps in previous 24 hours.', values: { deltaLabel: Math.abs(delta) === 0 diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_redux_es_search.ts b/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_redux_es_search.ts index 72715c596e82a..a74af36221a31 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_redux_es_search.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_redux_es_search.ts @@ -23,9 +23,9 @@ export const useReduxEsSearch = < >( params: TParams, fnDeps: any[], - options: { inspector?: IInspectorInfo; name: string } + options: { inspector?: IInspectorInfo; name: string; isRequestReady?: boolean } ) => { - const { name } = options ?? {}; + const { name, isRequestReady = true } = options ?? {}; const { addInspectorRequest } = useInspectorContext(); @@ -35,11 +35,11 @@ export const useReduxEsSearch = < const results = useSelector(selectEsQueryResult); useEffect(() => { - if (params.index) { + if (params.index && isRequestReady) { dispatch(executeEsQueryAction.get({ params, name, addInspectorRequest })); } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [addInspectorRequest, dispatch, name, JSON.stringify(params)]); + }, [addInspectorRequest, dispatch, name, JSON.stringify(params), isRequestReady]); return useMemo(() => { return {