-
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
[ML] Add indicator if there are stopped partitions in categorization job wizard #75709
Conversation
|
Pinging @elastic/ml-ui (:ml) |
...s/components/pick_fields_step/components/categorization_view/category_stopped_partitions.tsx
Outdated
Show resolved
Hide resolved
peteharverson
left a comment
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.
Tested and looks good. Just added a couple of minor suggestions.
...s/components/pick_fields_step/components/categorization_view/category_stopped_partitions.tsx
Show resolved
Hide resolved
...s/components/pick_fields_step/components/categorization_view/category_stopped_partitions.tsx
Outdated
Show resolved
Hide resolved
| // no need to keep fetching anymore | ||
| if ( | ||
| stoppedPartitionsPreview.length >= NUMBER_OF_PREVIEW && | ||
| _resultsSubscription !== undefined |
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.
can _resultsSubscription.closed be used here?
| // only need to run this check if jobCreator.perPartitionStopOnWarn is turned on | ||
| if (jobCreator.perPartitionCategorization && jobCreator.perPartitionStopOnWarn) { | ||
| // subscribe to result updates | ||
| _resultsSubscription = resultsLoader.subscribeToResults(setResultsWrapper); |
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.
keeping the subscription stored in _resultsSubscription which is not in a hook will mean it is redeclared on every render.
loadCategoryStoppedPartitions could be moved inside this useEffect or hasStoppedPartitions could be changed to stoppedPartitionsCount which blocks the running of the check, rather than unsubscribing early.
I think the counter change will be the simplest.
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.
I ended up using a ref 7a256b6 to make sure _resultsSubscription is not re-declared every time the component renders. Although I can also expose out this._results$ from resultsLoader as well so we can take advantage of other util observable functions if that's better in the long run.
| } | ||
|
|
||
| async function loadCategoryStoppedPartitions() { | ||
| const results = await ml.results.getCategoryStoppedPartitions([jobCreator.jobId]); |
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.
This fires when the job doesn't yet exist, which is fine, but it results in an uncaught error.
This error should be caught. if it's a 404 it can be ignored.
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.
Updated here 676dfff
…d-partitions-preview
…d-partitions-preview
| if ( | ||
| jobCreator.perPartitionCategorization && | ||
| jobCreator.perPartitionStopOnWarn && | ||
| _resultsSubscription?.current |
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.
this check stops the subscription from being created because _resultsSubscription?.current is null initially
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.
Thanks. I removed this whole block and replaced it with the rxjs utils instead here 63a4e02
...s/components/pick_fields_step/components/categorization_view/category_stopped_partitions.tsx
Outdated
Show resolved
Hide resolved
| _resultsSubscription?.current | ||
| ) { | ||
| // subscribe to result updates | ||
| _resultsSubscription.current = resultsLoader.subscribeToResults(setResultsWrapper); |
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.
I'm not sure if you need a reference for the subscription
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.
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.
| _resultsSubscription.current = resultsLoader.subscribeToResults(setResultsWrapper); | |
| resultsLoader.pipe( | |
| switchMap(() => { | |
| // fetch results | |
| return from(ml.results.getCategoryStoppedPartitions([jobCreator.jobId])) | |
| }), | |
| tap(r => { | |
| // update your state here | |
| }), | |
| takeWhile(r => { | |
| return stoppedPartitionsPreview.length , NUMBER_OF_PREVIEW | |
| } | |
| ) |
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.
Thanks I have updated here 63a4e02
jgowdyelastic
left a comment
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.
Added a couple of small comments but generally LGTM
| const [tableRow, setTableRow] = useState<Array<{ partitionName: string }>>([]); | ||
| const [stoppedPartitionsError, setStoppedPartitionsError] = useState<string | undefined>(); | ||
|
|
||
| // using ref so this Subscription instance is only intialized once |
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.
this comment isn't needed anymore
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.
Removed here cc44727
|
|
||
| const loadCategoryStoppedPartitions = useCallback(async () => { | ||
| try { | ||
| const results = await ml.results.getCategoryStoppedPartitions([jobCreator.jobId]); |
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.
nit, this could be { jobs } rather than results
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.
Updated here cc44727
| const resultsSubscription = resultsLoader.results$ | ||
| .pipe( | ||
| switchMap(() => { | ||
| return from(loadCategoryStoppedPartitions()); |
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.
loadCategoryStoppedPartitions depends on jobCreator.jobId, but your useEffect is 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.
...s/components/pick_fields_step/components/categorization_view/category_stopped_partitions.tsx
Outdated
Show resolved
Hide resolved
...s/components/pick_fields_step/components/categorization_view/category_stopped_partitions.tsx
Outdated
Show resolved
Hide resolved
| takeWhile((results) => { | ||
| return !results || (Array.isArray(results) && results.length <= NUMBER_OF_PREVIEW); | ||
| }) |
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.
When I shared a pseudo-code example I missed one point - takeWhile operator should be placed before switchMap where you perform stopped partitions fetching. With a current implementation potentially the stream can perform an unnecessary API call. It is not critical, but worth mentioning. 🙂 Can be improved later.
darnautov
left a comment
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.
Overall code LGTM. Worth extracting the observable part to a hook/function to cover it with some unit tests, to make sure it doesn't perform unnecessary API calls and closes the stream accordingly. You can check out model_memory_estimator tests as example.
peteharverson
left a comment
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.
Tested latest edits and LGTM
💚 Build SucceededBuild metrics@kbn/optimizer bundle module count
async chunks size
distributable file count
History
To update your PR or re-run it, just comment with: |

Summary
Part of #73968 to add an indicator in the categorization job wizard if the categorization status goes to warn for at least one partition. It will only perform the check if

analysis_config.per_partition_categorization.stop_on_warnis set toTrueCurrently, it's showing a preview of 5 stopped partitions maximum, where after it reaches that amount, will stop making calls to retrieve the list.
Checklist
Delete any items that are not applicable to this PR.