diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/ml/anomaly_detection/anomalies_table.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/ml/anomaly_detection/anomalies_table.tsx deleted file mode 100644 index 1ff21f6e2e729..0000000000000 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/ml/anomaly_detection/anomalies_table.tsx +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import React from 'react'; -// import { useState } from 'react'; -// import moment from 'moment'; -// import { useMetricsHostsAnomaliesResults } from '../../../hooks/use_metrics_hosts_anomalies'; -// import { useMetricsK8sAnomaliesResults } from '../../../hooks/use_metrics_k8s_anomalies'; - -export const AnomaliesTable = () => { - // const [start] = useState(moment().toDate().getTime()); - - // const SORT_DEFAULTS = { - // direction: 'desc' as const, - // field: 'anomalyScore' as const, - // }; - - // const PAGINATION_DEFAULTS = { - // pageSize: 25, - // }; - - // const { - // isLoadingMetricsHostsAnomalies, - // metricsHostsAnomalies, - // page, - // fetchNextPage, - // fetchPreviousPage, - // changeSortOptions, - // changePaginationOptions, - // sortOptions, - // paginationOptions, - // } = useMetricsHostsAnomaliesResults({ - // sourceId: 'default', - // startTime: moment(new Date(start)).subtract(10, 'd').toDate().getTime(), - // endTime: start, - // defaultSortOptions: SORT_DEFAULTS, - // defaultPaginationOptions: PAGINATION_DEFAULTS, - // }); - - // const { isLoadingMetricsK8sAnomalies, metricsK8sAnomalies } = useMetricsK8sAnomaliesResults({ - // sourceId: 'default', - // startTime: moment(new Date(start)).subtract(10, 'd').toDate().getTime(), - // endTime: start, - // defaultSortOptions: SORT_DEFAULTS, - // defaultPaginationOptions: PAGINATION_DEFAULTS, - // }); - - // console.log('metricsHostsAnomalies', metricsHostsAnomalies); - // console.log('metricsK8sAnomalies', metricsK8sAnomalies); - return
; -}; diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/ml/anomaly_detection/flyout_home.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/ml/anomaly_detection/flyout_home.tsx index 31672d50968a3..3f4f3b74903cb 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/ml/anomaly_detection/flyout_home.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/ml/anomaly_detection/flyout_home.tsx @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { useState, useCallback, useEffect } from 'react'; +import React, { useState, useCallback, useEffect, useMemo } from 'react'; import { EuiFlyoutHeader, EuiTitle, EuiFlyoutBody, EuiTabs, EuiTab, EuiSpacer } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiText, EuiFlexGroup, EuiFlexItem, EuiCard, EuiIcon } from '@elastic/eui'; @@ -12,6 +12,7 @@ import { i18n } from '@kbn/i18n'; import { EuiCallOut } from '@elastic/eui'; import { EuiButton } from '@elastic/eui'; import { EuiButtonEmpty } from '@elastic/eui'; +import moment from 'moment'; import { useInfraMLCapabilitiesContext } from '../../../../../../containers/ml/infra_ml_capabilities'; import { SubscriptionSplashContent } from './subscription_splash_content'; import { @@ -21,6 +22,7 @@ import { import { useMetricHostsModuleContext } from '../../../../../../containers/ml/modules/metrics_hosts/module'; import { useMetricK8sModuleContext } from '../../../../../../containers/ml/modules/metrics_k8s/module'; import { LoadingPage } from '../../../../../../components/loading_page'; +import { useLinkProps } from '../../../../../../hooks/use_link_props'; interface Props { hasSetupCapabilities: boolean; @@ -58,9 +60,14 @@ export const FlyoutHome = (props: Props) => { setTab('jobs'); }, []); - const goToAnomalies = useCallback(() => { - setTab('anomalies'); - }, []); + const jobIds = [ + ...(k8sJobSummaries || []).map((k) => k.id), + ...(hostJobSummaries || []).map((h) => h.id), + ]; + const anomaliesUrl = useLinkProps({ + app: 'ml', + pathname: `/explorer?_g=${createResultsUrl(jobIds)}`, + }); useEffect(() => { if (hasInfraMLReadCapabilities) { @@ -105,7 +112,11 @@ export const FlyoutHome = (props: Props) => { id="xpack.infra.ml.anomalyFlyout.jobsTabLabel" /> - + { )} - 0} - hasK8sJobs={k8sJobSummaries.length > 0} - hasSetupCapabilities={props.hasSetupCapabilities} - createHosts={createHosts} - createK8s={createK8s} - /> + {tab === 'jobs' && ( + 0} + hasK8sJobs={k8sJobSummaries.length > 0} + hasSetupCapabilities={props.hasSetupCapabilities} + createHosts={createHosts} + createK8s={createK8s} + /> + )} ); @@ -157,12 +170,10 @@ const JobsEnabledCallout = (props: CalloutProps) => { }); } - // const goToML = useCallback(() => { - // const manageJobsLinkProps = useLinkProps({ - // app: 'ml', - // pathname: '/explorer', - // }); - // }, []) + const manageJobsLinkProps = useLinkProps({ + app: 'ml', + pathname: '/jobs', + }); return ( <> @@ -179,7 +190,7 @@ const JobsEnabledCallout = (props: CalloutProps) => { iconType="check" /> - + { ); }; + +function createResultsUrl(jobIds: string[], mode = 'absolute') { + const idString = jobIds.map((j) => `'${j}'`).join(','); + let path = ''; + + const from = moment().subtract(4, 'weeks').toISOString(); + const to = moment().toISOString(); + + path += `(ml:(jobIds:!(${idString}))`; + path += `,refreshInterval:(display:Off,pause:!f,value:0),time:(from:'${from}'`; + path += `,to:'${to}'`; + if (mode === 'invalid') { + path += `,mode:invalid`; + } + path += "))&_a=(query:(query_string:(analyze_wildcard:!t,query:'*')))"; + + return path; +} diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/ml/anomaly_detection/job_setup_screen.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/ml/anomaly_detection/job_setup_screen.tsx index e5b6a649f298b..730cd7b6e9ef5 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/ml/anomaly_detection/job_setup_screen.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/ml/anomaly_detection/job_setup_screen.tsx @@ -147,7 +147,7 @@ export const JobSetupScreen = (props: Props) => { <>