Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Logs UI] Add "View in machine learning" links in the anomaly explorer #74555

Merged
merged 11 commits into from
Aug 19, 2020
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 };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth limiting ourselves to one date representation for simplicity's sake?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm removing this, since the time range is not needed for the job management pages


export const AnalyzeInMlButton: React.FunctionComponent<{
jobId: string;
partition?: string;
timeRange: TimeRange;
timeRange: DatemathRange;
}> = ({ jobId, partition, timeRange }) => {
const linkProps = useLinkProps(
typeof partition === 'string'
Expand All @@ -40,9 +42,9 @@ export const AnalyzeInMlButton: React.FunctionComponent<{
);
};

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

Expand All @@ -65,7 +67,7 @@ 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,13 +17,22 @@ 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;
}> = ({ onViewModuleSetup }) => {
const { hasLogAnalysisSetupCapabilities } = useLogAnalysisCapabilitiesContext();
const { setupStatus: logEntryRateSetupStatus } = useLogEntryRateModuleContext();
const { setupStatus: logEntryCategoriesSetupStatus } = useLogEntryCategoriesModuleContext();
const {
setupStatus: logEntryRateSetupStatus,
jobIds: logEntryRateJobIds,
} = useLogEntryRateModuleContext();
const {
setupStatus: logEntryCategoriesSetupStatus,
jobIds: logEntryCategoriesJobIds,
} = useLogEntryCategoriesModuleContext();

const { timeRange } = useLogAnalysisResultsUrlState();

const viewLogEntryRateSetupFlyout = useCallback(() => {
onViewModuleSetup('logs_ui_analysis');
Expand All @@ -37,6 +46,8 @@ export const LogAnalysisModuleList: React.FC<{
<EuiFlexGroup>
<EuiFlexItem>
<LogAnalysisModuleListCard
jobId={logEntryRateJobIds['log-entry-rate']}
timeRange={timeRange}
hasSetupCapabilities={hasLogAnalysisSetupCapabilities}
moduleDescription={logEntryRateModule.moduleDescription}
moduleName={logEntryRateModule.moduleName}
Expand All @@ -46,6 +57,8 @@ export const LogAnalysisModuleList: React.FC<{
</EuiFlexItem>
<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 @@ -4,26 +4,40 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { EuiCard, EuiIcon } from '@elastic/eui';
import { EuiCard, EuiIcon, EuiButtonEmpty } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import React from 'react';
import { SetupStatus } from '../../../../../common/log_analysis';
import { CreateJobButton, RecreateJobButton } from '../../log_analysis_setup/create_job_button';
import { useLinkProps } from '../../../../hooks/use_link_props';
import { getOverallAnomalyExplorerLinkDescriptor } from '../../log_analysis_results/analyze_in_ml_button';

export const LogAnalysisModuleListCard: React.FC<{
jobId: string;
timeRange: { startTime: string; endTime: string };
hasSetupCapabilities: boolean;
moduleDescription: string;
moduleName: string;
moduleStatus: SetupStatus;
onViewSetup: () => void;
}> = ({ hasSetupCapabilities, moduleDescription, moduleName, moduleStatus, onViewSetup }) => {
}> = ({
jobId,
timeRange,
hasSetupCapabilities,
moduleDescription,
moduleName,
moduleStatus,
onViewSetup,
}) => {
const moduleIcon =
moduleStatus.type === 'required' ? (
<EuiIcon size="xxl" type="machineLearningApp" />
) : (
<EuiIcon color="secondary" size="xxl" type="check" />
);

const viewInMlLinkProps = useLinkProps(getOverallAnomalyExplorerLinkDescriptor(jobId, timeRange));

const moduleSetupButton =
moduleStatus.type === 'required' ? (
<CreateJobButton hasSetupCapabilities={hasSetupCapabilities} onClick={onViewSetup}>
Expand All @@ -33,7 +47,15 @@ export const LogAnalysisModuleListCard: React.FC<{
/>
</CreateJobButton>
) : (
<RecreateJobButton hasSetupCapabilities={hasSetupCapabilities} onClick={onViewSetup} />
<>
<RecreateJobButton hasSetupCapabilities={hasSetupCapabilities} onClick={onViewSetup} />
<EuiButtonEmpty {...viewInMlLinkProps}>
<FormattedMessage
id="xpack.infra.logs.analysy.viewInMlButtonLabel"
afgomez marked this conversation as resolved.
Show resolved Hide resolved
defaultMessage="View in Machine Learning"
/>
</EuiButtonEmpty>
</>
);

return (
Expand Down