forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RAM] add maintenance window banner (elastic#163516)
## Summary Solves: elastic#163465 Add maintenance window banner to Rules list and Alerts list in O11y and Management. <img width="1334" alt="Screenshot 2023-08-09 at 13 03 50" src="https://github.com/elastic/kibana/assets/26089545/de0708b1-db2a-4517-91aa-a3d6b3e62b44"> <img width="1350" alt="Screenshot 2023-08-09 at 13 05 10" src="https://github.com/elastic/kibana/assets/26089545/9f7c488d-e992-4807-a60e-3c077b623b4e"> --------- Co-authored-by: Xavier Mouligneau <[email protected]> Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
9079b1c
commit b3122cb
Showing
14 changed files
with
306 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
53 changes: 53 additions & 0 deletions
53
packages/kbn-alerts-ui-shared/src/maintenance_window_callout/mock.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,53 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { AsApiContract } from '@kbn/alerting-plugin/server/routes/lib'; | ||
import { MaintenanceWindow, MaintenanceWindowStatus } from './types'; | ||
|
||
export const RUNNING_MAINTENANCE_WINDOW_1: Partial<MaintenanceWindow> = { | ||
title: 'Running maintenance window 1', | ||
id: '63057284-ac31-42ba-fe22-adfe9732e5ae', | ||
status: MaintenanceWindowStatus.Running, | ||
events: [{ gte: '2023-04-20T16:27:30.753Z', lte: '2023-04-20T16:57:30.753Z' }], | ||
}; | ||
|
||
export const RUNNING_MAINTENANCE_WINDOW_2: Partial<MaintenanceWindow> = { | ||
title: 'Running maintenance window 2', | ||
id: '45894340-df98-11ed-ac81-bfcb4982b4fd', | ||
status: MaintenanceWindowStatus.Running, | ||
events: [{ gte: '2023-04-20T16:47:42.871Z', lte: '2023-04-20T17:11:32.192Z' }], | ||
}; | ||
|
||
export const RECURRING_RUNNING_MAINTENANCE_WINDOW: Partial<AsApiContract<MaintenanceWindow>> = { | ||
title: 'Recurring running maintenance window', | ||
id: 'e2228300-e9ad-11ed-ba37-db17c6e6182b', | ||
status: MaintenanceWindowStatus.Running, | ||
events: [ | ||
{ gte: '2023-05-03T12:27:18.569Z', lte: '2023-05-03T12:57:18.569Z' }, | ||
{ gte: '2023-05-10T12:27:18.569Z', lte: '2023-05-10T12:57:18.569Z' }, | ||
], | ||
expiration_date: '2024-05-03T12:27:35.088Z', | ||
r_rule: { | ||
dtstart: '2023-05-03T12:27:18.569Z', | ||
tzid: 'Europe/Amsterdam', | ||
freq: 3, | ||
interval: 1, | ||
count: 2, | ||
byweekday: ['WE'], | ||
}, | ||
}; | ||
|
||
export const UPCOMING_MAINTENANCE_WINDOW: Partial<MaintenanceWindow> = { | ||
title: 'Upcoming maintenance window', | ||
id: '5eafe070-e030-11ed-ac81-bfcb4982b4fd', | ||
status: MaintenanceWindowStatus.Upcoming, | ||
events: [ | ||
{ gte: '2023-04-21T10:36:14.028Z', lte: '2023-04-21T10:37:00.000Z' }, | ||
{ gte: '2023-04-28T10:36:14.028Z', lte: '2023-04-28T10:37:00.000Z' }, | ||
], | ||
}; |
184 changes: 184 additions & 0 deletions
184
x-pack/plugins/observability/public/pages/alerts/alerts.test.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,184 @@ | ||
/* | ||
* 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 { render, waitFor } from '@testing-library/react'; | ||
import { CoreStart } from '@kbn/core/public'; | ||
import { AppMountParameters } from '@kbn/core/public'; | ||
import { TimeBuckets } from '@kbn/data-plugin/common'; | ||
import { fetchActiveMaintenanceWindows } from '@kbn/alerts-ui-shared/src/maintenance_window_callout/api'; | ||
import { RUNNING_MAINTENANCE_WINDOW_1 } from '@kbn/alerts-ui-shared/src/maintenance_window_callout/mock'; | ||
import { KibanaPageTemplate } from '@kbn/shared-ux-page-kibana-template'; | ||
import { __IntlProvider as IntlProvider } from '@kbn/i18n-react'; | ||
import { MAINTENANCE_WINDOW_FEATURE_ID } from '@kbn/alerting-plugin/common/maintenance_window'; | ||
|
||
import { ObservabilityPublicPluginsStart } from '../../plugin'; | ||
import { AlertsPage } from './alerts'; | ||
import { kibanaStartMock } from '../../utils/kibana_react.mock'; | ||
import * as pluginContext from '../../hooks/use_plugin_context'; | ||
import * as dataContext from '../../hooks/use_has_data'; | ||
import { createObservabilityRuleTypeRegistryMock } from '../../rules/observability_rule_type_registry_mock'; | ||
import { ThemeProvider } from '@emotion/react'; | ||
import { euiDarkVars } from '@kbn/ui-theme'; | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
|
||
const mockUseKibanaReturnValue = kibanaStartMock.startContract(); | ||
mockUseKibanaReturnValue.services.application.capabilities = { | ||
...mockUseKibanaReturnValue.services.application.capabilities, | ||
[MAINTENANCE_WINDOW_FEATURE_ID]: { | ||
save: true, | ||
show: true, | ||
}, | ||
}; | ||
|
||
jest.mock('../../utils/kibana_react', () => ({ | ||
__esModule: true, | ||
useKibana: jest.fn(() => mockUseKibanaReturnValue), | ||
})); | ||
jest.mock('@kbn/kibana-react-plugin/public', () => ({ | ||
__esModule: true, | ||
useKibana: jest.fn(() => mockUseKibanaReturnValue), | ||
})); | ||
jest.mock('@kbn/observability-shared-plugin/public'); | ||
jest.spyOn(pluginContext, 'usePluginContext').mockImplementation(() => ({ | ||
appMountParameters: { | ||
setHeaderActionMenu: () => {}, | ||
} as unknown as AppMountParameters, | ||
config: { | ||
unsafe: { | ||
slo: { enabled: false }, | ||
alertDetails: { | ||
apm: { enabled: false }, | ||
logs: { enabled: false }, | ||
metrics: { enabled: false }, | ||
uptime: { enabled: false }, | ||
observability: { enabled: false }, | ||
}, | ||
thresholdRule: { enabled: false }, | ||
}, | ||
compositeSlo: { | ||
enabled: false, | ||
}, | ||
aiAssistant: { | ||
enabled: false, | ||
feedback: { | ||
enabled: false, | ||
}, | ||
}, | ||
}, | ||
observabilityRuleTypeRegistry: createObservabilityRuleTypeRegistryMock(), | ||
ObservabilityPageTemplate: KibanaPageTemplate, | ||
kibanaFeatures: [], | ||
core: {} as CoreStart, | ||
plugins: {} as ObservabilityPublicPluginsStart, | ||
hasAnyData: true, | ||
isAllRequestsComplete: true, | ||
})); | ||
|
||
jest.spyOn(dataContext, 'useHasData').mockImplementation(() => ({ | ||
hasDataMap: {}, | ||
hasAnyData: true, | ||
isAllRequestsComplete: true, | ||
onRefreshTimeRange: jest.fn(), | ||
forceUpdate: 'false', | ||
})); | ||
|
||
jest.mock('@kbn/alerts-ui-shared/src/maintenance_window_callout/api', () => ({ | ||
fetchActiveMaintenanceWindows: jest.fn(() => Promise.resolve([])), | ||
})); | ||
const fetchActiveMaintenanceWindowsMock = fetchActiveMaintenanceWindows as jest.Mock; | ||
|
||
jest.mock('../../hooks/use_time_buckets', () => ({ | ||
useTimeBuckets: jest.fn(), | ||
})); | ||
|
||
jest.mock('../../hooks/use_has_data', () => ({ | ||
useHasData: jest.fn(), | ||
})); | ||
|
||
const { useTimeBuckets } = jest.requireMock('../../hooks/use_time_buckets'); | ||
const { useHasData } = jest.requireMock('../../hooks/use_has_data'); | ||
|
||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
retry: false, | ||
cacheTime: 0, | ||
}, | ||
}, | ||
}); | ||
function AllTheProviders({ children }: { children: any }) { | ||
return ( | ||
<ThemeProvider | ||
theme={() => ({ eui: { ...euiDarkVars, euiColorLightShade: '#ece' }, darkMode: true })} | ||
> | ||
<IntlProvider locale="en"> | ||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
</IntlProvider> | ||
</ThemeProvider> | ||
); | ||
} | ||
|
||
describe('AlertsPage with all capabilities', () => { | ||
const timeBuckets = new TimeBuckets({ | ||
'histogram:maxBars': 12, | ||
'histogram:barTarget': 10, | ||
dateFormat: 'MMM D, YYYY @ HH:mm:ss.SSS', | ||
'dateFormat:scaled': [ | ||
['', 'HH:mm:ss.SSS'], | ||
['PT1S', 'HH:mm:ss'], | ||
['PT1M', 'HH:mm'], | ||
['PT1H', 'YYYY-MM-DD HH:mm'], | ||
['P1DT', 'YYYY-MM-DD'], | ||
['P1YT', 'YYYY'], | ||
], | ||
}); | ||
|
||
async function setup() { | ||
return render(<AlertsPage />, { wrapper: AllTheProviders }); | ||
} | ||
|
||
beforeAll(() => { | ||
fetchActiveMaintenanceWindowsMock.mockResolvedValue([]); | ||
useHasData.mockReturnValue({ | ||
hasDataMap: { | ||
apm: { hasData: true, status: 'success' }, | ||
synthetics: { hasData: true, status: 'success' }, | ||
infra_logs: { hasData: undefined, status: 'success' }, | ||
infra_metrics: { hasData: true, status: 'success' }, | ||
ux: { hasData: undefined, status: 'success' }, | ||
alert: { hasData: false, status: 'success' }, | ||
}, | ||
hasAnyData: true, | ||
isAllRequestsComplete: true, | ||
onRefreshTimeRange: () => {}, | ||
forceUpdate: '', | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
fetchActiveMaintenanceWindowsMock.mockClear(); | ||
useTimeBuckets.mockReturnValue(timeBuckets); | ||
}); | ||
|
||
it('should render an alerts page template', async () => { | ||
const wrapper = await setup(); | ||
await waitFor(() => { | ||
expect(wrapper.getByText('Alerts')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('renders MaintenanceWindowCallout if one exists', async () => { | ||
fetchActiveMaintenanceWindowsMock.mockResolvedValue([RUNNING_MAINTENANCE_WINDOW_1]); | ||
const wrapper = await setup(); | ||
|
||
await waitFor(() => { | ||
expect(wrapper.getByTestId('maintenanceWindowCallout')).toBeInTheDocument(); | ||
expect(fetchActiveMaintenanceWindowsMock).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.