From 9e339c55ef3458a1abc011070390c2a05a2a057e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Fern=C3=A1ndez=20G=C3=B3mez?= Date: Thu, 6 Aug 2020 17:47:13 +0200 Subject: [PATCH] Pass time range to ML links --- .../analyze_in_ml_button.tsx | 20 +++++++++++++------ .../setup_flyout/module_list.tsx | 5 +++++ .../setup_flyout/module_list_card.tsx | 9 +++------ 3 files changed, 22 insertions(+), 12 deletions(-) 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' ? (