-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[ML] Stats bar for data frame analytics #49464
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
Changes from 8 commits
8e0dfa7
1b2e26b
f7a1ace
0d6fd83
cc5cb95
8abeadd
50ffc39
5307506
a9cac46
c4603cd
7bd5ad5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,14 @@ import React, { Fragment, FC, useState } from 'react'; | |
|
|
||
| import { i18n } from '@kbn/i18n'; | ||
|
|
||
| import { EuiButtonEmpty, EuiCallOut, EuiEmptyPrompt } from '@elastic/eui'; | ||
| import { | ||
| EuiButtonEmpty, | ||
| EuiCallOut, | ||
| EuiEmptyPrompt, | ||
| EuiFlexGroup, | ||
| EuiFlexItem, | ||
| EuiSpacer, | ||
| } from '@elastic/eui'; | ||
|
|
||
| import { DataFrameAnalyticsId, useRefreshAnalyticsList } from '../../../../common'; | ||
| import { checkPermission } from '../../../../../privilege/check_privilege'; | ||
|
|
@@ -22,7 +29,6 @@ import { | |
| Query, | ||
| Clause, | ||
| } from './common'; | ||
| import { ActionDispatchers } from '../../hooks/use_create_analytics_form/actions'; | ||
| import { getAnalyticsFactory } from '../../services/analytics_service'; | ||
| import { getColumns } from './columns'; | ||
| import { ExpandedRow } from './expanded_row'; | ||
|
|
@@ -33,6 +39,9 @@ import { | |
| SortDirection, | ||
| SORT_DIRECTION, | ||
| } from '../../../../../components/ml_in_memory_table'; | ||
| import { AnalyticStatsBarStats, StatsBar } from '../../../../../components/stats_bar'; | ||
| import { RefreshAnalyticsListButton } from '../refresh_analytics_list_button'; | ||
| import { CreateAnalyticsButton } from '../create_analytics_button'; | ||
|
|
||
| function getItemIdToExpandedRowMap( | ||
| itemIds: DataFrameAnalyticsId[], | ||
|
|
@@ -59,23 +68,25 @@ function stringMatch(str: string | undefined, substr: string) { | |
| } | ||
|
|
||
| interface Props { | ||
| isManagementTable?: boolean; | ||
| allowCreate?: boolean; | ||
| isMlEnabledInSpace?: boolean; | ||
| blockRefresh?: boolean; | ||
| openCreateJobModal?: ActionDispatchers['openModal']; | ||
| createAnalyticsForm?: any; | ||
| } | ||
| // isManagementTable - for use in Kibana managagement ML section | ||
| export const DataFrameAnalyticsList: FC<Props> = ({ | ||
| isManagementTable = false, | ||
| allowCreate = true, | ||
| isMlEnabledInSpace = true, | ||
| blockRefresh = false, | ||
| openCreateJobModal, | ||
| createAnalyticsForm, | ||
| }) => { | ||
| const [isInitialized, setIsInitialized] = useState(false); | ||
| const [isLoading, setIsLoading] = useState(false); | ||
| const [filterActive, setFilterActive] = useState(false); | ||
|
|
||
| const [analytics, setAnalytics] = useState<DataFrameAnalyticsListRow[]>([]); | ||
| const [analyticsStats, setAnalyticsStats] = useState<AnalyticStatsBarStats | undefined>( | ||
| undefined | ||
| ); | ||
| const [filteredAnalytics, setFilteredAnalytics] = useState<DataFrameAnalyticsListRow[]>([]); | ||
| const [expandedRowItemIds, setExpandedRowItemIds] = useState<DataFrameAnalyticsId[]>([]); | ||
|
|
||
|
|
@@ -94,10 +105,12 @@ export const DataFrameAnalyticsList: FC<Props> = ({ | |
|
|
||
| const getAnalytics = getAnalyticsFactory( | ||
| setAnalytics, | ||
| setAnalyticsStats, | ||
| setErrorMessage, | ||
| setIsInitialized, | ||
| blockRefresh | ||
| ); | ||
|
|
||
| // Subscribe to the refresh observable to trigger reloading the analytics list. | ||
| useRefreshAnalyticsList({ | ||
| isLoading: setIsLoading, | ||
|
|
@@ -213,9 +226,12 @@ export const DataFrameAnalyticsList: FC<Props> = ({ | |
| </h2> | ||
| } | ||
| actions={ | ||
| !isManagementTable && openCreateJobModal !== undefined | ||
| !allowCreate | ||
| ? [ | ||
| <EuiButtonEmpty onClick={openCreateJobModal} isDisabled={disabled}> | ||
| <EuiButtonEmpty | ||
| onClick={createAnalyticsForm.actions.openModal} | ||
| isDisabled={disabled} | ||
| > | ||
| {i18n.translate('xpack.ml.dataFrame.analyticsList.emptyPromptButtonText', { | ||
| defaultMessage: 'Create your first data frame analytics job', | ||
| })} | ||
|
|
@@ -232,7 +248,7 @@ export const DataFrameAnalyticsList: FC<Props> = ({ | |
| const columns = getColumns( | ||
| expandedRowItemIds, | ||
| setExpandedRowItemIds, | ||
| isManagementTable, | ||
| allowCreate, | ||
|
||
| isMlEnabledInSpace | ||
| ); | ||
|
|
||
|
|
@@ -310,7 +326,28 @@ export const DataFrameAnalyticsList: FC<Props> = ({ | |
|
|
||
| return ( | ||
| <Fragment> | ||
| <ProgressBar isLoading={isLoading} /> | ||
| <EuiFlexGroup justifyContent="spaceBetween"> | ||
| <EuiFlexItem grow={false}> | ||
| {analyticsStats && ( | ||
| <EuiFlexItem grow={false}> | ||
| <StatsBar stats={analyticsStats} dataTestSub={'mlAnalyticsStatsBar'} /> | ||
| </EuiFlexItem> | ||
| )} | ||
| </EuiFlexItem> | ||
| <EuiFlexItem grow={false}> | ||
| <EuiFlexGroup alignItems="center" gutterSize="s"> | ||
| <EuiFlexItem grow={false}> | ||
| <RefreshAnalyticsListButton /> | ||
| </EuiFlexItem> | ||
| {allowCreate && ( | ||
| <EuiFlexItem grow={false}> | ||
| <CreateAnalyticsButton {...createAnalyticsForm} /> | ||
| </EuiFlexItem> | ||
| )} | ||
| </EuiFlexGroup> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| <EuiSpacer size="s" /> | ||
| <MlInMemoryTable | ||
| allowNeutralSort={false} | ||
| className="mlAnalyticsTable" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,29 +4,22 @@ | |
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import React, { Fragment, FC, useState } from 'react'; | ||
| import React, { FC, Fragment, useState } from 'react'; | ||
|
|
||
| import { FormattedMessage } from '@kbn/i18n/react'; | ||
| import { i18n } from '@kbn/i18n'; | ||
|
|
||
| import { | ||
| EuiBetaBadge, | ||
| EuiFlexGroup, | ||
| EuiFlexItem, | ||
| EuiPage, | ||
| EuiPageBody, | ||
| EuiPageContentBody, | ||
| EuiPageContentHeader, | ||
| EuiPageContentHeaderSection, | ||
| EuiPanel, | ||
| EuiSpacer, | ||
| EuiTitle, | ||
| EuiPageHeader, | ||
| EuiPageHeaderSection, | ||
| } from '@elastic/eui'; | ||
|
|
||
| import { NavigationMenu } from '../../../components/navigation_menu'; | ||
| import { CreateAnalyticsButton } from './components/create_analytics_button'; | ||
| import { DataFrameAnalyticsList } from './components/analytics_list'; | ||
| import { RefreshAnalyticsListButton } from './components/refresh_analytics_list_button'; | ||
| import { useRefreshInterval } from './components/analytics_list/use_refresh_interval'; | ||
| import { useCreateAnalyticsForm } from './hooks/use_create_analytics_form'; | ||
|
|
||
|
|
@@ -42,8 +35,8 @@ export const Page: FC = () => { | |
| <NavigationMenu tabId="data_frame_analytics" /> | ||
| <EuiPage data-test-subj="mlPageDataFrameAnalytics"> | ||
| <EuiPageBody> | ||
| <EuiPageContentHeader> | ||
| <EuiPageContentHeaderSection> | ||
| <EuiPageHeader> | ||
| <EuiPageHeaderSection> | ||
| <EuiTitle> | ||
| <h1> | ||
| <FormattedMessage | ||
|
|
@@ -67,29 +60,12 @@ export const Page: FC = () => { | |
| /> | ||
| </h1> | ||
| </EuiTitle> | ||
| </EuiPageContentHeaderSection> | ||
| <EuiPageContentHeaderSection> | ||
| <EuiFlexGroup alignItems="center"> | ||
| {/* grow={false} fixes IE11 issue with nested flex */} | ||
| <EuiFlexItem grow={false}> | ||
| <RefreshAnalyticsListButton /> | ||
| </EuiFlexItem> | ||
| {/* grow={false} fixes IE11 issue with nested flex */} | ||
| <EuiFlexItem grow={false}> | ||
| <CreateAnalyticsButton {...createAnalyticsForm} /> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| </EuiPageContentHeaderSection> | ||
| </EuiPageContentHeader> | ||
| <EuiPageContentBody> | ||
| <EuiSpacer size="l" /> | ||
| <EuiPanel> | ||
| <DataFrameAnalyticsList | ||
| blockRefresh={blockRefresh} | ||
| openCreateJobModal={createAnalyticsForm.actions.openModal} | ||
| /> | ||
| </EuiPanel> | ||
| </EuiPageContentBody> | ||
| </EuiPageHeaderSection> | ||
| </EuiPageHeader> | ||
| <DataFrameAnalyticsList | ||
| blockRefresh={blockRefresh} | ||
| createAnalyticsForm={createAnalyticsForm} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to move
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's the first thing I tried, but
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, makes sense, let's leave it as it is then. |
||
| /> | ||
| </EuiPageBody> | ||
| </EuiPage> | ||
| </Fragment> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* | ||
| * 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 { GetDataFrameAnalyticsStatsResponseOk } from '../../../../../services/ml_api_service'; | ||
| import { getAnalyticsJobsStats } from './get_analytics'; | ||
| import { DATA_FRAME_TASK_STATE } from '../../components/analytics_list/common'; | ||
|
|
||
| jest.mock('ui/index_patterns', () => ({ | ||
| validateIndexPattern: () => true, | ||
| })); | ||
|
|
||
| describe('get_analytics', () => { | ||
| test('should get analytics jobs stats', () => { | ||
| // arrange | ||
| const mockResponse: GetDataFrameAnalyticsStatsResponseOk = { | ||
| count: 2, | ||
| data_frame_analytics: [ | ||
| { | ||
| id: 'outlier-cloudwatch', | ||
| state: DATA_FRAME_TASK_STATE.STOPPED, | ||
| progress: [ | ||
| { | ||
| phase: 'reindexing', | ||
| progress_percent: 0, | ||
| }, | ||
| { | ||
| phase: 'loading_data', | ||
| progress_percent: 0, | ||
| }, | ||
| { | ||
| phase: 'analyzing', | ||
| progress_percent: 0, | ||
| }, | ||
| { | ||
| phase: 'writing_results', | ||
| progress_percent: 0, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| id: 'reg-gallery', | ||
| state: DATA_FRAME_TASK_STATE.FAILED, | ||
| progress: [ | ||
| { | ||
| phase: 'reindexing', | ||
| progress_percent: 0, | ||
| }, | ||
| { | ||
| phase: 'loading_data', | ||
| progress_percent: 0, | ||
| }, | ||
| { | ||
| phase: 'analyzing', | ||
| progress_percent: 0, | ||
| }, | ||
| { | ||
| phase: 'writing_results', | ||
| progress_percent: 0, | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| // act and assert | ||
| expect(getAnalyticsJobsStats(mockResponse)).toEqual({ | ||
| total: { | ||
| label: 'Total analytics jobs', | ||
| value: 2, | ||
| show: true, | ||
| }, | ||
| started: { | ||
| label: 'Running', | ||
| value: 0, | ||
| show: true, | ||
| }, | ||
| stopped: { | ||
| label: 'Stopped', | ||
| value: 1, | ||
| show: true, | ||
| }, | ||
| failed: { | ||
| label: 'Failed', | ||
| value: 1, | ||
| show: true, | ||
| }, | ||
| }); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.