mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[8.9] [RAM][Maintenance Windows][Bug] Show Maintenance Window Ids If Unable to Fetch Maintenance Windows (#160218) (#160553)
# Backport This will backport the following commits from `main` to `8.9`: - [[RAM][Maintenance Windows][Bug] Show Maintenance Window Ids If Unable to Fetch Maintenance Windows (#160218)](https://github.com/elastic/kibana/pull/160218) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Jiawei Wu","email":"74562234+JiaweiWu@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-06-26T16:50:45Z","message":"[RAM][Maintenance Windows][Bug] Show Maintenance Window Ids If Unable to Fetch Maintenance Windows (#160218)\n\n## Summary\r\nResolves: https://github.com/elastic/kibana/issues/160202\r\n\r\nWe should show maintenance window IDs in the alert table columns if the\r\nuser does not have the capability or license to fetch maintenance\r\nwindows. Right now we will show nothing if the user can't fetch.\r\n\r\n## To Test:\r\n\r\n1. Start trial, make sure you have a platinum license\r\n2. Create a few maintenance windows (management -> Maintenance windows)\r\n3. Create an O11y rule, trigger a few alerts\r\n4. Go to the O11Y alerts table, ensuring the `Maintenance Windows`\r\ncolumn is visible\r\n5. Assert the MW names are displayed\r\n6. Revert to a basic license\r\n7. Go to the O11y alerts table again\r\n8. Assert the MW ids are displayed\r\n9. Repeat 1-8 for the rule details alerts page\r\n\r\n### Checklist\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","sha":"53f32b37900743fda0096168ae3e9f839973f823","branchLabelMapping":{"^v8.10.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:ResponseOps","Feature:Alerting/RulesManagement","v8.9.0","v8.10.0"],"number":160218,"url":"https://github.com/elastic/kibana/pull/160218","mergeCommit":{"message":"[RAM][Maintenance Windows][Bug] Show Maintenance Window Ids If Unable to Fetch Maintenance Windows (#160218)\n\n## Summary\r\nResolves: https://github.com/elastic/kibana/issues/160202\r\n\r\nWe should show maintenance window IDs in the alert table columns if the\r\nuser does not have the capability or license to fetch maintenance\r\nwindows. Right now we will show nothing if the user can't fetch.\r\n\r\n## To Test:\r\n\r\n1. Start trial, make sure you have a platinum license\r\n2. Create a few maintenance windows (management -> Maintenance windows)\r\n3. Create an O11y rule, trigger a few alerts\r\n4. Go to the O11Y alerts table, ensuring the `Maintenance Windows`\r\ncolumn is visible\r\n5. Assert the MW names are displayed\r\n6. Revert to a basic license\r\n7. Go to the O11y alerts table again\r\n8. Assert the MW ids are displayed\r\n9. Repeat 1-8 for the rule details alerts page\r\n\r\n### Checklist\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","sha":"53f32b37900743fda0096168ae3e9f839973f823"}},"sourceBranch":"main","suggestedTargetBranches":["8.9"],"targetPullRequestStates":[{"branch":"8.9","label":"v8.9.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.10.0","labelRegex":"^v8.10.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/160218","number":160218,"mergeCommit":{"message":"[RAM][Maintenance Windows][Bug] Show Maintenance Window Ids If Unable to Fetch Maintenance Windows (#160218)\n\n## Summary\r\nResolves: https://github.com/elastic/kibana/issues/160202\r\n\r\nWe should show maintenance window IDs in the alert table columns if the\r\nuser does not have the capability or license to fetch maintenance\r\nwindows. Right now we will show nothing if the user can't fetch.\r\n\r\n## To Test:\r\n\r\n1. Start trial, make sure you have a platinum license\r\n2. Create a few maintenance windows (management -> Maintenance windows)\r\n3. Create an O11y rule, trigger a few alerts\r\n4. Go to the O11Y alerts table, ensuring the `Maintenance Windows`\r\ncolumn is visible\r\n5. Assert the MW names are displayed\r\n6. Revert to a basic license\r\n7. Go to the O11y alerts table again\r\n8. Assert the MW ids are displayed\r\n9. Repeat 1-8 for the rule details alerts page\r\n\r\n### Checklist\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","sha":"53f32b37900743fda0096168ae3e9f839973f823"}}]}] BACKPORT--> Co-authored-by: Jiawei Wu <74562234+JiaweiWu@users.noreply.github.com>
This commit is contained in:
parent
02265aef44
commit
4365d08901
3 changed files with 55 additions and 27 deletions
|
@ -19,7 +19,7 @@ const maintenanceWindowsMap = getMaintenanceWindowMockMap();
|
|||
const alert = {
|
||||
_id: 'alert-id',
|
||||
_index: 'alert-index',
|
||||
[ALERT_MAINTENANCE_WINDOW_IDS]: ['test-mw-id-1'],
|
||||
[ALERT_MAINTENANCE_WINDOW_IDS]: ['test-mw-id-1', 'test-mw-id-2'],
|
||||
} as Alert;
|
||||
|
||||
const props: CellComponentProps = {
|
||||
|
@ -34,7 +34,7 @@ const props: CellComponentProps = {
|
|||
describe('MaintenanceWindowCell', () => {
|
||||
it('renders the maintenance window cell', async () => {
|
||||
render(<MaintenanceWindowCell {...props} />);
|
||||
expect(screen.getByText('test-title')).toBeInTheDocument();
|
||||
expect(screen.getByText('test-title,')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders the loading skeleton', async () => {
|
||||
|
@ -44,8 +44,16 @@ describe('MaintenanceWindowCell', () => {
|
|||
|
||||
it('shows the tooltip', async () => {
|
||||
render(<MaintenanceWindowCell {...props} />);
|
||||
expect(screen.getByText('test-title')).toBeInTheDocument();
|
||||
userEvent.hover(screen.getByText('test-title'));
|
||||
expect(screen.getByText('test-title,')).toBeInTheDocument();
|
||||
userEvent.hover(screen.getByText('test-title,'));
|
||||
expect(await screen.findByTestId('maintenance-window-tooltip-content')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders the maintenance window IDs if the endpoint could not be fetched', async () => {
|
||||
render(<MaintenanceWindowCell {...props} maintenanceWindows={new Map()} />);
|
||||
expect(screen.queryByText('test-title,')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('test-title-2')).not.toBeInTheDocument();
|
||||
expect(screen.getByText('test-mw-id-1,')).toBeInTheDocument();
|
||||
expect(screen.getByText('test-mw-id-2')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import React, { memo, useMemo } from 'react';
|
||||
import { EuiSkeletonText, EuiToolTip, EuiText } from '@elastic/eui';
|
||||
import { EuiSkeletonText, EuiToolTip } from '@elastic/eui';
|
||||
import { MaintenanceWindow } from '@kbn/alerting-plugin/common';
|
||||
import { ALERT_MAINTENANCE_WINDOW_IDS, TIMESTAMP } from '@kbn/rule-data-utils';
|
||||
import { CellComponentProps } from '../types';
|
||||
|
@ -18,34 +18,42 @@ const isMaintenanceWindowValid = (mw: MaintenanceWindow | undefined): mw is Main
|
|||
|
||||
interface MaintenanceWindowBaseCellProps {
|
||||
maintenanceWindows: MaintenanceWindow[];
|
||||
maintenanceWindowIds: string[];
|
||||
timestamp?: string;
|
||||
isLoading: boolean;
|
||||
}
|
||||
|
||||
export const MaintenanceWindowBaseCell = memo((props: MaintenanceWindowBaseCellProps) => {
|
||||
const { maintenanceWindows, isLoading, timestamp } = props;
|
||||
const { maintenanceWindows, maintenanceWindowIds, isLoading, timestamp } = props;
|
||||
|
||||
const tooltipWithText = useMemo(() => {
|
||||
if (!maintenanceWindows.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return maintenanceWindows.map((mw, index) => {
|
||||
return (
|
||||
<>
|
||||
<EuiToolTip
|
||||
key={`${mw.id}_tooltip`}
|
||||
content={<TooltipContent maintenanceWindow={mw} timestamp={timestamp} />}
|
||||
>
|
||||
<EuiText key={`${mw.id}_text`} size="relative">
|
||||
{mw.title}
|
||||
</EuiText>
|
||||
</EuiToolTip>
|
||||
{index !== maintenanceWindows.length - 1 && <>, </>}
|
||||
</>
|
||||
);
|
||||
});
|
||||
}, [maintenanceWindows, timestamp]);
|
||||
const totalLength = maintenanceWindows.length + maintenanceWindowIds.length;
|
||||
return (
|
||||
<>
|
||||
{maintenanceWindows.map((mw, index) => (
|
||||
<>
|
||||
<EuiToolTip
|
||||
key={`${mw.id}_tooltip`}
|
||||
content={<TooltipContent maintenanceWindow={mw} timestamp={timestamp} />}
|
||||
>
|
||||
<span key={`${mw.id}_title`}>
|
||||
{mw.title}
|
||||
{index !== totalLength - 1 && <>, </>}
|
||||
</span>
|
||||
</EuiToolTip>
|
||||
</>
|
||||
))}
|
||||
{maintenanceWindowIds.map((id, index) => (
|
||||
<>
|
||||
<span key={`${id}_id`}>
|
||||
{id}
|
||||
{index + maintenanceWindows.length !== totalLength - 1 && <>, </>}
|
||||
</span>
|
||||
</>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}, [maintenanceWindows, maintenanceWindowIds, timestamp]);
|
||||
|
||||
return (
|
||||
<EuiSkeletonText
|
||||
|
@ -69,13 +77,19 @@ export const MaintenanceWindowCell = memo((props: CellComponentProps) => {
|
|||
.filter(isMaintenanceWindowValid);
|
||||
}, [alert, maintenanceWindows]);
|
||||
|
||||
if (validMaintenanceWindows.length === 0) {
|
||||
const idsWithoutMaintenanceWindow = useMemo(() => {
|
||||
const maintenanceWindowIds = alert[ALERT_MAINTENANCE_WINDOW_IDS] || [];
|
||||
return maintenanceWindowIds.filter((id) => !maintenanceWindows.get(id));
|
||||
}, [alert, maintenanceWindows]);
|
||||
|
||||
if (validMaintenanceWindows.length === 0 && idsWithoutMaintenanceWindow.length === 0) {
|
||||
return <>--</>;
|
||||
}
|
||||
|
||||
return (
|
||||
<MaintenanceWindowBaseCell
|
||||
maintenanceWindows={validMaintenanceWindows}
|
||||
maintenanceWindowIds={idsWithoutMaintenanceWindow}
|
||||
isLoading={isLoading}
|
||||
timestamp={alert[TIMESTAMP]?.[0]}
|
||||
/>
|
||||
|
|
|
@ -72,10 +72,16 @@ const RuleAlertListMaintenanceWindowCell = (props: RuleAlertListMaintenanceWindo
|
|||
.filter(isMaintenanceWindowValid);
|
||||
}, [alert, maintenanceWindows]);
|
||||
|
||||
const idsWithoutMaintenanceWindow = useMemo(() => {
|
||||
const maintenanceWindowIds = alert.maintenanceWindowIds || [];
|
||||
return maintenanceWindowIds.filter((id) => !maintenanceWindows.get(id));
|
||||
}, [alert, maintenanceWindows]);
|
||||
|
||||
return (
|
||||
<MaintenanceWindowBaseCell
|
||||
timestamp={alert.start?.toISOString()}
|
||||
maintenanceWindows={validMaintenanceWindows}
|
||||
maintenanceWindowIds={idsWithoutMaintenanceWindow}
|
||||
isLoading={isLoading}
|
||||
/>
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue