Skip to content

Commit

Permalink
Merge branch 'main' into fix-endpoint-test
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaElastic authored Oct 2, 2023
2 parents 2804f25 + c7b3888 commit 6916883
Show file tree
Hide file tree
Showing 172 changed files with 2,211 additions and 453 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/create-deploy-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ jobs:
"<https://github.com/elastic/kibana/actions/runs/${{ github.run_id }}|GitHub Workflow run>",
"<https://buildkite.com/elastic/kibana-serverless-release/builds?branch=${{ env.TAG_NAME }}|Kibana Serverless Release pipeline>",
"<https://argo-workflows.us-central1.gcp.qa.cld.elstc.co/workflows?label=hash%3D${{ env.COMMIT }}|Argo Workflow> (use Elastic Cloud Staging VPN)",
"<https://overview.qa.cld.elstc.co/app/dashboards#/view/serverless-tooling-gpctl-deployment-status?_g=(refreshInterval:(pause:!t,value:0),time:(from:now-1d,to:now))&service-name=kibana&_a=(controlGroupInput:(chainingSystem:HIERARCHICAL,controlStyle:oneLine,ignoreParentSettings:(ignoreFilters:!f,ignoreQuery:!f,ignoreTimerange:!f,ignoreValidations:!f),panels:('18201b8e-3aae-4459-947d-21e007b6a3a5':(explicitInput:(dataViewId:'serverless.logs-*',enhancements:(),fieldName:commit-hash,id:'18201b8e-3aae-4459-947d-21e007b6a3a5',selectedOptions:!('${{ env.COMMIT }}'),title:commit-hash),grow:!t,order:1,type:optionsListControl,width:medium),'41060e65-ce4c-414e-b8cf-492ccb19245f':(explicitInput:(dataViewId:'serverless.logs-*',enhancements:(),fieldName:service-name,id:'41060e65-ce4c-414e-b8cf-492ccb19245f',selectedOptions:!(kibana),title:service-name),grow:!t,order:0,type:optionsListControl,width:medium),ed96828e-efe9-43ad-be3f-0e04218f79af:(explicitInput:(dataViewId:'serverless.logs-*',enhancements:(),fieldName:to-env,id:ed96828e-efe9-43ad-be3f-0e04218f79af,selectedOptions:!(qa),title:to-env),grow:!t,order:2,type:optionsListControl,width:medium))))|GPCTL Deployment Status dashboard>",
"<https://overview.qa.cld.elstc.co/app/dashboards#/view/serverless-tooling-gpctl-deployment-status?_g=(refreshInterval:(pause:!t,value:0),time:(from:now-1d,to:now))&service-name=kibana&_a=(controlGroupInput:(chainingSystem:HIERARCHICAL,controlStyle:oneLine,ignoreParentSettings:(ignoreFilters:!f,ignoreQuery:!f,ignoreTimerange:!f,ignoreValidations:!f),panels:('18201b8e-3aae-4459-947d-21e007b6a3a5':(explicitInput:(dataViewId:'serverless.logs-*',enhancements:(),fieldName:commit-hash,id:'18201b8e-3aae-4459-947d-21e007b6a3a5',selectedOptions:!('${{ env.COMMIT }}'),title:commit-hash),grow:!t,order:1,type:optionsListControl,width:medium),'41060e65-ce4c-414e-b8cf-492ccb19245f':(explicitInput:(dataViewId:'serverless.logs-*',enhancements:(),fieldName:service-name,id:'41060e65-ce4c-414e-b8cf-492ccb19245f',selectedOptions:!(kibana),title:service-name),grow:!t,order:0,type:optionsListControl,width:medium),ed96828e-efe9-43ad-be3f-0e04218f79af:(explicitInput:(dataViewId:'serverless.logs-*',enhancements:(),fieldName:to-env,id:ed96828e-efe9-43ad-be3f-0e04218f79af,selectedOptions:!(qa),title:to-env),grow:!t,order:2,type:optionsListControl,width:medium))))|GPCTL Deployment Status dashboard for nonprod >",
"<https://overview.elastic-cloud.com/app/dashboards#/view/serverless-tooling-gpctl-deployment-status?_g=(refreshInterval:(pause:!t,value:0),time:(from:now-1d,to:now))&service-name=kibana&_a=(controlGroupInput:(chainingSystem:HIERARCHICAL,controlStyle:oneLine,ignoreParentSettings:(ignoreFilters:!f,ignoreQuery:!f,ignoreTimerange:!f,ignoreValidations:!f),panels:('18201b8e-3aae-4459-947d-21e007b6a3a5':(explicitInput:(dataViewId:'serverless.logs-*',enhancements:(),fieldName:commit-hash,id:'18201b8e-3aae-4459-947d-21e007b6a3a5',selectedOptions:!('${{ env.COMMIT }}'),title:commit-hash),grow:!t,order:1,type:optionsListControl,width:medium),'41060e65-ce4c-414e-b8cf-492ccb19245f':(explicitInput:(dataViewId:'serverless.logs-*',enhancements:(),fieldName:service-name,id:'41060e65-ce4c-414e-b8cf-492ccb19245f',selectedOptions:!(kibana),title:service-name),grow:!t,order:0,type:optionsListControl,width:medium),ed96828e-efe9-43ad-be3f-0e04218f79af:(explicitInput:(dataViewId:'serverless.logs-*',enhancements:(),fieldName:to-env,id:ed96828e-efe9-43ad-be3f-0e04218f79af,selectedOptions:!(production),title:to-env),grow:!t,order:2,type:optionsListControl,width:medium))))|GPCTL Deployment Status dashboard>",
"<https://buildkite.com/elastic/kibana-tests/builds?branch=main|Quality Gate pipeline>"
]
- name: Post Slack failure message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,45 @@
* Side Public License, v 1.
*/

import { KibanaServices } from './types';
import { AsApiContract } from '@kbn/actions-plugin/common';
import type { KibanaServices, MaintenanceWindow } from './types';

const rewriteMaintenanceWindowRes = ({
expiration_date: expirationDate,
r_rule: rRule,
created_by: createdBy,
updated_by: updatedBy,
created_at: createdAt,
updated_at: updatedAt,
event_start_time: eventStartTime,
event_end_time: eventEndTime,
category_ids: categoryIds,
...rest
}: AsApiContract<MaintenanceWindow>): MaintenanceWindow => ({
...rest,
expirationDate,
rRule,
createdBy,
updatedBy,
createdAt,
updatedAt,
eventStartTime,
eventEndTime,
categoryIds,
});

export const fetchActiveMaintenanceWindows = async (
http: KibanaServices['http'],
signal?: AbortSignal
) =>
http.fetch(INTERNAL_ALERTING_API_GET_ACTIVE_MAINTENANCE_WINDOWS_PATH, {
method: 'GET',
signal,
});
): Promise<MaintenanceWindow[]> => {
const result = await http.fetch<Array<AsApiContract<MaintenanceWindow>>>(
INTERNAL_ALERTING_API_GET_ACTIVE_MAINTENANCE_WINDOWS_PATH,
{
method: 'GET',
signal,
}
);
return result.map((mw) => rewriteMaintenanceWindowRes(mw));
};

const INTERNAL_ALERTING_API_GET_ACTIVE_MAINTENANCE_WINDOWS_PATH = `/internal/alerting/rules/maintenance_window/_active`;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import React from 'react';
import { I18nProvider } from '@kbn/i18n-react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { render, waitFor, cleanup } from '@testing-library/react';
import { render, waitFor, cleanup, screen } from '@testing-library/react';
import { MAINTENANCE_WINDOW_FEATURE_ID } from '@kbn/alerting-plugin/common';
import { MaintenanceWindowCallout } from '.';
import { fetchActiveMaintenanceWindows } from './api';
Expand Down Expand Up @@ -215,4 +215,56 @@ describe('MaintenanceWindowCallout', () => {

expect(await findByText('Maintenance window is running')).toBeInTheDocument();
});

it('should display the callout if the category ids contains the specified category', async () => {
fetchActiveMaintenanceWindowsMock.mockResolvedValue([
{
...RUNNING_MAINTENANCE_WINDOW_1,
categoryIds: ['observability'],
},
]);

render(
<MaintenanceWindowCallout
kibanaServices={kibanaServicesMock}
categories={['securitySolution']}
/>,
{
wrapper: TestProviders,
}
);

await waitFor(() => {
expect(screen.queryByTestId('maintenanceWindowCallout')).not.toBeInTheDocument();
});

fetchActiveMaintenanceWindowsMock.mockResolvedValue([
{
...RUNNING_MAINTENANCE_WINDOW_1,
categoryIds: ['securitySolution'],
},
]);

render(
<MaintenanceWindowCallout
kibanaServices={kibanaServicesMock}
categories={['securitySolution']}
/>,
{
wrapper: TestProviders,
}
);

await waitFor(() => {
expect(screen.getByTestId('maintenanceWindowCallout')).toBeInTheDocument();
});

render(<MaintenanceWindowCallout kibanaServices={kibanaServicesMock} />, {
wrapper: TestProviders,
});

await waitFor(() => {
expect(screen.getByTestId('maintenanceWindowCallout')).toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
* Side Public License, v 1.
*/

import React from 'react';
import React, { useMemo } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiCallOut } from '@elastic/eui';
import { MaintenanceWindow, MaintenanceWindowStatus, KibanaServices } from './types';
import { MaintenanceWindowStatus, KibanaServices } from './types';
import { useFetchActiveMaintenanceWindows } from './use_fetch_active_maintenance_windows';

const MAINTENANCE_WINDOW_FEATURE_ID = 'maintenanceWindow';
Expand All @@ -28,8 +28,10 @@ const MAINTENANCE_WINDOW_RUNNING_DESCRIPTION = i18n.translate(

export function MaintenanceWindowCallout({
kibanaServices,
categories,
}: {
kibanaServices: KibanaServices;
categories?: string[];
}): JSX.Element | null {
const {
application: { capabilities },
Expand All @@ -38,28 +40,48 @@ export function MaintenanceWindowCallout({
const isMaintenanceWindowDisabled =
!capabilities[MAINTENANCE_WINDOW_FEATURE_ID].show &&
!capabilities[MAINTENANCE_WINDOW_FEATURE_ID].save;
const { data } = useFetchActiveMaintenanceWindows(kibanaServices, {
const { data: activeMaintenanceWindows = [] } = useFetchActiveMaintenanceWindows(kibanaServices, {
enabled: !isMaintenanceWindowDisabled,
});

const shouldShowMaintenanceWindowCallout = useMemo(() => {
if (!activeMaintenanceWindows) {
return false;
}
if (activeMaintenanceWindows.length === 0) {
return false;
}
if (!Array.isArray(categories)) {
return true;
}

return activeMaintenanceWindows.some(({ status, categoryIds }) => {
if (status !== MaintenanceWindowStatus.Running) {
return false;
}
if (!Array.isArray(categoryIds)) {
return true;
}
return categoryIds.some((category) => categories.includes(category));
});
}, [categories, activeMaintenanceWindows]);

if (isMaintenanceWindowDisabled) {
return null;
}

const activeMaintenanceWindows = (data as MaintenanceWindow[]) || [];

if (activeMaintenanceWindows.some(({ status }) => status === MaintenanceWindowStatus.Running)) {
return (
<EuiCallOut
title={MAINTENANCE_WINDOW_RUNNING}
color="warning"
iconType="iInCircle"
data-test-subj="maintenanceWindowCallout"
>
{MAINTENANCE_WINDOW_RUNNING_DESCRIPTION}
</EuiCallOut>
);
if (!shouldShowMaintenanceWindowCallout) {
return null;
}

return null;
return (
<EuiCallOut
title={MAINTENANCE_WINDOW_RUNNING}
color="warning"
iconType="iInCircle"
data-test-subj="maintenanceWindowCallout"
>
{MAINTENANCE_WINDOW_RUNNING_DESCRIPTION}
</EuiCallOut>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface MaintenanceWindowSOProperties {
expirationDate: string;
events: DateRange[];
rRule: RRuleParams;
categoryIds?: string[];
}

export type MaintenanceWindowSOAttributes = MaintenanceWindowSOProperties &
Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-alerts-ui-shared/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@kbn/core",
"@kbn/i18n-react",
"@kbn/alerting-plugin",
"@kbn/rrule"
"@kbn/rrule",
"@kbn/actions-plugin"
]
}
Loading

0 comments on commit 6916883

Please sign in to comment.