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

[Obs Alert Table] Refactor alert table registration and change default columns #175119

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
cb6f582
Refactor alert table registration and change default columns
maryam-saeidi Jan 18, 2024
27c2cab
Add rule category on hover for rule name
maryam-saeidi Jan 18, 2024
819d5e4
Merge branch 'main' into 174239-improve-obs-alert-table
maryam-saeidi Jan 18, 2024
199c443
Change default search box time range to now-2h
maryam-saeidi Jan 18, 2024
3801e00
Merge branch 'main' into 174239-improve-obs-alert-table
maryam-saeidi Jan 18, 2024
f183b51
Fix translations
maryam-saeidi Jan 18, 2024
3c3f42e
Adjust number of cells and columns in the alert table tests
maryam-saeidi Jan 22, 2024
e01c2ab
Merge branch 'main' into 174239-improve-obs-alert-table
maryam-saeidi Jan 22, 2024
113e3c5
Fix default alert search bar time range in test
maryam-saeidi Jan 22, 2024
c2be17b
Merge branch 'main' into 174239-improve-obs-alert-table
maryam-saeidi Jan 22, 2024
e5951ec
Remove any type and fix test
maryam-saeidi Jan 23, 2024
39b2e1e
Merge branch 'main' into 174239-improve-obs-alert-table
maryam-saeidi Jan 23, 2024
8202ace
Use ALERT_INSTANCE_ID instead of ALERT_GROUP_VALUE
maryam-saeidi Jan 24, 2024
705d879
Merge branch 'main' into 174239-improve-obs-alert-table
maryam-saeidi Jan 24, 2024
024ae8d
Fix sorting
maryam-saeidi Jan 24, 2024
c493199
Merge branch 'main' into 174239-improve-obs-alert-table
maryam-saeidi Jan 24, 2024
e45faae
Fix test after changing the default sort
maryam-saeidi Jan 25, 2024
a26ebb0
Add type
maryam-saeidi Jan 25, 2024
be17b8e
Merge branch 'main' into 174239-improve-obs-alert-table
maryam-saeidi Jan 25, 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 @@ -35,7 +35,7 @@ interface AlertSearchBarStateTransitions {
}

const defaultState: AlertSearchBarContainerState = {
rangeFrom: 'now-15m',
rangeFrom: 'now-2h',
rangeTo: 'now',
kuery: '',
status: ALL_ALERTS.status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@
*/

import React from 'react';
import { TIMESTAMP } from '@kbn/rule-data-utils';
import { SortOrder } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { ALERT_START } from '@kbn/rule-data-utils';
import {
AlertsTableConfigurationRegistry,
RenderCustomActionsRowArgs,
} from '@kbn/triggers-actions-ui-plugin/public/types';
import { casesFeatureId, observabilityFeatureId } from '../../../common';
import { getRenderCellValue } from './render_cell_value';
import { columns } from './default_columns';
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 { 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 getAlertsTableConfiguration = (
export const getAlertsPageTableConfiguration = (
observabilityRuleTypeRegistry: ObservabilityRuleTypeRegistry,
config: ConfigSchema
): AlertsTableConfigurationRegistry => ({
id: observabilityFeatureId,
cases: { featureId: casesFeatureId, owner: [observabilityFeatureId] },
columns,
columns: getColumns({ showRuleName: true }),
getRenderCellValue: ({ setFlyoutAlert }) =>
getRenderCellValue({
observabilityRuleTypeRegistry,
setFlyoutAlert,
}),
sort: [
{
[TIMESTAMP]: {
[ALERT_START]: {
order: 'desc' as SortOrder,
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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 { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { CellTooltip } from './cell_tooltip';

describe('CellTooltip', () => {
it('should render tooltipContent on hover', async () => {
render(<CellTooltip value="cell value" tooltipContent="tooltip content" />);

fireEvent.mouseOver(screen.getByText('cell value'));

await waitFor(() => screen.getByTestId('cell-tooltip'));

expect(screen.getByText('tooltip content')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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 { EuiToolTip } from '@elastic/eui';

interface Props {
value: string;
tooltipContent: string;
}

export function CellTooltip({ value, tooltipContent }: Props) {
return (
<EuiToolTip content={tooltipContent} data-test-subj="cell-tooltip">
<>{value}</>
</EuiToolTip>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* 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.
*/

/**
* We need to produce types and code transpilation at different folders during the build of the package.
* We have types and code at different imports because we don't want to import the whole package in the resulting webpack bundle for the plugin.
* This way plugins can do targeted imports to reduce the final code bundle
*/
import {
ALERT_EVALUATION_VALUE,
ALERT_EVALUATION_THRESHOLD,
ALERT_DURATION,
ALERT_REASON,
ALERT_RULE_NAME,
ALERT_START,
ALERT_STATUS,
ALERT_INSTANCE_ID,
TAGS,
} from '@kbn/rule-data-utils';
import { EuiDataGridColumn } from '@elastic/eui';
import type { ColumnHeaderOptions } from '@kbn/timelines-plugin/common';
import { i18n } from '@kbn/i18n';

/**
* columns implements a subset of `EuiDataGrid`'s `EuiDataGridColumn` interface,
* plus additional TGrid column properties
*/
export const getColumns = (
{
showRuleName,
}: {
showRuleName?: boolean;
} = { showRuleName: false }
): Array<
Pick<EuiDataGridColumn, 'display' | 'displayAsText' | 'id' | 'initialWidth'> & ColumnHeaderOptions
> => {
const ruleNameColumn: Array<
Pick<EuiDataGridColumn, 'display' | 'displayAsText' | 'id' | 'initialWidth'> &
ColumnHeaderOptions
> = showRuleName
? [
{
columnHeaderType: 'not-filtered',
displayAsText: i18n.translate(
'xpack.observability.alertsTGrid.ruleNameColumnDescription',
{
defaultMessage: 'Rule name',
}
),
id: ALERT_RULE_NAME,
initialWidth: 150,
},
]
: [];

return [
{
columnHeaderType: 'not-filtered',
displayAsText: i18n.translate('xpack.observability.alertsTGrid.statusColumnDescription', {
defaultMessage: 'Alert Status',
}),
id: ALERT_STATUS,
initialWidth: 120,
},
{
columnHeaderType: 'not-filtered',
displayAsText: i18n.translate('xpack.observability.alertsTGrid.triggeredColumnDescription', {
defaultMessage: 'Triggered',
}),
id: ALERT_START,
initialWidth: 190,
schema: 'datetime',
},
{
columnHeaderType: 'not-filtered',
displayAsText: i18n.translate('xpack.observability.alertsTGrid.durationColumnDescription', {
defaultMessage: 'Duration',
}),
id: ALERT_DURATION,
initialWidth: 70,
},
...ruleNameColumn,
{
columnHeaderType: 'not-filtered',
displayAsText: i18n.translate('xpack.observability.alertsTGrid.sourceColumnDescription', {
defaultMessage: 'Group',
}),
id: ALERT_INSTANCE_ID,
initialWidth: 100,
},
{
columnHeaderType: 'not-filtered',
displayAsText: i18n.translate(
'xpack.observability.alertsTGrid.observedValueColumnDescription',
{
defaultMessage: 'Observed value',
}
),
id: ALERT_EVALUATION_VALUE,
initialWidth: 100,
},
{
columnHeaderType: 'not-filtered',
displayAsText: i18n.translate('xpack.observability.alertsTGrid.thresholdColumnDescription', {
defaultMessage: 'Threshold',
}),
id: ALERT_EVALUATION_THRESHOLD,
initialWidth: 100,
},
{
columnHeaderType: 'not-filtered',
displayAsText: i18n.translate('xpack.observability.alertsTGrid.tagsColumnDescription', {
defaultMessage: 'Tags',
}),
id: TAGS,
initialWidth: 150,
},
{
columnHeaderType: 'not-filtered',
displayAsText: i18n.translate('xpack.observability.alertsTGrid.reasonColumnDescription', {
defaultMessage: 'Reason',
}),
id: ALERT_REASON,
linkField: '*',
},
];
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

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 { createObservabilityRuleTypeRegistryMock } from '../../../rules/observability_rule_type_registry_mock';
import { render } from '../../../utils/test_helper';
import { getRenderCellValue } from './render_cell_value';

interface AlertsTableRow {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ import {
ALERT_REASON,
TIMESTAMP,
ALERT_UUID,
ALERT_EVALUATION_VALUE,
ALERT_EVALUATION_VALUES,
ALERT_RULE_NAME,
ALERT_RULE_CATEGORY,
} from '@kbn/rule-data-utils';
import { isEmpty } from 'lodash';
import type { TimelineNonEcsData } from '@kbn/timelines-plugin/common';

import { asDuration } from '../../../common/utils/formatters';
import { AlertSeverityBadge } from '../alert_severity_badge';
import { AlertStatusIndicator } from '../alert_status_indicator';
import { asDuration } from '../../../../common/utils/formatters';
import { AlertSeverityBadge } from '../../alert_severity_badge';
import { AlertStatusIndicator } from '../../alert_status_indicator';
import { parseAlert } from '../../../pages/alerts/helpers/parse_alert';
import type { ObservabilityRuleTypeRegistry } from '../../../rules/create_observability_rule_type_registry';
import { CellTooltip } from './cell_tooltip';
import { TimestampTooltip } from './timestamp_tooltip';
import { parseAlert } from '../../pages/alerts/helpers/parse_alert';
import type { ObservabilityRuleTypeRegistry } from '../../rules/create_observability_rule_type_registry';

export const getMappedNonEcsValue = ({
data,
Expand Down Expand Up @@ -56,7 +61,7 @@ const getRenderValue = (mappedNonEcsValue: any) => {
return value;
}

return '-';
return '--';
};

/**
Expand All @@ -78,7 +83,6 @@ export const getRenderCellValue = ({
data,
fieldName: columnId,
});

const value = getRenderValue(mappedNonEcsValue);

switch (columnId) {
Expand All @@ -95,6 +99,12 @@ export const getRenderCellValue = ({
return asDuration(Number(value));
case ALERT_SEVERITY:
return <AlertSeverityBadge severityLevel={value ?? undefined} />;
case ALERT_EVALUATION_VALUE:
const values = getMappedNonEcsValue({
data,
fieldName: ALERT_EVALUATION_VALUES,
});
return values ? values : value;
case ALERT_REASON:
const dataFieldEs = data.reduce((acc, d) => ({ ...acc, [d.field]: d.value }), {});
const alert = parseAlert(observabilityRuleTypeRegistry)(dataFieldEs);
Expand All @@ -108,6 +118,13 @@ export const getRenderCellValue = ({
{alert.reason}
</EuiLink>
);
case ALERT_RULE_NAME:
const ruleCategory = getMappedNonEcsValue({
data,
fieldName: ALERT_RULE_CATEGORY,
});
const tooltipContent = getRenderValue(ruleCategory);
return <CellTooltip value={value} tooltipContent={tooltipContent} />;
default:
return <>{value}</>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React from 'react';
import { EuiToolTip } from '@elastic/eui';
import { asAbsoluteDateTime, TimeUnit } from '../../../common/utils/formatters/datetime';
import { asAbsoluteDateTime, TimeUnit } from '../../../../common/utils/formatters/datetime';

interface Props {
/**
Expand Down

This file was deleted.

Loading