-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Logs UI] Add dataset filter to ML module setup screen (#64470)
This adds the ability to filter the datasets to be processed by the ML jobs on the setup screen.
- Loading branch information
1 parent
ccede29
commit 39e31d6
Showing
26 changed files
with
991 additions
and
271 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
x-pack/plugins/infra/common/http_api/log_analysis/validation/datasets.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,44 @@ | ||
/* | ||
* 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 * as rt from 'io-ts'; | ||
|
||
export const LOG_ANALYSIS_VALIDATE_DATASETS_PATH = | ||
'/api/infra/log_analysis/validation/log_entry_datasets'; | ||
|
||
/** | ||
* Request types | ||
*/ | ||
export const validateLogEntryDatasetsRequestPayloadRT = rt.type({ | ||
data: rt.type({ | ||
indices: rt.array(rt.string), | ||
timestampField: rt.string, | ||
startTime: rt.number, | ||
endTime: rt.number, | ||
}), | ||
}); | ||
|
||
export type ValidateLogEntryDatasetsRequestPayload = rt.TypeOf< | ||
typeof validateLogEntryDatasetsRequestPayloadRT | ||
>; | ||
|
||
/** | ||
* Response types | ||
* */ | ||
const logEntryDatasetsEntryRT = rt.strict({ | ||
indexName: rt.string, | ||
datasets: rt.array(rt.string), | ||
}); | ||
|
||
export const validateLogEntryDatasetsResponsePayloadRT = rt.type({ | ||
data: rt.type({ | ||
datasets: rt.array(logEntryDatasetsEntryRT), | ||
}), | ||
}); | ||
|
||
export type ValidateLogEntryDatasetsResponsePayload = rt.TypeOf< | ||
typeof validateLogEntryDatasetsResponsePayloadRT | ||
>; |
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
88 changes: 88 additions & 0 deletions
88
...ents/logging/log_analysis_setup/initial_configuration_step/index_setup_dataset_filter.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,88 @@ | ||
/* | ||
* 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 { | ||
EuiFilterButton, | ||
EuiFilterGroup, | ||
EuiPopover, | ||
EuiPopoverTitle, | ||
EuiSelectable, | ||
EuiSelectableOption, | ||
} from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import React, { useCallback, useMemo } from 'react'; | ||
import { DatasetFilter } from '../../../../../common/log_analysis'; | ||
import { useVisibilityState } from '../../../../utils/use_visibility_state'; | ||
|
||
export const IndexSetupDatasetFilter: React.FC<{ | ||
availableDatasets: string[]; | ||
datasetFilter: DatasetFilter; | ||
isDisabled?: boolean; | ||
onChangeDatasetFilter: (datasetFilter: DatasetFilter) => void; | ||
}> = ({ availableDatasets, datasetFilter, isDisabled, onChangeDatasetFilter }) => { | ||
const { isVisible, hide, show } = useVisibilityState(false); | ||
|
||
const changeDatasetFilter = useCallback( | ||
(options: EuiSelectableOption[]) => { | ||
const selectedDatasets = options | ||
.filter(({ checked }) => checked === 'on') | ||
.map(({ label }) => label); | ||
|
||
onChangeDatasetFilter( | ||
selectedDatasets.length === 0 | ||
? { type: 'includeAll' } | ||
: { type: 'includeSome', datasets: selectedDatasets } | ||
); | ||
}, | ||
[onChangeDatasetFilter] | ||
); | ||
|
||
const selectableOptions: EuiSelectableOption[] = useMemo( | ||
() => | ||
availableDatasets.map(datasetName => ({ | ||
label: datasetName, | ||
checked: | ||
datasetFilter.type === 'includeSome' && datasetFilter.datasets.includes(datasetName) | ||
? 'on' | ||
: undefined, | ||
})), | ||
[availableDatasets, datasetFilter] | ||
); | ||
|
||
const datasetFilterButton = ( | ||
<EuiFilterButton disabled={isDisabled} isSelected={isVisible} onClick={show}> | ||
<FormattedMessage | ||
id="xpack.infra.analysisSetup.indexDatasetFilterIncludeAllButtonLabel" | ||
defaultMessage="{includeType, select, includeAll {All datasets} includeSome {{includedDatasetCount, plural, one {# dataset} other {# datasets}}}}" | ||
values={{ | ||
includeType: datasetFilter.type, | ||
includedDatasetCount: | ||
datasetFilter.type === 'includeSome' ? datasetFilter.datasets.length : 0, | ||
}} | ||
/> | ||
</EuiFilterButton> | ||
); | ||
|
||
return ( | ||
<EuiFilterGroup> | ||
<EuiPopover | ||
button={datasetFilterButton} | ||
closePopover={hide} | ||
isOpen={isVisible} | ||
panelPaddingSize="none" | ||
> | ||
<EuiSelectable onChange={changeDatasetFilter} options={selectableOptions} searchable> | ||
{(list, search) => ( | ||
<div> | ||
<EuiPopoverTitle>{search}</EuiPopoverTitle> | ||
{list} | ||
</div> | ||
)} | ||
</EuiSelectable> | ||
</EuiPopover> | ||
</EuiFilterGroup> | ||
); | ||
}; |
Oops, something went wrong.