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 all 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
24 changes: 22 additions & 2 deletions x-pack/plugins/observability/public/hooks/use_fetch_rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { useEffect, useState, useCallback } from 'react';
import { isEmpty } from 'lodash';
import { loadRules, Rule } from '../../../triggers_actions_ui/public';
import { RULES_LOAD_ERROR } from '../pages/rules/translations';
import { FetchRulesProps } from '../pages/rules/types';
Expand All @@ -19,7 +20,13 @@ interface RuleState {
totalItemCount: number;
}

export function useFetchRules({ searchText, ruleLastResponseFilter, page, sort }: FetchRulesProps) {
export function useFetchRules({
searchText,
ruleLastResponseFilter,
setPage,
page,
sort,
}: FetchRulesProps) {
const { http } = useKibana().services;

const [rulesState, setRulesState] = useState<RuleState>({
Expand All @@ -29,6 +36,9 @@ export function useFetchRules({ searchText, ruleLastResponseFilter, page, sort }
totalItemCount: 0,
});

const [noData, setNoData] = useState<boolean>(true);
const [initialLoad, setInitialLoad] = useState<boolean>(true);

const fetchRules = useCallback(async () => {
setRulesState((oldState) => ({ ...oldState, isLoading: true }));

Expand All @@ -47,10 +57,18 @@ export function useFetchRules({ searchText, ruleLastResponseFilter, page, sort }
data: response.data,
totalItemCount: response.total,
}));

if (!response.data?.length && page.index > 0) {
setPage({ ...page, index: 0 });
}
const isFilterApplied = !(isEmpty(searchText) && isEmpty(ruleLastResponseFilter));

setNoData(response.data.length === 0 && !isFilterApplied);
} catch (_e) {
setRulesState((oldState) => ({ ...oldState, isLoading: false, error: RULES_LOAD_ERROR }));
}
}, [http, page, searchText, ruleLastResponseFilter, sort]);
setInitialLoad(false);
}, [http, page, setPage, searchText, ruleLastResponseFilter, sort]);
useEffect(() => {
fetchRules();
}, [fetchRules]);
Expand All @@ -59,5 +77,7 @@ export function useFetchRules({ searchText, ruleLastResponseFilter, page, sort }
rulesState,
reload: fetchRules,
setRulesState,
noData,
initialLoad,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 { EuiFlexGroup, EuiFlexItem, EuiLoadingSpinner } from '@elastic/eui';
import { EuiLoadingSpinnerSize } from '@elastic/eui/src/components/loading/loading_spinner';

interface Props {
size?: EuiLoadingSpinnerSize;
}

export function CenterJustifiedSpinner({ size }: Props) {
return (
<EuiFlexGroup data-test-subj="centerJustifiedSpinner" justifyContent="center">
<EuiFlexItem grow={false}>
<EuiLoadingSpinner size={size || 'xl'} />
</EuiFlexItem>
</EuiFlexGroup>
);
}
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
@@ -0,0 +1,69 @@
/*
* 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 { FormattedMessage } from '@kbn/i18n-react';
import React from 'react';
import { EuiButton, EuiEmptyPrompt, EuiLink, EuiButtonEmpty, EuiPageTemplate } from '@elastic/eui';

export function NoDataPrompt({
onCTAClicked,
documentationLink,
}: {
onCTAClicked: () => void;
documentationLink: string;
}) {
return (
<EuiPageTemplate
template="centeredContent"
pageContentProps={{
paddingSize: 'none',
role: null, // For passing a11y tests in EUI docs only
}}
>
<EuiEmptyPrompt
color="plain"
hasBorder={true}
data-test-subj="createFirstRuleEmptyPrompt"
title={
<h2>
<FormattedMessage
id="xpack.observability.rules.emptyPrompt.emptyTitle"
defaultMessage="Create your first Rule"
/>
</h2>
}
body={
<p>
<FormattedMessage
id="xpack.observability.rules.noDataPrompt.noDataDesc"
defaultMessage="Rules allow you to receive alerts and automate custom actions when specific conditions are met."
/>
</p>
}
actions={[
<EuiButton
iconType="plusInCircle"
data-test-subj="createFirstRuleButton"
key="create-action"
fill
onClick={onCTAClicked}
>
<FormattedMessage
id="xpack.observability.rules.emptyPrompt.emptyButton"
defaultMessage="Create Rule"
/>
</EuiButton>,
<EuiButtonEmpty color="primary">
<EuiLink href={documentationLink} target="_blank">
Documentation
</EuiLink>
</EuiButtonEmpty>,
]}
/>
</EuiPageTemplate>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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 { FormattedMessage } from '@kbn/i18n-react';
import React from 'react';
import { EuiEmptyPrompt, EuiPageTemplate } from '@elastic/eui';

export function NoPermissionPrompt() {
return (
<EuiPageTemplate
template="centeredContent"
pageContentProps={{
paddingSize: 'none',
role: null, // For passing a11y tests in EUI docs only
}}
>
<EuiEmptyPrompt
color="plain"
hasBorder={true}
iconType="securityApp"
title={
<h1>
<FormattedMessage
id="xpack.observability.rules.noPermissionToCreateTitle"
defaultMessage="No permissions to create rules"
/>
</h1>
}
body={
<p data-test-subj="permissionDeniedMessage">
<FormattedMessage
id="xpack.observability.rules.noPermissionToCreateDescription"
defaultMessage="Contact your system administrator."
/>
</p>
}
/>
</EuiPageTemplate>
);
}
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
16 changes: 14 additions & 2 deletions x-pack/plugins/observability/public/pages/rules/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,25 @@ import {
RULE_STATUS_PENDING,
RULE_STATUS_UNKNOWN,
RULE_STATUS_WARNING,
RULE_STATUS_ENABLED,
RULE_STATUS_DISABLED,
RULE_STATUS_SNOOZED_INDEFINITELY,
} from './translations';
import { AlertExecutionStatuses } from '../../../../alerting/common';
import { Rule, RuleTypeIndex, RuleType } from '../../../../triggers_actions_ui/public';

export const statusMap: Status = {
[RuleStatus.enabled]: {
color: 'primary',
label: 'Enabled',
label: RULE_STATUS_ENABLED,
},
[RuleStatus.disabled]: {
color: 'default',
label: 'Disabled',
label: RULE_STATUS_DISABLED,
},
[RuleStatus.snoozed]: {
color: 'warning',
label: RULE_STATUS_SNOOZED_INDEFINITELY,
},
};

Expand Down Expand Up @@ -93,3 +100,8 @@ export function convertRulesToTableItems(
enabledInLicense: !!ruleTypeIndex.get(rule.ruleTypeId)?.enabledInLicense,
}));
}

type Capabilities = Record<string, any>;

export const hasExecuteActionsCapability = (capabilities: Capabilities) =>
capabilities?.actions?.execute;
Loading