-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[ML] Add indicator if there are stopped partitions in categorization job wizard #75709
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 all commits
cf460be
0a53e43
618fa8f
268c13f
7a256b6
676dfff
eb14fc9
39bcf77
63a4e02
e282831
27445b0
ffd49c2
cc44727
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 |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| /* | ||
| * 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, { FC, useContext, useEffect, useState, useMemo, useCallback } from 'react'; | ||
| import { EuiBasicTable, EuiCallOut, EuiSpacer, EuiText } from '@elastic/eui'; | ||
| import { FormattedMessage } from '@kbn/i18n/react'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { from } from 'rxjs'; | ||
| import { switchMap, takeWhile, tap } from 'rxjs/operators'; | ||
| import { JobCreatorContext } from '../../../job_creator_context'; | ||
| import { CategorizationJobCreator } from '../../../../../common/job_creator'; | ||
| import { ml } from '../../../../../../../services/ml_api_service'; | ||
| import { extractErrorProperties } from '../../../../../../../../../common/util/errors'; | ||
|
|
||
| const NUMBER_OF_PREVIEW = 5; | ||
| export const CategoryStoppedPartitions: FC = () => { | ||
| const { jobCreator: jc, resultsLoader } = useContext(JobCreatorContext); | ||
| const jobCreator = jc as CategorizationJobCreator; | ||
| const [tableRow, setTableRow] = useState<Array<{ partitionName: string }>>([]); | ||
| const [stoppedPartitionsError, setStoppedPartitionsError] = useState<string | undefined>(); | ||
|
|
||
| const columns = useMemo( | ||
| () => [ | ||
| { | ||
| field: 'partitionName', | ||
| name: i18n.translate( | ||
| 'xpack.ml.newJob.wizard.pickFieldsStep.stoppedPartitionsPreviewColumnName', | ||
| { | ||
| defaultMessage: 'Stopped partition names', | ||
| } | ||
| ), | ||
| render: (partition: any) => ( | ||
| <EuiText size="s"> | ||
| <code>{partition}</code> | ||
| </EuiText> | ||
| ), | ||
| }, | ||
| ], | ||
| [] | ||
| ); | ||
|
|
||
| const loadCategoryStoppedPartitions = useCallback(async () => { | ||
| try { | ||
| const { jobs } = await ml.results.getCategoryStoppedPartitions([jobCreator.jobId]); | ||
|
|
||
| if ( | ||
| !Array.isArray(jobs) && // if jobs is object of jobId: [partitions] | ||
| Array.isArray(jobs[jobCreator.jobId]) && | ||
| jobs[jobCreator.jobId].length > 0 | ||
| ) { | ||
| return jobs[jobCreator.jobId]; | ||
| } | ||
| } catch (e) { | ||
| const error = extractErrorProperties(e); | ||
| // might get 404 because job has not been created yet and that's ok | ||
| if (error.statusCode !== 404) { | ||
| setStoppedPartitionsError(error.message); | ||
| } | ||
| } | ||
| }, [jobCreator.jobId]); | ||
|
|
||
| useEffect(() => { | ||
| // only need to run this check if jobCreator.perPartitionStopOnWarn is turned on | ||
| if (jobCreator.perPartitionCategorization && jobCreator.perPartitionStopOnWarn) { | ||
| // subscribe to result updates | ||
| const resultsSubscription = resultsLoader.results$ | ||
| .pipe( | ||
| switchMap(() => { | ||
| return from(loadCategoryStoppedPartitions()); | ||
| }), | ||
| tap((results) => { | ||
| if (Array.isArray(results)) { | ||
| setTableRow( | ||
| results.slice(0, NUMBER_OF_PREVIEW).map((partitionName) => ({ | ||
| partitionName, | ||
| })) | ||
| ); | ||
| } | ||
| }), | ||
| takeWhile((results) => { | ||
| return !results || (Array.isArray(results) && results.length <= NUMBER_OF_PREVIEW); | ||
| }) | ||
|
Comment on lines
+83
to
+85
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. When I shared a pseudo-code example I missed one point - |
||
| ) | ||
| .subscribe(); | ||
| return () => resultsSubscription.unsubscribe(); | ||
| } | ||
| }, []); | ||
|
|
||
| return ( | ||
| <> | ||
| {stoppedPartitionsError && ( | ||
| <> | ||
| <EuiSpacer /> | ||
| <EuiCallOut | ||
| color={'danger'} | ||
| size={'s'} | ||
| title={ | ||
| <FormattedMessage | ||
| id="xpack.ml.newJob.wizard.pickFieldsStep.stoppedPartitionsErrorCallout" | ||
| defaultMessage="An error occurred while fetching list of stopped partitions." | ||
| /> | ||
| } | ||
| /> | ||
| </> | ||
| )} | ||
| {Array.isArray(tableRow) && tableRow.length > 0 && ( | ||
| <> | ||
| <EuiSpacer /> | ||
| <div> | ||
| <FormattedMessage | ||
| id="xpack.ml.newJob.wizard.pickFieldsStep.categorizationStoppedPartitionsTitle" | ||
| defaultMessage="Stopped partitions" | ||
| /> | ||
| </div> | ||
| <EuiSpacer size={'s'} /> | ||
| <EuiCallOut | ||
peteharverson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| color={'warning'} | ||
| size={'s'} | ||
| title={ | ||
| <FormattedMessage | ||
| id="xpack.ml.newJob.wizard.pickFieldsStep.stoppedPartitionsExistCallout" | ||
| defaultMessage="Per-partition categorization and stop_on_warn settings are enabled. Some partitions in job '{jobId}' are unsuitable for categorization and have been excluded from further categorization or anomaly detection analysis." | ||
| values={{ | ||
| jobId: jobCreator.jobId, | ||
| }} | ||
| /> | ||
| } | ||
| /> | ||
| <EuiBasicTable columns={columns} items={tableRow} /> | ||
| </> | ||
| )} | ||
| </> | ||
| ); | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loadCategoryStoppedPartitionsdepends onjobCreator.jobId, but youruseEffectis only executed once, hence it only gets a reference of the initial callback. It could lead to unexpected behavior.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from my testing jobId is always correct here as this component is recreated when navigating to the summary step and the jobId cannot be changed by the user without navigating away to a previous step.