-
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.
[8.x] [ML] AiOps: Action for adding Log Pattern embeddable to a dashb…
…oard and case (#199478) (#200021) # Backport This will backport the following commits from `main` to `8.x`: - [[ML] AiOps: Action for adding Log Pattern embeddable to a dashboard and case (#199478)](#199478) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Robert Jaszczurek","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-13T14:56:56Z","message":"[ML] AiOps: Action for adding Log Pattern embeddable to a dashboard and case (#199478)\n\n## Summary\r\n\r\nPart of [#197247](https://github.com/elastic/kibana/issues/197247)\r\n\r\n- Added the ability to add a Log Pattern Embeddable to a dashboard and\r\ncase.\r\n\r\n- Fixed the Change Point Detection embeddable in cases and added a\r\nfunctional test to cover this scenario.\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/d09eccc1-6738-4c8b-9a54-7c78d9ac9017\r\n\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n- [x] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"4ad25cf88df179334db72a593d05ff5bc0e3eb3e","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement",":ml","v9.0.0","Team:ML","Feature:ML/AIOps","backport:version","v8.17.0"],"title":"[ML] AiOps: Action for adding Log Pattern embeddable to a dashboard and case","number":199478,"url":"https://github.com/elastic/kibana/pull/199478","mergeCommit":{"message":"[ML] AiOps: Action for adding Log Pattern embeddable to a dashboard and case (#199478)\n\n## Summary\r\n\r\nPart of [#197247](https://github.com/elastic/kibana/issues/197247)\r\n\r\n- Added the ability to add a Log Pattern Embeddable to a dashboard and\r\ncase.\r\n\r\n- Fixed the Change Point Detection embeddable in cases and added a\r\nfunctional test to cover this scenario.\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/d09eccc1-6738-4c8b-9a54-7c78d9ac9017\r\n\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n- [x] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"4ad25cf88df179334db72a593d05ff5bc0e3eb3e"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199478","number":199478,"mergeCommit":{"message":"[ML] AiOps: Action for adding Log Pattern embeddable to a dashboard and case (#199478)\n\n## Summary\r\n\r\nPart of [#197247](https://github.com/elastic/kibana/issues/197247)\r\n\r\n- Added the ability to add a Log Pattern Embeddable to a dashboard and\r\ncase.\r\n\r\n- Fixed the Change Point Detection embeddable in cases and added a\r\nfunctional test to cover this scenario.\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/d09eccc1-6738-4c8b-9a54-7c78d9ac9017\r\n\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n- [x] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"4ad25cf88df179334db72a593d05ff5bc0e3eb3e"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Robert Jaszczurek <[email protected]>
- Loading branch information
1 parent
55be3c7
commit cdb923b
Showing
22 changed files
with
575 additions
and
34 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
61 changes: 61 additions & 0 deletions
61
x-pack/plugins/aiops/public/cases/log_pattern_attachment.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,61 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public'; | ||
import { memoize } from 'lodash'; | ||
import React from 'react'; | ||
import type { PersistableStateAttachmentViewProps } from '@kbn/cases-plugin/public/client/attachment_framework/types'; | ||
import { FIELD_FORMAT_IDS } from '@kbn/field-formats-plugin/common'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { EuiDescriptionList } from '@elastic/eui'; | ||
import deepEqual from 'fast-deep-equal'; | ||
import type { | ||
PatternAnalysisProps, | ||
PatternAnalysisSharedComponent, | ||
} from '../shared_components/pattern_analysis'; | ||
|
||
export const initComponent = memoize( | ||
(fieldFormats: FieldFormatsStart, PatternAnalysisComponent: PatternAnalysisSharedComponent) => { | ||
return React.memo( | ||
(props: PersistableStateAttachmentViewProps) => { | ||
const { persistableStateAttachmentState } = props; | ||
|
||
const dataFormatter = fieldFormats.deserialize({ | ||
id: FIELD_FORMAT_IDS.DATE, | ||
}); | ||
|
||
const inputProps = persistableStateAttachmentState as unknown as PatternAnalysisProps; | ||
|
||
const listItems = [ | ||
{ | ||
title: ( | ||
<FormattedMessage | ||
id="xpack.aiops.logPatternAnalysis.cases.timeRangeLabel" | ||
defaultMessage="Time range" | ||
/> | ||
), | ||
description: `${dataFormatter.convert( | ||
inputProps.timeRange.from | ||
)} - ${dataFormatter.convert(inputProps.timeRange.to)}`, | ||
}, | ||
]; | ||
|
||
return ( | ||
<> | ||
<EuiDescriptionList compressed type={'inline'} listItems={listItems} /> | ||
<PatternAnalysisComponent {...inputProps} embeddingOrigin={'cases'} /> | ||
</> | ||
); | ||
}, | ||
(prevProps, nextProps) => | ||
deepEqual( | ||
prevProps.persistableStateAttachmentState, | ||
nextProps.persistableStateAttachmentState | ||
) | ||
); | ||
} | ||
); |
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
243 changes: 243 additions & 0 deletions
243
x-pack/plugins/aiops/public/components/log_categorization/attachments_menu.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,243 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { EuiContextMenuProps } from '@elastic/eui'; | ||
import { | ||
EuiButton, | ||
EuiButtonIcon, | ||
EuiContextMenu, | ||
EuiFlexItem, | ||
EuiForm, | ||
EuiFormRow, | ||
EuiPanel, | ||
EuiPopover, | ||
EuiSpacer, | ||
EuiSwitch, | ||
} from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import type { SaveModalDashboardProps } from '@kbn/presentation-util-plugin/public'; | ||
import { | ||
LazySavedObjectSaveModalDashboard, | ||
withSuspense, | ||
} from '@kbn/presentation-util-plugin/public'; | ||
import React, { useCallback, useState } from 'react'; | ||
import { useMemo } from 'react'; | ||
import type { DataView } from '@kbn/data-views-plugin/common'; | ||
import { EMBEDDABLE_PATTERN_ANALYSIS_TYPE } from '@kbn/aiops-log-pattern-analysis/constants'; | ||
import { useTimeRangeUpdates } from '@kbn/ml-date-picker'; | ||
import type { PatternAnalysisEmbeddableState } from '../../embeddables/pattern_analysis/types'; | ||
import type { RandomSamplerOption, RandomSamplerProbability } from './sampling_menu/random_sampler'; | ||
import { useCasesModal } from '../../hooks/use_cases_modal'; | ||
import { useAiopsAppContext } from '../../hooks/use_aiops_app_context'; | ||
|
||
const SavedObjectSaveModalDashboard = withSuspense(LazySavedObjectSaveModalDashboard); | ||
|
||
interface AttachmentsMenuProps { | ||
randomSamplerMode: RandomSamplerOption; | ||
randomSamplerProbability: RandomSamplerProbability; | ||
dataView: DataView; | ||
selectedField?: string; | ||
} | ||
|
||
export const AttachmentsMenu = ({ | ||
randomSamplerMode, | ||
randomSamplerProbability, | ||
dataView, | ||
selectedField, | ||
}: AttachmentsMenuProps) => { | ||
const { | ||
application: { capabilities }, | ||
cases, | ||
embeddable, | ||
} = useAiopsAppContext(); | ||
|
||
const [applyTimeRange, setApplyTimeRange] = useState(false); | ||
|
||
const [dashboardAttachmentReady, setDashboardAttachmentReady] = useState(false); | ||
const [isActionMenuOpen, setIsActionMenuOpen] = useState(false); | ||
|
||
const { create: canCreateCase, update: canUpdateCase } = cases?.helpers?.canUseCases() ?? { | ||
create: false, | ||
update: false, | ||
}; | ||
|
||
const openCasesModalCallback = useCasesModal(EMBEDDABLE_PATTERN_ANALYSIS_TYPE); | ||
|
||
const timeRange = useTimeRangeUpdates(); | ||
|
||
const canEditDashboards = capabilities.dashboard.createNew; | ||
|
||
const onSave: SaveModalDashboardProps['onSave'] = useCallback( | ||
({ dashboardId, newTitle, newDescription }) => { | ||
const stateTransfer = embeddable!.getStateTransfer(); | ||
|
||
const embeddableInput: Partial<PatternAnalysisEmbeddableState> = { | ||
title: newTitle, | ||
description: newDescription, | ||
dataViewId: dataView.id, | ||
fieldName: selectedField, | ||
randomSamplerMode, | ||
randomSamplerProbability, | ||
minimumTimeRangeOption: 'No minimum', | ||
...(applyTimeRange && { timeRange }), | ||
}; | ||
|
||
const state = { | ||
input: embeddableInput, | ||
type: EMBEDDABLE_PATTERN_ANALYSIS_TYPE, | ||
}; | ||
|
||
const path = dashboardId === 'new' ? '#/create' : `#/view/${dashboardId}`; | ||
|
||
stateTransfer.navigateToWithEmbeddablePackage('dashboards', { | ||
state, | ||
path, | ||
}); | ||
}, | ||
[ | ||
embeddable, | ||
dataView.id, | ||
selectedField, | ||
randomSamplerMode, | ||
randomSamplerProbability, | ||
applyTimeRange, | ||
timeRange, | ||
] | ||
); | ||
|
||
const panels = useMemo<EuiContextMenuProps['panels']>(() => { | ||
return [ | ||
{ | ||
id: 'attachMainPanel', | ||
size: 's', | ||
items: [ | ||
...(canEditDashboards | ||
? [ | ||
{ | ||
name: i18n.translate('xpack.aiops.logCategorization.addToDashboardTitle', { | ||
defaultMessage: 'Add to dashboard', | ||
}), | ||
panel: 'attachToDashboardPanel', | ||
'data-test-subj': 'aiopsLogPatternAnalysisAttachToDashboardButton', | ||
}, | ||
] | ||
: []), | ||
...(canUpdateCase || canCreateCase | ||
? [ | ||
{ | ||
name: i18n.translate('xpack.aiops.logCategorization.attachToCaseLabel', { | ||
defaultMessage: 'Add to case', | ||
}), | ||
'data-test-subj': 'aiopsLogPatternAnalysisAttachToCaseButton', | ||
onClick: () => { | ||
setIsActionMenuOpen(false); | ||
openCasesModalCallback({ | ||
dataViewId: dataView.id, | ||
fieldName: selectedField, | ||
minimumTimeRangeOption: 'No minimum', | ||
randomSamplerMode, | ||
randomSamplerProbability, | ||
timeRange, | ||
}); | ||
}, | ||
}, | ||
] | ||
: []), | ||
], | ||
}, | ||
{ | ||
id: 'attachToDashboardPanel', | ||
size: 's', | ||
title: i18n.translate('xpack.aiops.logCategorization.addToDashboardTitle', { | ||
defaultMessage: 'Add to dashboard', | ||
}), | ||
content: ( | ||
<EuiPanel paddingSize="s"> | ||
<EuiSpacer size="s" /> | ||
<EuiForm> | ||
<EuiFormRow> | ||
<EuiSwitch | ||
label={i18n.translate('xpack.aiops.logCategorization.applyTimeRangeLabel', { | ||
defaultMessage: 'Apply time range', | ||
})} | ||
checked={applyTimeRange} | ||
onChange={(e) => setApplyTimeRange(e.target.checked)} | ||
/> | ||
</EuiFormRow> | ||
<EuiSpacer size="m" /> | ||
<EuiButton | ||
size="s" | ||
data-test-subj="aiopsLogPatternAnalysisAttachToDashboardSubmitButton" | ||
fill | ||
fullWidth | ||
type={'submit'} | ||
onClick={() => { | ||
setIsActionMenuOpen(false); | ||
setDashboardAttachmentReady(true); | ||
}} | ||
> | ||
<FormattedMessage | ||
id="xpack.aiops.logCategorization.attachToDashboardSubmitButtonLabel" | ||
defaultMessage="Attach" | ||
/> | ||
</EuiButton> | ||
</EuiForm> | ||
</EuiPanel> | ||
), | ||
}, | ||
]; | ||
}, [ | ||
canEditDashboards, | ||
canUpdateCase, | ||
canCreateCase, | ||
applyTimeRange, | ||
openCasesModalCallback, | ||
dataView.id, | ||
selectedField, | ||
randomSamplerMode, | ||
randomSamplerProbability, | ||
timeRange, | ||
]); | ||
|
||
return ( | ||
<EuiFlexItem> | ||
<EuiPopover | ||
button={ | ||
<EuiButtonIcon | ||
data-test-subj="aiopsLogPatternAnalysisAttachmentsMenuButton" | ||
aria-label={i18n.translate('xpack.aiops.logCategorization.attachmentsMenuAriaLabel', { | ||
defaultMessage: 'Attachments', | ||
})} | ||
iconType="boxesHorizontal" | ||
color="text" | ||
onClick={() => setIsActionMenuOpen(!isActionMenuOpen)} | ||
/> | ||
} | ||
isOpen={isActionMenuOpen} | ||
closePopover={() => setIsActionMenuOpen(false)} | ||
panelPaddingSize="none" | ||
anchorPosition="downRight" | ||
> | ||
<EuiContextMenu panels={panels} initialPanelId="attachMainPanel" /> | ||
</EuiPopover> | ||
{dashboardAttachmentReady ? ( | ||
<SavedObjectSaveModalDashboard | ||
canSaveByReference={false} | ||
objectType={i18n.translate('xpack.aiops.logCategorization.objectTypeLabel', { | ||
defaultMessage: 'Log pattern analysis', | ||
})} | ||
documentInfo={{ | ||
title: 'Log pattern analysis', | ||
}} | ||
onClose={() => setDashboardAttachmentReady(false)} | ||
onSave={onSave} | ||
/> | ||
) : null} | ||
</EuiFlexItem> | ||
); | ||
}; |
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
Oops, something went wrong.