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

[RAM] Update Rule Status - UI Changes #144466

Merged
merged 58 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
1dd3687
re-structure migrations code
XavierM Sep 13, 2022
d1ca8f0
change mappings to match new design
XavierM Sep 13, 2022
0b74e72
wip
XavierM Sep 14, 2022
bbfc35a
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Sep 16, 2022
5579627
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Sep 16, 2022
defdf85
Merge branch 'main' of github.com:elastic/kibana into 136039-rules-st…
XavierM Oct 17, 2022
1707107
wip to add a monitoring service
XavierM Oct 28, 2022
eb8ce8b
Merge branch 'main' of github.com:elastic/kibana into 136039-rules-st…
XavierM Oct 28, 2022
7ca2fc2
Merge branch '136039-rules-status' of github.com:XavierM/kibana into …
XavierM Oct 28, 2022
c882426
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Oct 28, 2022
0fe91eb
jiawei work on backend of rule
JiaweiWu Nov 1, 2022
6b4531f
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Nov 1, 2022
4a1de41
Fix conflicts
JiaweiWu Nov 1, 2022
6430691
Fix some of the missing functions used in rules_client
JiaweiWu Nov 1, 2022
2bc3b35
consolidate status frontend changes
JiaweiWu Nov 1, 2022
4c57e09
Fix types and unit tests
JiaweiWu Nov 3, 2022
2151d4f
Removing running and fix associated tests
JiaweiWu Nov 3, 2022
aa1977c
Remove more references to running
JiaweiWu Nov 3, 2022
992cccb
Address comments and update task runner tests
JiaweiWu Nov 4, 2022
a907217
Fix and add more tests
JiaweiWu Nov 7, 2022
55f2cae
Merge branch 'main' into 136039-rules-status
kibanamachine Nov 7, 2022
74269ac
Migration unit and integration tests, fixed some more tests
JiaweiWu Nov 7, 2022
6fdf08f
Merge branch 'main' into 136039-rules-status
kibanamachine Nov 7, 2022
be1feb3
Fix types
JiaweiWu Nov 7, 2022
d404fd8
Fix tests and types
JiaweiWu Nov 8, 2022
8da8345
Fix SO migration snapshot, add more task runner tests
JiaweiWu Nov 8, 2022
1345ac2
Merge branch 'main' into 136039-rules-status
kibanamachine Nov 8, 2022
daac93e
Fix type check
JiaweiWu Nov 9, 2022
9a70231
Fix type check
JiaweiWu Nov 9, 2022
f0b1c66
Merge branch 'main' into 136039-rules-status
kibanamachine Nov 9, 2022
7c14e08
Merge branch '136039-rules-status' of https://github.com/XavierM/kiba…
JiaweiWu Nov 9, 2022
439ae75
Fix tests
JiaweiWu Nov 10, 2022
897ec3f
Fix more types
JiaweiWu Nov 10, 2022
cae7541
Merge branch 'main' of github.com:elastic/kibana into 136039-rules-st…
XavierM Nov 10, 2022
2ce6b6e
Address comments
JiaweiWu Nov 14, 2022
d0b5298
Update rule monitoring mock
JiaweiWu Nov 14, 2022
bbef4eb
Merge branch 'main' into 136039-rules-status
kibanamachine Nov 14, 2022
1bc1db7
Merge branch '136039-rules-status' of github.com:XavierM/kibana into …
XavierM Nov 14, 2022
d9a6b9d
add more test
XavierM Nov 14, 2022
1869e17
unit test
XavierM Nov 14, 2022
c8e1da5
Merge branch 'main' into 136039-rules-status
kibanamachine Nov 14, 2022
f2e4735
fix type
XavierM Nov 14, 2022
fad9da5
Merge branch '136039-rules-status' of github.com:XavierM/kibana into …
XavierM Nov 14, 2022
49d07a1
Merge branch 'main' into 136039-rules-status
kibanamachine Nov 14, 2022
367b3d8
Merge branch 'main' into 136039-rules-status
kibanamachine Nov 14, 2022
3576550
merge conflicts
JiaweiWu Nov 14, 2022
9b73b61
fix translations
JiaweiWu Nov 14, 2022
2de0983
Merge branch 'main' into 136039-rules-status-deploy
kibanamachine Nov 14, 2022
345c32a
Add no data for newly created rules, add unit tests
JiaweiWu Nov 14, 2022
a4e15c3
Merge branch '136039-rules-status-deploy' of https://github.com/Jiawe…
JiaweiWu Nov 14, 2022
789384e
Merge branch 'main' into 136039-rules-status-deploy
kibanamachine Nov 14, 2022
8d222b4
Address comments
JiaweiWu Nov 15, 2022
725a38b
Address comments
JiaweiWu Nov 15, 2022
cd9a6ec
Fix type check and add loading indicator to rule details
JiaweiWu Nov 15, 2022
ab0e401
Fix types, again
JiaweiWu Nov 15, 2022
6872e67
Merge branch 'main' into 136039-rules-status-deploy
kibanamachine Nov 15, 2022
ed54bb8
Merge branch 'main' into 136039-rules-status-deploy
kibanamachine Nov 15, 2022
60b7d97
Merge branch 'main' into 136039-rules-status-deploy
kibanamachine Nov 15, 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 @@ -40,7 +40,7 @@ const getMockRule = () => {
error: null,
},
monitoring: {
execution: {
run: {
history: [
{
success: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export const StorybookContextDecorator: React.FC<StorybookContextDecoratorProps>
ruleTagFilter: true,
ruleStatusFilter: true,
rulesDetailLogs: true,
ruleLastRunOutcome: true,
},
});
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const allowedExperimentalValues = Object.freeze({
ruleTagFilter: true,
ruleStatusFilter: true,
rulesDetailLogs: true,
ruleLastRunOutcome: true,
});

type ExperimentalConfigKeys = Array<keyof ExperimentalFeatures>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ interface UseBulkEditSelectProps {
actionTypesFilter?: string[];
tagsFilter?: string[];
ruleExecutionStatusesFilter?: string[];
ruleLastRunOutcomesFilter?: string[];
ruleStatusesFilter?: RuleStatus[];
searchText?: string;
}
Expand All @@ -89,6 +90,7 @@ export function useBulkEditSelect(props: UseBulkEditSelectProps) {
actionTypesFilter,
tagsFilter,
ruleExecutionStatusesFilter,
ruleLastRunOutcomesFilter,
ruleStatusesFilter,
searchText,
} = props;
Expand Down Expand Up @@ -187,6 +189,7 @@ export function useBulkEditSelect(props: UseBulkEditSelectProps) {
actionTypesFilter,
tagsFilter,
ruleExecutionStatusesFilter,
ruleLastRunOutcomesFilter,
ruleStatusesFilter,
searchText,
});
Expand All @@ -208,6 +211,7 @@ export function useBulkEditSelect(props: UseBulkEditSelectProps) {
actionTypesFilter,
tagsFilter,
ruleExecutionStatusesFilter,
ruleLastRunOutcomesFilter,
ruleStatusesFilter,
searchText,
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@

import { i18n } from '@kbn/i18n';
import { useState, useCallback, useMemo } from 'react';
import { RuleExecutionStatusValues } from '@kbn/alerting-plugin/common';
import { RuleExecutionStatusValues, RuleLastRunOutcomeValues } from '@kbn/alerting-plugin/common';
import type { LoadRuleAggregationsProps } from '../lib/rule_api';
import { loadRuleAggregationsWithKueryFilter } from '../lib/rule_api/aggregate_kuery_filter';
import { useKibana } from '../../common/lib/kibana';

const initializeAggregationResult = (values: readonly string[]) => {
return values.reduce<Record<string, number>>(
(prev: Record<string, number>, status: string) => ({
...prev,
[status]: 0,
}),
{}
);
};

type UseLoadRuleAggregationsProps = Omit<LoadRuleAggregationsProps, 'http'> & {
onError: (message: string) => void;
};
Expand All @@ -21,22 +31,21 @@ export function useLoadRuleAggregations({
typesFilter,
actionTypesFilter,
ruleExecutionStatusesFilter,
ruleLastRunOutcomesFilter,
ruleStatusesFilter,
tagsFilter,
onError,
}: UseLoadRuleAggregationsProps) {
const { http } = useKibana().services;

const [rulesStatusesTotal, setRulesStatusesTotal] = useState<Record<string, number>>(
RuleExecutionStatusValues.reduce<Record<string, number>>(
(prev: Record<string, number>, status: string) => ({
...prev,
[status]: 0,
}),
{}
)
initializeAggregationResult(RuleExecutionStatusValues)
);

const [rulesLastRunOutcomesTotal, setRulesLastRunOutcomesTotal] = useState<
Record<string, number>
>(initializeAggregationResult(RuleLastRunOutcomeValues));

const internalLoadRuleAggregations = useCallback(async () => {
try {
const rulesAggs = await loadRuleAggregationsWithKueryFilter({
Expand All @@ -45,12 +54,16 @@ export function useLoadRuleAggregations({
typesFilter,
actionTypesFilter,
ruleExecutionStatusesFilter,
ruleLastRunOutcomesFilter,
ruleStatusesFilter,
tagsFilter,
});
if (rulesAggs?.ruleExecutionStatus) {
setRulesStatusesTotal(rulesAggs.ruleExecutionStatus);
}
if (rulesAggs?.ruleLastRunOutcome) {
setRulesLastRunOutcomesTotal(rulesAggs.ruleLastRunOutcome);
}
} catch (e) {
onError(
i18n.translate(
Expand All @@ -67,18 +80,28 @@ export function useLoadRuleAggregations({
typesFilter,
actionTypesFilter,
ruleExecutionStatusesFilter,
ruleLastRunOutcomesFilter,
ruleStatusesFilter,
tagsFilter,
onError,
setRulesStatusesTotal,
setRulesLastRunOutcomesTotal,
]);

return useMemo(
() => ({
loadRuleAggregations: internalLoadRuleAggregations,
rulesStatusesTotal,
rulesLastRunOutcomesTotal,
setRulesStatusesTotal,
setRulesLastRunOutcomesTotal,
}),
[internalLoadRuleAggregations, rulesStatusesTotal, setRulesStatusesTotal]
[
internalLoadRuleAggregations,
rulesStatusesTotal,
rulesLastRunOutcomesTotal,
setRulesStatusesTotal,
setRulesLastRunOutcomesTotal,
]
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export function useLoadRules({
typesFilter,
actionTypesFilter,
ruleExecutionStatusesFilter,
ruleLastRunOutcomesFilter,
ruleStatusesFilter,
tagsFilter,
sort,
Expand Down Expand Up @@ -120,6 +121,7 @@ export function useLoadRules({
typesFilter,
actionTypesFilter,
ruleExecutionStatusesFilter,
ruleLastRunOutcomesFilter,
ruleStatusesFilter,
tagsFilter,
sort,
Expand All @@ -144,6 +146,7 @@ export function useLoadRules({
hasEmptyTypesFilter &&
isEmpty(actionTypesFilter) &&
isEmpty(ruleExecutionStatusesFilter) &&
isEmpty(ruleLastRunOutcomesFilter) &&
isEmpty(ruleStatusesFilter) &&
isEmpty(tagsFilter)
);
Expand All @@ -168,6 +171,7 @@ export function useLoadRules({
typesFilter,
actionTypesFilter,
ruleExecutionStatusesFilter,
ruleLastRunOutcomesFilter,
ruleStatusesFilter,
tagsFilter,
sort,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface RuleTagsAggregations {

export const rewriteBodyRes: RewriteRequestCase<RuleAggregations> = ({
rule_execution_status: ruleExecutionStatus,
rule_last_run_outcome: ruleLastRunOutcome,
rule_enabled_status: ruleEnabledStatus,
rule_muted_status: ruleMutedStatus,
rule_snoozed_status: ruleSnoozedStatus,
Expand All @@ -26,6 +27,7 @@ export const rewriteBodyRes: RewriteRequestCase<RuleAggregations> = ({
ruleEnabledStatus,
ruleMutedStatus,
ruleSnoozedStatus,
ruleLastRunOutcome,
ruleTags,
});

Expand All @@ -41,6 +43,7 @@ export interface LoadRuleAggregationsProps {
typesFilter?: string[];
actionTypesFilter?: string[];
ruleExecutionStatusesFilter?: string[];
ruleLastRunOutcomesFilter?: string[];
ruleStatusesFilter?: RuleStatus[];
tagsFilter?: string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import { RuleExecutionStatus } from '@kbn/alerting-plugin/common';
import { AsApiContract, RewriteRequestCase } from '@kbn/actions-plugin/common';
import { Rule, RuleAction, ResolvedRule } from '../../../types';
import { Rule, RuleAction, ResolvedRule, RuleLastRun } from '../../../types';

const transformAction: RewriteRequestCase<RuleAction> = ({
group,
Expand All @@ -30,6 +30,16 @@ const transformExecutionStatus: RewriteRequestCase<RuleExecutionStatus> = ({
...rest,
});

const transformLastRun: RewriteRequestCase<RuleLastRun> = ({
outcome_msg: outcomeMsg,
alerts_count: alertsCount,
...rest
}) => ({
outcomeMsg,
alertsCount,
...rest,
});

export const transformRule: RewriteRequestCase<Rule> = ({
rule_type_id: ruleTypeId,
created_by: createdBy,
Expand All @@ -46,6 +56,8 @@ export const transformRule: RewriteRequestCase<Rule> = ({
snooze_schedule: snoozeSchedule,
is_snoozed_until: isSnoozedUntil,
active_snoozes: activeSnoozes,
last_run: lastRun,
next_run: nextRun,
...rest
}: any) => ({
ruleTypeId,
Expand All @@ -65,6 +77,8 @@ export const transformRule: RewriteRequestCase<Rule> = ({
scheduledTaskId,
isSnoozedUntil,
activeSnoozes,
...(lastRun ? { lastRun: transformLastRun(lastRun) } : {}),
...(nextRun ? { nextRun } : {}),
...rest,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import { transformRule } from './common_transformations';

type RuleCreateBody = Omit<
RuleUpdates,
'createdBy' | 'updatedBy' | 'muteAll' | 'mutedInstanceIds' | 'executionStatus'
| 'createdBy'
| 'updatedBy'
| 'muteAll'
| 'mutedInstanceIds'
| 'executionStatus'
| 'lastRun'
| 'nextRun'
>;
const rewriteBodyRequest: RewriteResponseCase<RuleCreateBody> = ({
ruleTypeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,30 @@ describe('mapFiltersToKueryNode', () => {
);
});

test('should handle ruleLastRunOutcomesFilter', () => {
expect(
toElasticsearchQuery(
mapFiltersToKueryNode({
ruleLastRunOutcomesFilter: ['succeeded'],
}) as KueryNode
)
).toEqual(
toElasticsearchQuery(fromKueryExpression('alert.attributes.lastRun.outcome: succeeded'))
);

expect(
toElasticsearchQuery(
mapFiltersToKueryNode({
ruleLastRunOutcomesFilter: ['succeeded', 'failed', 'warning'],
}) as KueryNode
)
).toEqual(
toElasticsearchQuery(
fromKueryExpression('alert.attributes.lastRun.outcome: (succeeded or failed or warning)')
)
);
});

test('should handle ruleStatusesFilter', () => {
expect(
toElasticsearchQuery(
Expand Down Expand Up @@ -260,6 +284,7 @@ describe('mapFiltersToKueryNode', () => {
typesFilter: ['type', 'filter'],
actionTypesFilter: ['action', 'types', 'filter'],
ruleExecutionStatusesFilter: ['alert', 'statuses', 'filter'],
ruleLastRunOutcomesFilter: ['warning', 'failed'],
tagsFilter: ['a', 'b', 'c'],
}) as KueryNode
)
Expand All @@ -271,6 +296,7 @@ describe('mapFiltersToKueryNode', () => {
alert.attributes.actions:{ actionTypeId:types } OR
alert.attributes.actions:{ actionTypeId:filter }) and
alert.attributes.executionStatus.status:(alert or statuses or filter) and
alert.attributes.lastRun.outcome:(warning or failed) and
alert.attributes.tags:(a or b or c)`
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const mapFiltersToKueryNode = ({
typesFilter,
actionTypesFilter,
ruleExecutionStatusesFilter,
ruleLastRunOutcomesFilter,
ruleStatusesFilter,
tagsFilter,
searchText,
Expand All @@ -20,6 +21,7 @@ export const mapFiltersToKueryNode = ({
actionTypesFilter?: string[];
tagsFilter?: string[];
ruleExecutionStatusesFilter?: string[];
ruleLastRunOutcomesFilter?: string[];
ruleStatusesFilter?: RuleStatus[];
searchText?: string;
}): KueryNode | null => {
Expand Down Expand Up @@ -51,6 +53,16 @@ export const mapFiltersToKueryNode = ({
);
}

if (ruleLastRunOutcomesFilter && ruleLastRunOutcomesFilter.length) {
XavierM marked this conversation as resolved.
Show resolved Hide resolved
filterKueryNode.push(
nodeBuilder.or(
ruleLastRunOutcomesFilter.map((resf) =>
nodeBuilder.is('alert.attributes.lastRun.outcome', resf)
)
)
);
}

if (ruleStatusesFilter && ruleStatusesFilter.length) {
const snoozedFilter = nodeBuilder.or([
fromKueryExpression('alert.attributes.muteAll: true'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface LoadRulesProps {
actionTypesFilter?: string[];
tagsFilter?: string[];
ruleExecutionStatusesFilter?: string[];
ruleLastRunOutcomesFilter?: string[];
ruleStatusesFilter?: RuleStatus[];
sort?: Sorting;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export async function loadRulesWithKueryFilter({
typesFilter,
actionTypesFilter,
ruleExecutionStatusesFilter,
ruleLastRunOutcomesFilter,
ruleStatusesFilter,
tagsFilter,
sort = { field: 'name', direction: 'asc' },
Expand All @@ -32,6 +33,7 @@ export async function loadRulesWithKueryFilter({
actionTypesFilter,
tagsFilter,
ruleExecutionStatusesFilter,
ruleLastRunOutcomesFilter,
ruleStatusesFilter,
searchText,
});
Expand Down
Loading