Skip to content

Conversation

@qn895
Copy link
Member

@qn895 qn895 commented Aug 21, 2020

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_warn is set to True
Screen Shot 2020-08-21 at 4 48 11 PM

Currently, 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.

@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@qn895
Copy link
Member Author

qn895 commented Aug 21, 2020

Alternatively, we can also keep fetching the updated list of partitions and show a more accurate count, while keeping the preview small.
Screen Shot 2020-08-21 at 5 04 04 PM

Copy link
Contributor

@peteharverson peteharverson left a 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.

// no need to keep fetching anymore
if (
stoppedPartitionsPreview.length >= NUMBER_OF_PREVIEW &&
_resultsSubscription !== undefined
Copy link
Member

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);
Copy link
Member

@jgowdyelastic jgowdyelastic Aug 25, 2020

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.

Copy link
Member Author

@qn895 qn895 Aug 26, 2020

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]);
Copy link
Member

@jgowdyelastic jgowdyelastic Aug 25, 2020

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated here 676dfff

if (
jobCreator.perPartitionCategorization &&
jobCreator.perPartitionStopOnWarn &&
_resultsSubscription?.current
Copy link
Member

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

Copy link
Member Author

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

_resultsSubscription?.current
) {
// subscribe to result updates
_resultsSubscription.current = resultsLoader.subscribeToResults(setResultsWrapper);
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

You could try to utilize taleUntil or takeWhile operators to stop fetching

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
_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
}
)

Copy link
Member Author

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

Copy link
Member

@jgowdyelastic jgowdyelastic left a 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
Copy link
Member

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

Copy link
Member Author

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]);
Copy link
Member

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

Copy link
Member Author

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());
Copy link
Contributor

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.

Copy link
Member

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.

Comment on lines +87 to +89
takeWhile((results) => {
return !results || (Array.isArray(results) && results.length <= NUMBER_OF_PREVIEW);
})
Copy link
Contributor

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.

Copy link
Contributor

@darnautov darnautov left a 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.

Copy link
Contributor

@peteharverson peteharverson left a 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

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

@kbn/optimizer bundle module count

id value diff baseline
ml 1374 +1 1373

async chunks size

id value diff baseline
ml 8.2MB +15.0KB 8.2MB

distributable file count

id value diff baseline
total 53127 +1 53126

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@qn895 qn895 merged commit 1bd8f41 into elastic:master Aug 27, 2020
@qn895 qn895 deleted the job-wizard-stopped-partitions-preview branch August 27, 2020 18:50
qn895 added a commit to qn895/kibana that referenced this pull request Aug 27, 2020
qn895 added a commit that referenced this pull request Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants