Skip to content

Commit

Permalink
Remove feature flag for manual rule run (elastic#193833)
Browse files Browse the repository at this point in the history
## Summary

Remove feature flag for manual rule run

---------

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
nkhristinin and elasticmachine authored Oct 9, 2024
1 parent 15bccdf commit 3f75a1d
Show file tree
Hide file tree
Showing 24 changed files with 104 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,6 @@ export const allowedExperimentalValues = Object.freeze({
*/
valueListItemsModalEnabled: true,

/**
* Enables the manual rule run
*/
manualRuleRunEnabled: false,

/**
* Adds a new option to filter descendants of a process for Management / Event Filters
*/
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
} from '../../../../../../common/detection_engine/rule_management/execution_log';

import { ExecutionStatusFilter, ExecutionRunTypeFilter } from '../../../../rule_monitoring';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';
import * as i18n from './translations';

export const EXECUTION_LOG_SCHEMA_MAPPING = {
Expand Down Expand Up @@ -75,7 +74,6 @@ export const ExecutionLogSearchBar = React.memo<ExecutionLogTableSearchProps>(
},
[onSearch]
);
const isManualRuleRunEnabled = useIsExperimentalFeatureEnabled('manualRuleRunEnabled');

return (
<EuiFlexGroup gutterSize={'s'}>
Expand All @@ -93,15 +91,14 @@ export const ExecutionLogSearchBar = React.memo<ExecutionLogTableSearchProps>(
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiFlexGroup gutterSize={'s'}>
{isManualRuleRunEnabled && (
<EuiFlexItem grow={true}>
<ExecutionRunTypeFilter
items={RUN_TYPE_FILTERS}
selectedItems={selectedRunTypes}
onChange={onRunTypeFilterChange}
/>
</EuiFlexItem>
)}
<EuiFlexItem grow={true}>
<ExecutionRunTypeFilter
items={RUN_TYPE_FILTERS}
selectedItems={selectedRunTypes}
onChange={onRunTypeFilterChange}
/>
</EuiFlexItem>

<EuiFlexItem grow={true}>
<ExecutionStatusFilter
items={STATUS_FILTERS}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ import {
} from './execution_log_columns';
import { ExecutionLogSearchBar } from './execution_log_search_bar';

import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';

const EXECUTION_UUID_FIELD_NAME = 'kibana.alert.rule.execution.uuid';

const UtilitySwitch = styled(EuiSwitch)`
Expand Down Expand Up @@ -128,7 +126,6 @@ const ExecutionLogTableComponent: React.FC<ExecutionLogTableProps> = ({
timelines,
telemetry,
} = useKibana().services;
const isManualRuleRunEnabled = useIsExperimentalFeatureEnabled('manualRuleRunEnabled');

const {
[RuleDetailTabs.executionResults]: {
Expand Down Expand Up @@ -473,15 +470,10 @@ const ExecutionLogTableComponent: React.FC<ExecutionLogTableProps> = ({
);

const executionLogColumns = useMemo(() => {
const columns = [...EXECUTION_LOG_COLUMNS].filter((item) => {
if ('field' in item) {
return item.field === 'type' ? isManualRuleRunEnabled : true;
}
return true;
});
const columns = [...EXECUTION_LOG_COLUMNS];
let messageColumnWidth = 50;

if (showSourceEventTimeRange && isManualRuleRunEnabled) {
if (showSourceEventTimeRange) {
columns.push(...getSourceEventTimeRangeColumns());
messageColumnWidth = 30;
}
Expand All @@ -506,7 +498,6 @@ const ExecutionLogTableComponent: React.FC<ExecutionLogTableProps> = ({

return columns;
}, [
isManualRuleRunEnabled,
actions,
docLinks,
showMetricColumns,
Expand Down Expand Up @@ -583,14 +574,12 @@ const ExecutionLogTableComponent: React.FC<ExecutionLogTableProps> = ({
updatedAt: dataUpdatedAt,
})}
</UtilityBarText>
{isManualRuleRunEnabled && (
<UtilitySwitch
label={i18n.RULE_EXECUTION_LOG_SHOW_SOURCE_EVENT_TIME_RANGE}
checked={showSourceEventTimeRange}
compressed={true}
onChange={handleShowSourceEventTimeRange}
/>
)}
<UtilitySwitch
label={i18n.RULE_EXECUTION_LOG_SHOW_SOURCE_EVENT_TIME_RANGE}
checked={showSourceEventTimeRange}
compressed={true}
onChange={handleShowSourceEventTimeRange}
/>
<UtilitySwitch
label={i18n.RULE_EXECUTION_LOG_SHOW_METRIC_COLUMNS_SWITCH}
checked={showMetricColumns}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import moment from 'moment';
import React, { useCallback, useMemo, useState } from 'react';
import { MAX_MANUAL_RULE_RUN_LOOKBACK_WINDOW_DAYS } from '../../../../../common/constants';
import { TECHNICAL_PREVIEW, TECHNICAL_PREVIEW_TOOLTIP } from '../../../../common/translations';
import { BETA, BETA_TOOLTIP } from '../../../../common/translations';

import * as i18n from './translations';

Expand Down Expand Up @@ -73,7 +73,7 @@ const ManualRuleRunModalComponent = ({ onCancel, onConfirm }: ManualRuleRunModal
<EuiFlexGroup justifyContent="spaceBetween">
<EuiFlexItem>{i18n.MANUAL_RULE_RUN_MODAL_TITLE}</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiBetaBadge label={TECHNICAL_PREVIEW} tooltipContent={TECHNICAL_PREVIEW_TOOLTIP} />
<EuiBetaBadge label={BETA} tooltipContent={BETA_TOOLTIP} />
</EuiFlexItem>
</EuiFlexGroup>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ import { hasUserCRUDPermission } from '../../../../common/utils/privileges';
import { useUserData } from '../../../../detections/components/user_info';
import { getBackfillRowsFromResponse } from './utils';
import { HeaderSection } from '../../../../common/components/header_section';
import { useIsExperimentalFeatureEnabled } from '../../../../common/hooks/use_experimental_features';
import { TableHeaderTooltipCell } from '../../../rule_management_ui/components/rules_table/table_header_tooltip_cell';
import { TECHNICAL_PREVIEW, TECHNICAL_PREVIEW_TOOLTIP } from '../../../../common/translations';
import { BETA, BETA_TOOLTIP } from '../../../../common/translations';
import { useKibana } from '../../../../common/lib/kibana';

const DEFAULT_PAGE_SIZE = 10;
Expand Down Expand Up @@ -143,26 +142,16 @@ const getBackfillsTableColumns = (hasCRUDPermissions: boolean) => {
};

export const RuleBackfillsInfo = React.memo<{ ruleId: string }>(({ ruleId }) => {
const isManualRuleRunEnabled = useIsExperimentalFeatureEnabled('manualRuleRunEnabled');
const [pageIndex, setPageIndex] = useState(0);
const [pageSize, setPageSize] = useState(DEFAULT_PAGE_SIZE);
const [{ canUserCRUD }] = useUserData();
const hasCRUDPermissions = hasUserCRUDPermission(canUserCRUD);
const { timelines } = useKibana().services;
const { data, isLoading, isError, refetch, dataUpdatedAt } = useFindBackfillsForRules(
{
ruleIds: [ruleId],
page: pageIndex + 1,
perPage: pageSize,
},
{
enabled: isManualRuleRunEnabled,
}
);

if (!isManualRuleRunEnabled) {
return null;
}
const { data, isLoading, isError, refetch, dataUpdatedAt } = useFindBackfillsForRules({
ruleIds: [ruleId],
page: pageIndex + 1,
perPage: pageSize,
});

const backfills: BackfillRow[] = getBackfillRowsFromResponse(data?.data ?? []);

Expand Down Expand Up @@ -197,7 +186,7 @@ export const RuleBackfillsInfo = React.memo<{ ruleId: string }>(({ ruleId }) =>
title={i18n.BACKFILL_TABLE_TITLE}
subtitle={i18n.BACKFILL_TABLE_SUBTITLE}
/>
<EuiBetaBadge label={TECHNICAL_PREVIEW} tooltipContent={TECHNICAL_PREVIEW_TOOLTIP} />
<EuiBetaBadge label={BETA} tooltipContent={BETA_TOOLTIP} />
</EuiFlexGroup>
</EuiFlexItem>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { MAX_MANUAL_RULE_RUN_BULK_SIZE } from '../../../../../../common/constant
import type { TimeRange } from '../../../../rule_gaps/types';
import { useKibana } from '../../../../../common/lib/kibana';
import { convertRulesFilterToKQL } from '../../../../../../common/detection_engine/rule_management/rule_filtering';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';
import { DuplicateOptions } from '../../../../../../common/detection_engine/rule_management/constants';
import type {
BulkActionEditPayload,
Expand Down Expand Up @@ -89,7 +88,6 @@ export const useBulkActions = ({
actions: { clearRulesSelection, setIsPreflightInProgress },
} = rulesTableContext;

const isManualRuleRunEnabled = useIsExperimentalFeatureEnabled('manualRuleRunEnabled');
const getBulkItemsPopoverContent = useCallback(
(closePopover: () => void): EuiContextMenuPanelDescriptor[] => {
const selectedRules = rules.filter(({ id }) => selectedRuleIds.includes(id));
Expand Down Expand Up @@ -448,18 +446,14 @@ export const useBulkActions = ({
onClick: handleExportAction,
icon: undefined,
},
...(isManualRuleRunEnabled
? [
{
key: i18n.BULK_ACTION_MANUAL_RULE_RUN,
name: i18n.BULK_ACTION_MANUAL_RULE_RUN,
'data-test-subj': 'scheduleRuleRunBulk',
disabled: containsLoading || (!containsEnabled && !isAllSelected),
onClick: handleScheduleRuleRunAction,
icon: undefined,
},
]
: []),
{
key: i18n.BULK_ACTION_MANUAL_RULE_RUN,
name: i18n.BULK_ACTION_MANUAL_RULE_RUN,
'data-test-subj': 'scheduleRuleRunBulk',
disabled: containsLoading || (!containsEnabled && !isAllSelected),
onClick: handleScheduleRuleRunAction,
icon: undefined,
},
{
key: i18n.BULK_ACTION_DISABLE,
name: i18n.BULK_ACTION_DISABLE,
Expand Down Expand Up @@ -600,7 +594,6 @@ export const useBulkActions = ({
filterOptions,
completeBulkEditForm,
startServices,
isManualRuleRunEnabled,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import type { DefaultItemAction } from '@elastic/eui';
import { EuiToolTip } from '@elastic/eui';
import React from 'react';
import { useIsExperimentalFeatureEnabled } from '../../../../common/hooks/use_experimental_features';
import { DuplicateOptions } from '../../../../../common/detection_engine/rule_management/constants';
import { BulkActionTypeEnum } from '../../../../../common/api/detection_engine/rule_management';
import { SINGLE_RULE_ACTIONS } from '../../../../common/lib/apm/user_actions';
Expand Down Expand Up @@ -47,8 +46,6 @@ export const useRulesTableActions = ({
const downloadExportedRules = useDownloadExportedRules();
const { scheduleRuleRun } = useScheduleRuleRun();

const isManualRuleRunEnabled = useIsExperimentalFeatureEnabled('manualRuleRunEnabled');

return [
{
type: 'icon',
Expand Down Expand Up @@ -120,33 +117,28 @@ export const useRulesTableActions = ({
},
enabled: (rule: Rule) => !rule.immutable,
},
...(isManualRuleRunEnabled
? [
{
type: 'icon',
'data-test-subj': 'manualRuleRunAction',
description: (rule) =>
!rule.enabled ? i18n.MANUAL_RULE_RUN_TOOLTIP : i18n.MANUAL_RULE_RUN,
icon: 'play',
name: i18n.MANUAL_RULE_RUN,
onClick: async (rule: Rule) => {
startTransaction({ name: SINGLE_RULE_ACTIONS.MANUAL_RULE_RUN });
const modalManualRuleRunConfirmationResult = await showManualRuleRunConfirmation();
telemetry.reportManualRuleRunOpenModal({
type: 'single',
});
if (modalManualRuleRunConfirmationResult === null) {
return;
}
await scheduleRuleRun({
ruleIds: [rule.id],
timeRange: modalManualRuleRunConfirmationResult,
});
},
enabled: (rule: Rule) => rule.enabled,
} as DefaultItemAction<Rule>,
]
: []),
{
type: 'icon',
'data-test-subj': 'manualRuleRunAction',
description: (rule) => (!rule.enabled ? i18n.MANUAL_RULE_RUN_TOOLTIP : i18n.MANUAL_RULE_RUN),
icon: 'play',
name: i18n.MANUAL_RULE_RUN,
onClick: async (rule: Rule) => {
startTransaction({ name: SINGLE_RULE_ACTIONS.MANUAL_RULE_RUN });
const modalManualRuleRunConfirmationResult = await showManualRuleRunConfirmation();
telemetry.reportManualRuleRunOpenModal({
type: 'single',
});
if (modalManualRuleRunConfirmationResult === null) {
return;
}
await scheduleRuleRun({
ruleIds: [rule.id],
timeRange: modalManualRuleRunConfirmationResult,
});
},
enabled: (rule: Rule) => rule.enabled,
},
{
type: 'icon',
'data-test-subj': 'deleteRuleAction',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,20 @@

import { useQuery } from '@tanstack/react-query';
import { useAppToasts } from '../../../../common/hooks/use_app_toasts';

import { RuleRunTypeEnum } from '../../../../../common/api/detection_engine/rule_monitoring';
import type { GetRuleExecutionResultsResponse } from '../../../../../common/api/detection_engine/rule_monitoring';
import type { FetchRuleExecutionResultsArgs } from '../../api';
import { api } from '../../api';
import { useIsExperimentalFeatureEnabled } from '../../../../common/hooks/use_experimental_features';
import * as i18n from './translations';

export type UseExecutionResultsArgs = Omit<FetchRuleExecutionResultsArgs, 'signal'>;

export const useExecutionResults = (args: UseExecutionResultsArgs) => {
const { addError } = useAppToasts();
const isManualRuleRunEnabled = useIsExperimentalFeatureEnabled('manualRuleRunEnabled');

return useQuery<GetRuleExecutionResultsResponse>(
['detectionEngine', 'ruleMonitoring', 'executionResults', args],
({ signal }) => {
let runTypeFilters = args.runTypeFilters;

// if manual rule run is disabled, only show standard runs
if (!isManualRuleRunEnabled) {
runTypeFilters = [RuleRunTypeEnum.standard];
}
const runTypeFilters = args.runTypeFilters;

return api.fetchRuleExecutionResults({ ...args, runTypeFilters, signal });
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,25 +274,6 @@ describe('RuleActionsOverflow', () => {
expect(getByTestId('rules-details-popover')).not.toHaveTextContent(/.+/);
});

test('it does not show "Manual run" action item when feature flag "manualRuleRunEnabled" is set to false', () => {
useIsExperimentalFeatureEnabledMock.mockReturnValue(false);

const { getByTestId } = render(
<RuleActionsOverflow
showBulkDuplicateExceptionsConfirmation={showBulkDuplicateExceptionsConfirmation}
showManualRuleRunConfirmation={showManualRuleRunConfirmation}
rule={mockRule('id')}
userHasPermissions
canDuplicateRuleWithActions={true}
confirmDeletion={() => Promise.resolve(true)}
/>,
{ wrapper: TestProviders }
);
fireEvent.click(getByTestId('rules-details-popover-button-icon'));

expect(getByTestId('rules-details-menu-panel')).not.toHaveTextContent('Manual run');
});

test('it calls telemetry.reportManualRuleRunOpenModal when rules-details-manual-rule-run is clicked', async () => {
const { getByTestId } = render(
<RuleActionsOverflow
Expand Down
Loading

0 comments on commit 3f75a1d

Please sign in to comment.