diff --git a/x-pack/plugins/infra/public/components/logging/log_analysis_results/analyze_in_ml_button.tsx b/x-pack/plugins/infra/public/components/logging/log_analysis_results/analyze_in_ml_button.tsx index 3e54920160c5..052e5dd6866f 100644 --- a/x-pack/plugins/infra/public/components/logging/log_analysis_results/analyze_in_ml_button.tsx +++ b/x-pack/plugins/infra/public/components/logging/log_analysis_results/analyze_in_ml_button.tsx @@ -11,10 +11,12 @@ import { encode } from 'rison-node'; import { TimeRange } from '../../../../common/http_api/shared/time_range'; import { useLinkProps, LinkDescriptor } from '../../../hooks/use_link_props'; +type DatemathRange = TimeRange & { startTime: string; endTime: string }; + export const AnalyzeInMlButton: React.FunctionComponent<{ jobId: string; partition?: string; - timeRange: TimeRange; + timeRange: DatemathRange; }> = ({ jobId, partition, timeRange }) => { const linkProps = useLinkProps( typeof partition === 'string' @@ -42,7 +44,7 @@ export const AnalyzeInMlButton: React.FunctionComponent<{ export const getOverallAnomalyExplorerLinkDescriptor = ( jobId: string, - timeRange: TimeRange + timeRange: DatemathRange ): LinkDescriptor => { const { from, to } = convertTimeRangeToParams(timeRange); @@ -65,7 +67,7 @@ export const getOverallAnomalyExplorerLinkDescriptor = ( export const getEntitySpecificSingleMetricViewerLink = ( jobId: string, - timeRange: TimeRange, + timeRange: DatemathRange, entities: Record ): LinkDescriptor => { const { from, to } = convertTimeRangeToParams(timeRange); @@ -94,9 +96,15 @@ export const getEntitySpecificSingleMetricViewerLink = ( }; }; -const convertTimeRangeToParams = (timeRange: TimeRange): { from: string; to: string } => { +const convertTimeRangeToParams = (timeRange: DatemathRange): { from: string; to: string } => { return { - from: new Date(timeRange.startTime).toISOString(), - to: new Date(timeRange.endTime).toISOString(), + from: + typeof timeRange.startTime === 'number' + ? new Date(timeRange.startTime).toISOString() + : timeRange.startTime, + to: + typeof timeRange.endTime === 'number' + ? new Date(timeRange.endTime).toISOString() + : timeRange.endTime, }; }; diff --git a/x-pack/plugins/infra/public/components/logging/log_analysis_setup/setup_flyout/module_list.tsx b/x-pack/plugins/infra/public/components/logging/log_analysis_setup/setup_flyout/module_list.tsx index d7414950b35a..c38db73a0198 100644 --- a/x-pack/plugins/infra/public/components/logging/log_analysis_setup/setup_flyout/module_list.tsx +++ b/x-pack/plugins/infra/public/components/logging/log_analysis_setup/setup_flyout/module_list.tsx @@ -17,6 +17,7 @@ import { } from '../../../../containers/logs/log_analysis/modules/log_entry_rate'; import { LogAnalysisModuleListCard } from './module_list_card'; import type { ModuleId } from './setup_flyout_state'; +import { useLogAnalysisResultsUrlState } from '../../../../pages/logs/log_entry_rate/use_log_entry_rate_results_url_state'; export const LogAnalysisModuleList: React.FC<{ onViewModuleSetup: (module: ModuleId) => void; @@ -31,6 +32,8 @@ export const LogAnalysisModuleList: React.FC<{ jobIds: logEntryCategoriesJobIds, } = useLogEntryCategoriesModuleContext(); + const { timeRange } = useLogAnalysisResultsUrlState(); + const viewLogEntryRateSetupFlyout = useCallback(() => { onViewModuleSetup('logs_ui_analysis'); }, [onViewModuleSetup]); @@ -44,6 +47,7 @@ export const LogAnalysisModuleList: React.FC<{ void; }> = ({ jobId, + timeRange, hasSetupCapabilities, moduleDescription, moduleName, @@ -34,12 +36,7 @@ export const LogAnalysisModuleListCard: React.FC<{ ); - const viewInMlLinkProps = useLinkProps( - getOverallAnomalyExplorerLinkDescriptor(jobId, { - endTime: Date.now(), - startTime: Date.now() - 86400000 * 14, - }) - ); + const viewInMlLinkProps = useLinkProps(getOverallAnomalyExplorerLinkDescriptor(jobId, timeRange)); const moduleSetupButton = moduleStatus.type === 'required' ? (