Skip to content
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

[Response Ops] [Alerts table] Cell context alert table performance #180016

Merged
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3dc391a
WIP
kqualters-elastic Mar 11, 2024
c8cd962
WIP STILL NEED TO FIX MERGE CONFLICTS IN TIGGERS_ACTIONS_UI
kqualters-elastic Mar 28, 2024
0ba76f6
Merge remote-tracking branch 'upstream/main' into row-cell-context-pr…
kqualters-elastic Apr 3, 2024
456946d
Mostly working
kqualters-elastic Apr 4, 2024
bad79b4
Merge branch 'main' into cell-context-alert-table
kqualters-elastic Apr 4, 2024
bbf47f8
Merge branch 'main' into cell-context-alert-table
kqualters-elastic Apr 4, 2024
076e373
Merge branch 'cell-context-alert-table' of github.com:kqualters-elast…
kqualters-elastic Apr 4, 2024
ddb09b7
Hard code timeline only draggable value false
kqualters-elastic Apr 4, 2024
ccac09c
Fix tests that should have been failing or skipped ha
kqualters-elastic Apr 4, 2024
ad063a6
Merge remote-tracking branch 'upstream/main' into cell-context-alert-…
kqualters-elastic Apr 4, 2024
165d404
Fix types
kqualters-elastic Apr 4, 2024
4d49a2d
Merge remote-tracking branch 'upstream/main' into cell-context-alert-…
kqualters-elastic Apr 4, 2024
da6721f
Merge remote-tracking branch 'upstream/main' into cell-context-alert-…
kqualters-elastic Apr 4, 2024
5c526ad
Merge branch 'main' into cell-context-alert-table
kqualters-elastic Apr 4, 2024
9b4bf15
Merge remote-tracking branch 'upstream/main' into cell-context-alert-…
kqualters-elastic Apr 10, 2024
e41fa42
Merge upstream, fix stack table
kqualters-elastic Apr 10, 2024
b0f1aae
Undo wrong test change
kqualters-elastic Apr 10, 2024
23a5fed
Fix types
kqualters-elastic Apr 10, 2024
4eb868b
Actually fix types
kqualters-elastic Apr 10, 2024
dc425e2
Pass config to cells as well
kqualters-elastic Apr 10, 2024
d1ccafb
Merge remote-tracking branch 'origin/cell-context-alert-table' into c…
kqualters-elastic Apr 10, 2024
fb300e0
Fix bad merge
kqualters-elastic Apr 10, 2024
47a3f70
Update old id from bad merge
kqualters-elastic Apr 10, 2024
0a2e385
Fix typo in alert assignee hook
kqualters-elastic Apr 11, 2024
c56da7e
Merge remote-tracking branch 'upstream/main' into cell-context-alert-…
kqualters-elastic Apr 11, 2024
d138582
Merge branch 'main' into cell-context-alert-table
kqualters-elastic Apr 11, 2024
f75acba
Merge branch 'main' into cell-context-alert-table
kqualters-elastic Apr 11, 2024
e4fd50c
Fix guided onboarding
kqualters-elastic Apr 12, 2024
278806d
Merge remote-tracking branch 'origin/cell-context-alert-table' into c…
kqualters-elastic Apr 12, 2024
92d1ee2
Merge remote-tracking branch 'upstream/main' into cell-context-alert-…
kqualters-elastic Apr 12, 2024
cae0199
Make sure onboarding steps only rendered once
kqualters-elastic Apr 12, 2024
95f3c52
Merge remote-tracking branch 'upstream/main' into cell-context-alert-…
kqualters-elastic Apr 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import type { FieldSpec } from '@kbn/data-views-plugin/common';
import { METRIC_TYPE, UiCounterMetricType } from '@kbn/analytics';
import React, { useCallback, useEffect } from 'react';
import React, { useCallback, useEffect, useMemo } from 'react';

import { groupActions, groupByIdSelector } from './state';
import type { GroupOption } from './types';
Expand Down Expand Up @@ -64,19 +64,21 @@ export const useGetGroupSelectorStateless = ({
[onGroupChange]
);

return (
<GroupSelector
{...{
groupingId,
groupsSelected: ['none'],
'data-test-subj': 'alerts-table-group-selector',
onGroupChange: onChange,
fields,
maxGroupingLevels,
options: defaultGroupingOptions,
}}
/>
);
return useMemo(() => {
return (
<GroupSelector
{...{
groupingId,
groupsSelected: ['none'],
'data-test-subj': 'alerts-table-group-selector',
onGroupChange: onChange,
fields,
maxGroupingLevels,
options: defaultGroupingOptions,
}}
/>
);
}, [groupingId, fields, maxGroupingLevels, defaultGroupingOptions, onChange]);
};

export const useGetGroupSelector = ({
Expand Down Expand Up @@ -198,18 +200,19 @@ export const useGetGroupSelector = ({
}
}, [defaultGroupingOptions, options, selectedGroups, setOptions]);

return (
<GroupSelector
{...{
groupingId,
groupsSelected: selectedGroups,
'data-test-subj': 'alerts-table-group-selector',
onGroupChange: onChange,
fields,
maxGroupingLevels,
options,
title,
}}
/>
);
return useMemo(() => {
return (
<GroupSelector
{...{
groupingId,
groupsSelected: selectedGroups,
'data-test-subj': 'alerts-table-group-selector',
onGroupChange: onChange,
fields,
maxGroupingLevels,
options,
}}
/>
);
}, [groupingId, fields, maxGroupingLevels, onChange, selectedGroups, options]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,11 @@ export class TriggersActionsUiExamplePlugin
id: 'observabilityCases',
columns,
useInternalFlyout,
getRenderCellValue: () => (props) => {
const value = props.data.find((d) => d.field === props.columnId)?.value ?? [];
getRenderCellValue: (props: {
data?: Array<{ field: string; value: string }>;
columnId?: string;
}) => {
const value = props.data?.find((d) => d.field === props.columnId)?.value ?? [];

if (Array.isArray(value)) {
return <>{value.length ? value.join() : '--'}</>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { useCallback } from 'react';
import { useCallback, useMemo } from 'react';
import { useApplication } from '../../../common/lib/kibana/use_application';
import { CaseStatuses } from '../../../../common/types/domain';
import type { AllCasesSelectorModalProps } from '.';
Expand Down Expand Up @@ -158,9 +158,11 @@ export const useCasesAddToExistingCaseModal = ({
[closeModal, dispatch, handleOnRowClick, onClose, onCreateCaseClicked]
);

return {
open: openModal,
close: closeModal,
};
return useMemo(() => {
return {
open: openModal,
close: closeModal,
};
}, [openModal, closeModal]);
};
export type UseCasesAddToExistingCaseModal = typeof useCasesAddToExistingCaseModal;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type React from 'react';
import { useCallback } from 'react';
import { useCallback, useMemo } from 'react';
import type { CaseAttachmentsWithoutOwner } from '../../../types';
import { useCasesToast } from '../../../common/use_cases_toast';
import type { CaseUI } from '../../../containers/types';
Expand Down Expand Up @@ -88,10 +88,12 @@ export const useCasesAddToNewCaseFlyout = ({
onClose,
]
);
return {
open: openFlyout,
close: closeFlyout,
};
return useMemo(() => {
return {
open: openFlyout,
close: closeFlyout,
};
}, [openFlyout, closeFlyout]);
};

export type UseCasesAddToNewCaseFlyout = typeof useCasesAddToNewCaseFlyout;
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export function registerAlertsTableConfiguration(
},
columns,
useInternalFlyout: getAlertFlyout(columns, getAlertFormatters(fieldFormats)),
getRenderCellValue: getRenderCellValue(fieldFormats),
getRenderCellValue,
sort,
useActionsColumn: () => ({
renderCustomActionsRow: (props: RenderCustomActionsRowArgs) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/

import { isEmpty } from 'lodash';
import React, { type ReactNode } from 'react';
import React from 'react';
import type { RenderCellValue } from '@elastic/eui';
import { isDefined } from '@kbn/ml-is-defined';
import { ALERT_DURATION, ALERT_END, ALERT_START } from '@kbn/rule-data-utils';
import type { GetRenderCellValue } from '@kbn/triggers-actions-ui-plugin/public';
import type { FieldFormatsRegistry } from '@kbn/field-formats-plugin/common';
import { FIELD_FORMAT_IDS } from '@kbn/field-formats-plugin/common';
import { getFormattedSeverityScore, getSeverityColor } from '@kbn/ml-anomaly-utils';
Expand All @@ -21,11 +21,6 @@ import {
} from '../../../common/constants/alerts';
import { getFieldFormatterProvider } from '../../application/contexts/kibana/use_field_formatter';

interface Props {
columnId: string;
data: any;
}

export const getMappedNonEcsValue = ({
data,
fieldName,
Expand Down Expand Up @@ -54,22 +49,17 @@ const getRenderValue = (mappedNonEcsValue: any) => {
return '—';
};

export const getRenderCellValue = (fieldFormats: FieldFormatsRegistry): GetRenderCellValue => {
export const getRenderCellValue: RenderCellValue = ({ columnId, data, fieldFormats }) => {
semd marked this conversation as resolved.
Show resolved Hide resolved
const alertValueFormatter = getAlertFormatters(fieldFormats);
if (!isDefined(data)) return;

return ({ setFlyoutAlert }) =>
(props): ReactNode => {
const { columnId, data } = props as Props;
if (!isDefined(data)) return;
const mappedNonEcsValue = getMappedNonEcsValue({
data,
fieldName: columnId,
});
const value = getRenderValue(mappedNonEcsValue);

const mappedNonEcsValue = getMappedNonEcsValue({
data,
fieldName: columnId,
});
const value = getRenderValue(mappedNonEcsValue);

return alertValueFormatter(columnId, value);
};
return alertValueFormatter(columnId, value);
};

export function getAlertFormatters(fieldFormats: FieldFormatsRegistry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export const AlertsPanel: FC = () => {

const [isOpen, setIsOpen] = useState(true);
const [toggleSelected, setToggleSelected] = useState(`alertsSummary`);

const {
services: { fieldFormats },
} = useMlKibana();
const { anomalyDetectionAlertsStateService } = useAnomalyExplorerContext();

const countByStatus = useObservable(anomalyDetectionAlertsStateService.countByStatus$);
Expand All @@ -48,6 +50,9 @@ export const AlertsPanel: FC = () => {
query: alertsQuery,
showExpandToDetails: true,
showAlertStatusWithFlapping: true,
cellContext: {
fieldFormats,
},
};
const alertsStateTable = triggersActionsUi!.getAlertsStateTable(alertStateProps);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ export const getAlertsPageTableConfiguration = (
id: observabilityFeatureId,
cases: { featureId: casesFeatureId, owner: [observabilityFeatureId] },
columns: getColumns({ showRuleName: true }),
getRenderCellValue: ({ setFlyoutAlert }) =>
getRenderCellValue({
observabilityRuleTypeRegistry,
setFlyoutAlert,
}),
getRenderCellValue,
sort: [
{
[ALERT_START]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import { ALERT_STATUS, ALERT_STATUS_ACTIVE, ALERT_STATUS_RECOVERED } from '@kbn/rule-data-utils';
import type { DeprecatedCellValueElementProps } from '@kbn/timelines-plugin/common';
import { createObservabilityRuleTypeRegistryMock } from '../../../rules/observability_rule_type_registry_mock';
import { render } from '../../../utils/test_helper';
import { getRenderCellValue } from './render_cell_value';

Expand All @@ -16,17 +15,10 @@ interface AlertsTableRow {
}

describe('getRenderCellValue', () => {
const observabilityRuleTypeRegistryMock = createObservabilityRuleTypeRegistryMock();

const renderCellValue = getRenderCellValue({
setFlyoutAlert: jest.fn(),
observabilityRuleTypeRegistry: observabilityRuleTypeRegistryMock,
});

describe('when column is alert status', () => {
it('should return an active indicator when alert status is active', async () => {
const cell = render(
renderCellValue({
getRenderCellValue({
...requiredProperties,
columnId: ALERT_STATUS,
data: makeAlertsTableRow({ alertStatus: ALERT_STATUS_ACTIVE }),
Expand All @@ -38,7 +30,7 @@ describe('getRenderCellValue', () => {

it('should return a recovered indicator when alert status is recovered', async () => {
const cell = render(
renderCellValue({
getRenderCellValue({
...requiredProperties,
columnId: ALERT_STATUS,
data: makeAlertsTableRow({ alertStatus: ALERT_STATUS_RECOVERED }),
Expand Down
Loading