Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Actionable Observability] rules page read permissions & snoozed status & no data screen #128108

Merged
merged 22 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3a07e12
users with read permissions can not edit/delete/create rules
mgiota Mar 18, 2022
32ff27d
users with read permissions can not change the status
mgiota Mar 18, 2022
22d99c8
Merge branch 'main' of github.com:elastic/kibana into 123585_rules_pa…
mgiota Mar 18, 2022
dbeef85
Merge branch 'main' into 123585_rules_page_read_permissions
kibanamachine Mar 21, 2022
882de2e
clean up unused code
mgiota Mar 21, 2022
20607d6
localization for change status aria label
mgiota Mar 21, 2022
237cb23
remove console log
mgiota Mar 21, 2022
2d51427
add muted status
mgiota Mar 21, 2022
ca868ba
rename to snoozed
mgiota Mar 21, 2022
d87bd1c
remove unused imports
mgiota Mar 21, 2022
ab76864
rename snoozed to snoozed permanently
mgiota Mar 22, 2022
316a086
localize statuses
mgiota Mar 22, 2022
1699116
implement no data and no permission screen
mgiota Mar 22, 2022
f71fca7
fix prompt filenames
mgiota Mar 22, 2022
4685334
fix i18n error
mgiota Mar 22, 2022
f249324
Merge branch 'main' into 123585_rules_page_read_permissions
kibanamachine Mar 22, 2022
4b9937e
change permanently to indefinitely
mgiota Mar 22, 2022
7ddd805
do not show noData screen when filters are applied and don't match an…
mgiota Mar 23, 2022
bd5a873
add centered spinner on initial load
mgiota Mar 23, 2022
b98f947
move currrent functionality from triggers_actions_ui related to pagin…
mgiota Mar 23, 2022
d3e9162
disable status column if license is not enabled
mgiota Mar 23, 2022
e4c11f4
Merge branch 'main' into 123585_rules_page_read_permissions
kibanamachine Mar 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
*/

import React from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiLink, EuiText, EuiBadge } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiFlexGroup, EuiFlexItem, EuiLink, EuiText } from '@elastic/eui';
import { RuleNameProps } from '../types';
import { useKibana } from '../../../utils/kibana_react';

Expand All @@ -34,17 +33,5 @@ export function Name({ name, rule }: RuleNameProps) {
</EuiFlexItem>
</EuiFlexGroup>
);
return (
<>
{link}
{rule.enabled && rule.muteAll && (
<EuiBadge data-test-subj="mutedActionsBadge" color="hollow">
<FormattedMessage
id="xpack.observability.rules.rulesTable.columns.mutedBadge"
defaultMessage="Muted"
/>
</EuiBadge>
)}
</>
);
return <>{link}</>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,28 @@
* 2.0.
*/

import React from 'react';
import React, { useMemo } from 'react';
import { EuiBadge } from '@elastic/eui';
import { noop } from 'lodash/fp';
import { StatusProps } from '../types';
import { statusMap } from '../config';
import { RULES_CHANGE_STATUS } from '../translations';

export function Status({ type, onClick }: StatusProps) {
export function Status({ type, disabled, onClick }: StatusProps) {
const props = useMemo(
() => ({
color: statusMap[type].color,
...(!disabled ? { onClick } : { onClick: noop }),
...(!disabled ? { iconType: 'arrowDown', iconSide: 'right' as const } : {}),
...(!disabled ? { iconOnClick: onClick } : { iconOnClick: noop }),
}),
[disabled, onClick, type]
);
return (
<EuiBadge
color={statusMap[type].color}
iconType="arrowDown"
iconSide="right"
onClick={onClick}
onClickAriaLabel="Change status"
{...props}
onClickAriaLabel={RULES_CHANGE_STATUS}
iconOnClickAriaLabel={RULES_CHANGE_STATUS}
>
{statusMap[type].label}
</EuiBadge>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,26 @@ import { statusMap } from '../config';

export function StatusContext({
item,
disabled = false,
onStatusChanged,
enableRule,
disableRule,
muteRule,
unMuteRule,
}: StatusContextProps) {
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const [isUpdating, setIsUpdating] = useState(false);
const togglePopover = useCallback(() => setIsPopoverOpen(!isPopoverOpen), [isPopoverOpen]);

const currentStatus = item.enabled ? RuleStatus.enabled : RuleStatus.disabled;
let currentStatus: RuleStatus;
if (item.enabled) {
currentStatus = item.muteAll ? RuleStatus.snoozed : RuleStatus.enabled;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to have a rule enabled and muted at the same time?

I assume snoozed == muteAll, right? The API that provides the item is using muteAll

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fkanout Yep we are using muteAll for the snoozed (indefinitely) state. And yes a rule can be enabled and muted at the same time. I had similar questions here #123580 (comment) and we ended up with @katrin-freihofner on following:

  • If it is only enabled the Enabled state is shown in the UI
  • If it is snoozed, then the Snoozed indefinitely state is shown in the UI, and yep it is enabled as well.
  • To unmute/unsnooze user needs to select enabled (behind the scenes it enables and unmutes the rule)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mgiota, excellent explanation, thanks!
snoozed + enabled will keep the rule but it will not generate alerts?

} else {
currentStatus = RuleStatus.disabled;
}
const popOverButton = useMemo(
() => <Status type={currentStatus} onClick={togglePopover} />,
[currentStatus, togglePopover]
() => <Status disabled={disabled} type={currentStatus} onClick={togglePopover} />,
[disabled, currentStatus, togglePopover]
);

const onContextMenuItemClick = useCallback(
Expand All @@ -41,22 +48,38 @@ export function StatusContext({

if (status === RuleStatus.enabled) {
await enableRule({ ...item, enabled: true });
if (item.muteAll) {
await unMuteRule({ ...item, muteAll: false });
}
} else if (status === RuleStatus.disabled) {
await disableRule({ ...item, enabled: false });
} else if (status === RuleStatus.snoozed) {
XavierM marked this conversation as resolved.
Show resolved Hide resolved
await muteRule({ ...item, muteAll: true });
}
setIsUpdating(false);
onStatusChanged(status);
}
},
[item, togglePopover, enableRule, disableRule, currentStatus, onStatusChanged]
[
item,
togglePopover,
enableRule,
disableRule,
muteRule,
unMuteRule,
currentStatus,
onStatusChanged,
]
);

const panelItems = useMemo(
() =>
Object.values(RuleStatus).map((status: RuleStatus) => (
<EuiContextMenuItem
icon={status === currentStatus ? 'check' : 'empty'}
key={status}
onClick={() => onContextMenuItemClick(status)}
disabled={status === RuleStatus.snoozed && currentStatus === RuleStatus.disabled}
>
{statusMap[status].label}
</EuiContextMenuItem>
Expand Down
9 changes: 9 additions & 0 deletions x-pack/plugins/observability/public/pages/rules/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export const statusMap: Status = {
color: 'default',
label: 'Disabled',
},
[RuleStatus.snoozed]: {
color: 'warning',
label: 'Snoozed',
},
};

export const DEFAULT_SEARCH_PAGE_SIZE: number = 25;
Expand Down Expand Up @@ -93,3 +97,8 @@ export function convertRulesToTableItems(
enabledInLicense: !!ruleTypeIndex.get(rule.ruleTypeId)?.enabledInLicense,
}));
}

type Capabilities = Record<string, any>;

export const hasExecuteActionsCapability = (capabilities: Capabilities) =>
capabilities?.actions?.execute;
52 changes: 37 additions & 15 deletions x-pack/plugins/observability/public/pages/rules/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ import {
disableRule,
muteRule,
useLoadRuleTypes,
unmuteRule,
} from '../../../../triggers_actions_ui/public';
import { AlertExecutionStatus, ALERTS_FEATURE_ID } from '../../../../alerting/common';
import { Pagination } from './types';
import {
DEFAULT_SEARCH_PAGE_SIZE,
convertRulesToTableItems,
OBSERVABILITY_SOLUTIONS,
hasExecuteActionsCapability,
} from './config';
import {
LAST_RESPONSE_COLUMN_TITLE,
Expand Down Expand Up @@ -73,9 +75,11 @@ export function RulesPage() {
http,
docLinks,
triggersActionsUi,
application: { capabilities },
notifications: { toasts },
} = useKibana().services;

const ruleTypeRegistry = triggersActionsUi.ruleTypeRegistry;
const canExecuteActions = hasExecuteActionsCapability(capabilities);
const [page, setPage] = useState<Pagination>({ index: 0, size: DEFAULT_SEARCH_PAGE_SIZE });
const [sort, setSort] = useState<EuiTableSortingType<RuleTableItem>['sort']>({
field: 'name',
Expand All @@ -90,6 +94,9 @@ export function RulesPage() {
const [rulesToDelete, setRulesToDelete] = useState<string[]>([]);
const [createRuleFlyoutVisibility, setCreateRuleFlyoutVisibility] = useState(false);

const isRuleTypeEditableInContext = (ruleTypeId: string) =>
ruleTypeRegistry.has(ruleTypeId) ? !ruleTypeRegistry.get(ruleTypeId).requiresAppContext : false;

const onRuleEdit = (ruleItem: RuleTableItem) => {
setCurrentRuleToEdit(ruleItem);
};
Expand All @@ -109,7 +116,14 @@ export function RulesPage() {
sort,
});
const { data: rules, totalItemCount, error } = rulesState;
const { ruleTypeIndex } = useLoadRuleTypes({ filteredSolutions: OBSERVABILITY_SOLUTIONS });
const { ruleTypeIndex, ruleTypes } = useLoadRuleTypes({
filteredSolutions: OBSERVABILITY_SOLUTIONS,
});
const authorizedRuleTypes = [...ruleTypes.values()];

const authorizedToCreateAnyRules = authorizedRuleTypes.some(
(ruleType) => ruleType.authorizedConsumers[ALERTS_FEATURE_ID]?.all
);

useEffect(() => {
const interval = setInterval(() => {
Expand Down Expand Up @@ -161,11 +175,13 @@ export function RulesPage() {
render: (_enabled: boolean, item: RuleTableItem) => {
return (
<StatusContext
disabled={!item.isEditable}
item={item}
onStatusChanged={() => reload()}
enableRule={async () => await enableRule({ http, id: item.id })}
disableRule={async () => await disableRule({ http, id: item.id })}
muteRule={async () => await muteRule({ http, id: item.id })}
unMuteRule={async () => await unmuteRule({ http, id: item.id })}
/>
);
},
Expand All @@ -180,6 +196,9 @@ export function RulesPage() {
<EuiFlexGroup justifyContent="flexEnd" gutterSize="s">
<EuiFlexItem grow={false} data-test-subj="ruleSidebarEditAction">
<EuiButtonIcon
isDisabled={
!(item.isEditable && isRuleTypeEditableInContext(item.ruleTypeId))
}
color={'primary'}
title={EDIT_ACTION_TOOLTIP}
className="ruleSidebarItem__action"
Expand All @@ -191,6 +210,7 @@ export function RulesPage() {
</EuiFlexItem>
<EuiFlexItem grow={false} data-test-subj="ruleSidebarDeleteAction">
<EuiButtonIcon
isDisabled={!item.isEditable}
color={'danger'}
title={DELETE_ACTION_TOOLTIP}
className="ruleSidebarItem__action"
Expand Down Expand Up @@ -232,18 +252,20 @@ export function RulesPage() {
</>
),
rightSideItems: [
<EuiButton
iconType="plusInCircle"
key="create-alert"
data-test-subj="createRuleButton"
fill
onClick={() => setCreateRuleFlyoutVisibility(true)}
>
<FormattedMessage
id="xpack.observability.rules.addRuleButtonLabel"
defaultMessage="Create rule"
/>
</EuiButton>,
authorizedToCreateAnyRules && (
<EuiButton
iconType="plusInCircle"
key="create-alert"
data-test-subj="createRuleButton"
fill
onClick={() => setCreateRuleFlyoutVisibility(true)}
>
<FormattedMessage
id="xpack.observability.rules.addRuleButtonLabel"
defaultMessage="Create rule"
/>
</EuiButton>
),
<EuiButtonEmpty
href={docLinks.links.alerting.guide}
target="_blank"
Expand Down Expand Up @@ -351,7 +373,7 @@ export function RulesPage() {
<EuiFlexItem>
<RulesTable
columns={getRulesTableColumns()}
rules={convertRulesToTableItems(rules, ruleTypeIndex, true)} // TODO add canExecuteActions and remove hardcoded true value
rules={convertRulesToTableItems(rules, ruleTypeIndex, canExecuteActions)}
isLoading={rulesState.isLoading}
page={page}
totalItemCount={totalItemCount}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ export const SEARCH_PLACEHOLDER = i18n.translate(
{ defaultMessage: 'Search' }
);

export const RULES_CHANGE_STATUS = i18n.translate(
'xpack.observability.rules.rulesTable.changeStatusAriaLabel',
{
defaultMessage: 'Change status',
}
);

export const confirmModalText = (
numIdsToDelete: number,
singleTitle: string,
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/observability/public/pages/rules/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { AlertExecutionStatus } from '../../../../alerting/common';
import { RuleTableItem, Rule } from '../../../../triggers_actions_ui/public';
export interface StatusProps {
type: RuleStatus;
disabled: boolean;
onClick: () => void;
}

export enum RuleStatus {
enabled = 'enabled',
disabled = 'disabled',
snoozed = 'snoozed',
}

export type Status = Record<
Expand All @@ -27,10 +29,12 @@ export type Status = Record<

export interface StatusContextProps {
item: RuleTableItem;
disabled: boolean;
onStatusChanged: (status: RuleStatus) => void;
enableRule: (rule: Rule) => Promise<void>;
disableRule: (rule: Rule) => Promise<void>;
muteRule: (rule: Rule) => Promise<void>;
unMuteRule: (rule: Rule) => Promise<void>;
}

export interface StatusFilterProps {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/triggers_actions_ui/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export { deleteRules } from './application/lib/rule_api/delete';
export { enableRule } from './application/lib/rule_api/enable';
export { disableRule } from './application/lib/rule_api/disable';
export { muteRule } from './application/lib/rule_api/mute';
export { unmuteRule } from './application/lib/rule_api/unmute';
export { loadRuleAggregations } from './application/lib/rule_api/aggregate';
export { useLoadRuleTypes } from './application/hooks/use_load_rule_types';

Expand Down