Skip to content

Commit

Permalink
[RAM] Fix bulk action for o11y for 7.17 (#126686)
Browse files Browse the repository at this point in the history
* fix bulk action for o11y

* review I

* discuss it more with Devin

* clean up
  • Loading branch information
XavierM authored Mar 3, 2022
1 parent 9c45883 commit 8f277d4
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const FullWidthFlexGroup = styled(EuiFlexGroup)<{ $visible: boolean }>`
`;

export const EVENTS_VIEWER_HEADER_HEIGHT = 90; // px
const STANDALONE_ID = 'standalone-t-grid';
export const STANDALONE_ID = 'standalone-t-grid';
const EMPTY_DATA_PROVIDERS: DataProvider[] = [];

const TitleText = styled.span`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ export const useUpdateAlertsStatus = (
body: JSON.stringify({ status, query }),
});
} else {
const { body } = await http.post<{ body: estypes.UpdateByQueryResponse }>(
const response = await http.post<estypes.UpdateByQueryResponse>(
RAC_ALERTS_BULK_UPDATE_URL,
{ body: JSON.stringify({ index, status, query }) }
);
return body;
return response;
}
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as i18n from '../components/t_grid/translations';
import type { AlertStatus, StatusBulkActionsProps } from '../../common/types/timeline';
import { useUpdateAlertsStatus } from '../container/use_update_alerts';
import { useAppToasts } from './use_app_toasts';
import { STANDALONE_ID } from '../components/t_grid/standalone';

export const getUpdateAlertsQuery = (eventIds: Readonly<string[]>) => {
return { bool: { filter: { terms: { _id: eventIds } } } };
Expand All @@ -28,7 +29,7 @@ export const useStatusBulkActionItems = ({
onUpdateFailure,
timelineId,
}: StatusBulkActionsProps) => {
const { updateAlertStatus } = useUpdateAlertsStatus(timelineId != null);
const { updateAlertStatus } = useUpdateAlertsStatus(timelineId !== STANDALONE_ID);
const { addSuccess, addError, addWarning } = useAppToasts();

const onAlertStatusUpdateSuccess = useCallback(
Expand Down
21 changes: 21 additions & 0 deletions x-pack/test/functional/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,27 @@ export default async function ({ readConfigFile }) {
cluster: ['manage'],
},
},

global_alerts_logs_all_else_read: {
kibana: [
{
feature: {
apm: ['read'],
logs: ['all'],
infrastructure: ['read'],
},
spaces: ['*'],
},
],
elasticsearch: {
indices: [
{
names: ['*'],
privileges: ['all'],
},
],
},
},
},
defaultRoles: ['superuser'],
},
Expand Down
10 changes: 10 additions & 0 deletions x-pack/test/functional/services/observability/alerts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ export function ObservabilityAlertsCommonProvider({
return await testSubjects.findAll('dataGridRowCell');
};

const getAllDisabledCheckBoxInTable = async () => {
return await find.allByCssSelector('.euiDataGridRowCell input[type="checkbox"]:disabled');
};

const getAllEnabledCheckBoxInTable = async () => {
return await find.allByCssSelector('.euiDataGridRowCell input[type="checkbox"]:enabled');
};

const getExperimentalDisclaimer = async () => {
return testSubjects.existOrFail('o11yExperimentalDisclaimer');
};
Expand Down Expand Up @@ -287,6 +295,8 @@ export function ObservabilityAlertsCommonProvider({
getAlertsFlyoutOrFail,
getAlertsFlyoutTitle,
getAlertsFlyoutViewInAppButtonOrFail,
getAllDisabledCheckBoxInTable,
getAllEnabledCheckBoxInTable,
getFilterForValueButton,
getNoDataPageOrFail,
getNoDataStateOrFail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const ACTIVE_ALERTS_CELL_COUNT = 78;
const RECOVERED_ALERTS_CELL_COUNT = 150;
const TOTAL_ALERTS_CELL_COUNT = 200;

const DISABLED_ALERTS_CHECKBOX = 6;
const ENABLED_ALERTS_CHECKBOX = 4;

export default ({ getService }: FtrProviderContext) => {
const esArchiver = getService('esArchiver');
const find = getService('find');
Expand All @@ -23,6 +26,7 @@ export default ({ getService }: FtrProviderContext) => {
const testSubjects = getService('testSubjects');
const retry = getService('retry');
const observability = getService('observability');
const security = getService('security');

before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/observability/alerts');
Expand Down Expand Up @@ -215,22 +219,73 @@ export default ({ getService }: FtrProviderContext) => {
});

describe('Actions Button', () => {
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/infra/metrics_and_logs');
await observability.alerts.common.navigateToTimeWithData();
});

after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/infra/metrics_and_logs');
});

it('Opens rule details page when click on "View Rule Details"', async () => {
const actionsButton = await observability.alerts.common.getActionsButtonByIndex(0);
await actionsButton.click();
await observability.alerts.common.viewRuleDetailsButtonClick();
expect(await find.existsByCssSelector('[title="Rules and Connectors"]')).to.eql(true);
});
});

/*
* ATTENTION FUTURE DEVELOPER
*
* These tests should only be valid for 7.17.x
* You can run this test if you go to this file:
* x-pack/plugins/observability/public/pages/alerts/containers/alerts_table_t_grid/alerts_table_t_grid.tsx
* and at line 397 and change showCheckboxes to true
*
*/
describe.skip('Bulk Actions', () => {
before(async () => {
await security.testUser.setRoles(['global_alerts_logs_all_else_read'], true);
await observability.alerts.common.submitQuery('kibana.alert.status: "active"');
});
after(async () => {
await observability.alerts.common.submitQuery('');
await security.testUser.restoreDefaults();
});

it('Only logs alert should be enable for bulk actions', async () => {
const disabledCheckBoxes =
await observability.alerts.common.getAllDisabledCheckBoxInTable();
const enabledCheckBoxes =
await observability.alerts.common.getAllEnabledCheckBoxInTable();

expect(disabledCheckBoxes.length).to.eql(DISABLED_ALERTS_CHECKBOX);
expect(enabledCheckBoxes.length).to.eql(ENABLED_ALERTS_CHECKBOX);
});

it('validate formatting of the bulk actions button', async () => {
const selectAll = await testSubjects.find('select-all-events');
await selectAll.click();
const bulkActionsButton = await testSubjects.find('selectedShowBulkActionsButton');
expect(await bulkActionsButton.getVisibleText()).to.be('Selected 4 alerts');
await selectAll.click();
});

it('validate functionality of the bulk actions button', async () => {
const selectAll = await testSubjects.find('select-all-events');
await selectAll.click();

const bulkActionsButton = await testSubjects.find('selectedShowBulkActionsButton');
await bulkActionsButton.click();

const bulkActionsAcknowledgedAlertStatusButton = await testSubjects.find(
'acknowledged-alert-status'
);
await bulkActionsAcknowledgedAlertStatusButton.click();
await observability.alerts.common.submitQuery(
'kibana.alert.workflow_status : "acknowledged"'
);

await retry.try(async () => {
const enabledCheckBoxes =
await observability.alerts.common.getAllEnabledCheckBoxInTable();
expect(enabledCheckBoxes.length).to.eql(1);
});
});
});
});
});
};

0 comments on commit 8f277d4

Please sign in to comment.