Skip to content

Commit

Permalink
Pass time range to ML links
Browse files Browse the repository at this point in the history
  • Loading branch information
afgomez authored and Alejandro Fernández Gómez committed Aug 6, 2020
1 parent 80859ff commit 9e339c5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -42,7 +44,7 @@ export const AnalyzeInMlButton: React.FunctionComponent<{

export const getOverallAnomalyExplorerLinkDescriptor = (
jobId: string,
timeRange: TimeRange
timeRange: DatemathRange
): LinkDescriptor => {
const { from, to } = convertTimeRangeToParams(timeRange);

Expand All @@ -65,7 +67,7 @@ export const getOverallAnomalyExplorerLinkDescriptor = (

export const getEntitySpecificSingleMetricViewerLink = (
jobId: string,
timeRange: TimeRange,
timeRange: DatemathRange,
entities: Record<string, string>
): LinkDescriptor => {
const { from, to } = convertTimeRangeToParams(timeRange);
Expand Down Expand Up @@ -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,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +32,8 @@ export const LogAnalysisModuleList: React.FC<{
jobIds: logEntryCategoriesJobIds,
} = useLogEntryCategoriesModuleContext();

const { timeRange } = useLogAnalysisResultsUrlState();

const viewLogEntryRateSetupFlyout = useCallback(() => {
onViewModuleSetup('logs_ui_analysis');
}, [onViewModuleSetup]);
Expand All @@ -44,6 +47,7 @@ export const LogAnalysisModuleList: React.FC<{
<EuiFlexItem>
<LogAnalysisModuleListCard
jobId={logEntryRateJobIds['log-entry-rate']}
timeRange={timeRange}
hasSetupCapabilities={hasLogAnalysisSetupCapabilities}
moduleDescription={logEntryRateModule.moduleDescription}
moduleName={logEntryRateModule.moduleName}
Expand All @@ -54,6 +58,7 @@ export const LogAnalysisModuleList: React.FC<{
<EuiFlexItem>
<LogAnalysisModuleListCard
jobId={logEntryCategoriesJobIds['log-entry-categories-count']}
timeRange={timeRange}
hasSetupCapabilities={hasLogAnalysisSetupCapabilities}
moduleDescription={logEntryCategoriesModule.moduleDescription}
moduleName={logEntryCategoriesModule.moduleName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import { getOverallAnomalyExplorerLinkDescriptor } from '../../log_analysis_resu

export const LogAnalysisModuleListCard: React.FC<{
jobId: string;
timeRange: { startTime: string; endTime: string };
hasSetupCapabilities: boolean;
moduleDescription: string;
moduleName: string;
moduleStatus: SetupStatus;
onViewSetup: () => void;
}> = ({
jobId,
timeRange,
hasSetupCapabilities,
moduleDescription,
moduleName,
Expand All @@ -34,12 +36,7 @@ export const LogAnalysisModuleListCard: React.FC<{
<EuiIcon color="secondary" size="xxl" type="check" />
);

const viewInMlLinkProps = useLinkProps(
getOverallAnomalyExplorerLinkDescriptor(jobId, {
endTime: Date.now(),
startTime: Date.now() - 86400000 * 14,
})
);
const viewInMlLinkProps = useLinkProps(getOverallAnomalyExplorerLinkDescriptor(jobId, timeRange));

const moduleSetupButton =
moduleStatus.type === 'required' ? (
Expand Down

0 comments on commit 9e339c5

Please sign in to comment.