-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add alert grouping functionality to the observability alerts page (#1…
…89958) Closes #190995 ## Summary This PR adds grouping functionality to the alerts page alert table based on @umbopepato's implementation in this [draft PR](#183114) (basically, he implemented the feature and I adjusted a bit for our use case :D). For now, we only added the **rule** and **source** as default grouping, and I will create a ticket to add tags as well. The challenge with tags is that since it is an array, the value of the alert is joined by a comma as the group, which does not match with what we want for tags. ![image](https:/user-attachments/assets/c08c3cb1-4c6c-4918-8071-3c5913de41f6) Here is how we show the rules that don't have a group by field selected for them: (We used "ungrouped" similar to what we have in SLOs) ![image](https:/user-attachments/assets/280bbd34-6c3b-41c1-803b-dcc6448f6fb4) --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: DeDe Morton <[email protected]> Co-authored-by: Shahzad <[email protected]>
- Loading branch information
1 parent
00975ad
commit 34d392b
Showing
27 changed files
with
605 additions
and
59 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
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
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
66 changes: 66 additions & 0 deletions
66
...y_solution/observability/public/components/alerts_table/alerts/get_persistent_controls.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,66 @@ | ||
/* | ||
* 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 { useMemo, useCallback } from 'react'; | ||
import { type AlertsGroupingProps, useAlertsGroupingState } from '@kbn/alerts-grouping'; | ||
import { useAlertsDataView } from '@kbn/alerts-ui-shared/src/common/hooks/use_alerts_data_view'; | ||
import { useGetGroupSelectorStateless } from '@kbn/grouping/src/hooks/use_get_group_selector'; | ||
import { AlertConsumers } from '@kbn/rule-data-utils'; | ||
import { AlertsByGroupingAgg } from '../types'; | ||
|
||
interface GetPersistentControlsParams { | ||
groupingId: string; | ||
featureIds: AlertConsumers[]; | ||
maxGroupingLevels?: number; | ||
services: Pick< | ||
AlertsGroupingProps<AlertsByGroupingAgg>['services'], | ||
'dataViews' | 'http' | 'notifications' | ||
>; | ||
} | ||
|
||
export const getPersistentControlsHook = | ||
({ | ||
groupingId, | ||
featureIds, | ||
maxGroupingLevels = 3, | ||
services: { dataViews, http, notifications }, | ||
}: GetPersistentControlsParams) => | ||
() => { | ||
const { grouping, updateGrouping } = useAlertsGroupingState(groupingId); | ||
|
||
const onGroupChange = useCallback( | ||
(selectedGroups: string[]) => { | ||
updateGrouping({ | ||
activeGroups: | ||
grouping.activeGroups?.filter((g) => g !== 'none').concat(selectedGroups) ?? [], | ||
}); | ||
}, | ||
[grouping, updateGrouping] | ||
); | ||
|
||
const { dataView } = useAlertsDataView({ | ||
featureIds, | ||
dataViewsService: dataViews, | ||
http, | ||
toasts: notifications.toasts, | ||
}); | ||
|
||
const groupSelector = useGetGroupSelectorStateless({ | ||
groupingId, | ||
onGroupChange, | ||
fields: dataView?.fields ?? [], | ||
defaultGroupingOptions: | ||
grouping.options?.filter((option) => !grouping.activeGroups.includes(option.key)) ?? [], | ||
maxGroupingLevels, | ||
}); | ||
|
||
return useMemo(() => { | ||
return { | ||
right: groupSelector, | ||
}; | ||
}, [groupSelector]); | ||
}; |
58 changes: 58 additions & 0 deletions
58
...lity/public/components/alerts_table/observability/get_alerts_page_table_configuration.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,58 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { SortOrder } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; | ||
import { ALERT_START, AlertConsumers } from '@kbn/rule-data-utils'; | ||
import { | ||
AlertsTableConfigurationRegistry, | ||
RenderCustomActionsRowArgs, | ||
} from '@kbn/triggers-actions-ui-plugin/public/types'; | ||
import { casesFeatureId, observabilityFeatureId } from '../../../../common'; | ||
import { AlertActions } from '../../../pages/alerts/components/alert_actions'; | ||
import { useGetAlertFlyoutComponents } from '../../alerts_flyout/use_get_alert_flyout_components'; | ||
import type { ObservabilityRuleTypeRegistry } from '../../../rules/create_observability_rule_type_registry'; | ||
import type { ConfigSchema } from '../../../plugin'; | ||
import { getRenderCellValue } from '../common/render_cell_value'; | ||
import { getColumns } from '../common/get_columns'; | ||
|
||
export const getObservabilityTableConfiguration = ( | ||
observabilityRuleTypeRegistry: ObservabilityRuleTypeRegistry, | ||
config: ConfigSchema | ||
): AlertsTableConfigurationRegistry => { | ||
const renderCustomActionsRow = (props: RenderCustomActionsRowArgs) => { | ||
return ( | ||
<AlertActions | ||
{...props} | ||
config={config} | ||
observabilityRuleTypeRegistry={observabilityRuleTypeRegistry} | ||
/> | ||
); | ||
}; | ||
return { | ||
id: AlertConsumers.OBSERVABILITY, | ||
cases: { featureId: casesFeatureId, owner: [observabilityFeatureId] }, | ||
columns: getColumns({ showRuleName: true }), | ||
getRenderCellValue, | ||
sort: [ | ||
{ | ||
[ALERT_START]: { | ||
order: 'desc' as SortOrder, | ||
}, | ||
}, | ||
], | ||
useActionsColumn: () => ({ | ||
renderCustomActionsRow, | ||
}), | ||
useInternalFlyout: () => { | ||
const { header, body, footer } = useGetAlertFlyoutComponents(observabilityRuleTypeRegistry); | ||
return { header, body, footer }; | ||
}, | ||
ruleTypeIds: observabilityRuleTypeRegistry.list(), | ||
showInspectButton: true, | ||
}; | ||
}; |
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
36 changes: 36 additions & 0 deletions
36
x-pack/plugins/observability_solution/observability/public/components/alerts_table/types.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,36 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export interface BucketItem { | ||
key: string; | ||
doc_count: number; | ||
} | ||
|
||
export interface AlertsByGroupingAgg extends Record<string, unknown> { | ||
groupByFields: { | ||
doc_count_error_upper_bound: number; | ||
sum_other_doc_count: number; | ||
buckets: BucketItem[]; | ||
}; | ||
ruleTags: { | ||
doc_count_error_upper_bound: number; | ||
sum_other_doc_count: number; | ||
buckets: BucketItem[]; | ||
}; | ||
rulesCountAggregation?: { | ||
value: number; | ||
}; | ||
sourceCountAggregation?: { | ||
value: number; | ||
}; | ||
groupsCount: { | ||
value: number; | ||
}; | ||
unitsCount: { | ||
value: number; | ||
}; | ||
} |
Oops, something went wrong.