-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [ML] Adding bucket span estimator to new wizards * disabling next button when estimating * fixing population
- Loading branch information
1 parent
99141c0
commit 580b1bb
Showing
10 changed files
with
147 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...es/components/pick_fields_step/components/bucket_span_estimator/bucket_span_estimator.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* 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, useEffect } from 'react'; | ||
import { EuiButton } from '@elastic/eui'; | ||
|
||
import { useEstimateBucketSpan, ESTIMATE_STATUS } from './estimate_bucket_span'; | ||
|
||
interface Props { | ||
setEstimating(estimating: boolean): void; | ||
} | ||
|
||
export const BucketSpanEstimator: FC<Props> = ({ setEstimating }) => { | ||
const { status, estimateBucketSpan } = useEstimateBucketSpan(); | ||
|
||
useEffect(() => { | ||
setEstimating(status === ESTIMATE_STATUS.RUNNING); | ||
}, [status]); | ||
|
||
return ( | ||
<EuiButton disabled={status === ESTIMATE_STATUS.RUNNING} onClick={estimateBucketSpan}> | ||
Estimate bucket span | ||
</EuiButton> | ||
); | ||
}; |
70 changes: 70 additions & 0 deletions
70
...ages/components/pick_fields_step/components/bucket_span_estimator/estimate_bucket_span.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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 { useContext, useState } from 'react'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { toastNotifications } from 'ui/notify'; | ||
import { JobCreatorContext } from '../../../job_creator_context'; | ||
import { EVENT_RATE_FIELD_ID } from '../../../../../../../../common/types/fields'; | ||
import { isMultiMetricJobCreator, isPopulationJobCreator } from '../../../../../common/job_creator'; | ||
import { ml } from '../../../../../../../services/ml_api_service'; | ||
import { useKibanaContext } from '../../../../../../../contexts/kibana'; | ||
|
||
export enum ESTIMATE_STATUS { | ||
NOT_RUNNING, | ||
RUNNING, | ||
} | ||
|
||
export function useEstimateBucketSpan() { | ||
const { jobCreator, jobCreatorUpdate } = useContext(JobCreatorContext); | ||
const kibanaContext = useKibanaContext(); | ||
|
||
const [status, setStatus] = useState(ESTIMATE_STATUS.NOT_RUNNING); | ||
|
||
const data = { | ||
aggTypes: jobCreator.aggregations.map(a => a.dslName), | ||
duration: { | ||
start: jobCreator.start, | ||
end: jobCreator.end, | ||
}, | ||
fields: jobCreator.fields.map(f => (f.id === EVENT_RATE_FIELD_ID ? null : f.id)), | ||
index: kibanaContext.currentIndexPattern.title, | ||
query: kibanaContext.combinedQuery, | ||
splitField: | ||
(isMultiMetricJobCreator(jobCreator) || isPopulationJobCreator(jobCreator)) && | ||
jobCreator.splitField !== null | ||
? jobCreator.splitField.id | ||
: undefined, | ||
timeField: kibanaContext.currentIndexPattern.timeFieldName, | ||
}; | ||
|
||
async function estimateBucketSpan() { | ||
setStatus(ESTIMATE_STATUS.RUNNING); | ||
const { name, error, message } = await ml.estimateBucketSpan(data); | ||
setStatus(ESTIMATE_STATUS.NOT_RUNNING); | ||
if (error === true) { | ||
let text = ''; | ||
if (message !== undefined) { | ||
if (typeof message === 'object') { | ||
text = message.msg || JSON.stringify(message); | ||
} else { | ||
text = message; | ||
} | ||
} | ||
toastNotifications.addDanger({ | ||
title: i18n.translate('xpack.ml.newJob.wizard.estimateBucketSpanError', { | ||
defaultMessage: `Bucket span estimation error`, | ||
}), | ||
text, | ||
}); | ||
} else { | ||
jobCreator.bucketSpan = name; | ||
jobCreatorUpdate(); | ||
} | ||
} | ||
return { status, estimateBucketSpan }; | ||
} |
6 changes: 6 additions & 0 deletions
6
...s/new_job_new/pages/components/pick_fields_step/components/bucket_span_estimator/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* 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. | ||
*/ | ||
export { BucketSpanEstimator } from './bucket_span_estimator'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters