mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[8.11] [RAM][Bug] Fix bug preventing filters from being added to conditional actions (#171048) (#171362)
# Backport This will backport the following commits from `main` to `8.11`: - [[RAM][Bug] Fix bug preventing filters from being added to conditional actions (#171048)](https://github.com/elastic/kibana/pull/171048) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Jiawei Wu","email":"74562234+JiaweiWu@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-11-15T19:38:50Z","message":"[RAM][Bug] Fix bug preventing filters from being added to conditional actions (#171048)\n\n## Summary\r\nResolves: https://github.com/elastic/kibana/issues/171036\r\n\r\nFixes a bug where the schema name for the conditional action filter\r\n`$state` was incorrectly name. This prevented the user from adding\r\nfilters to conditional actions as the schema validation would reject the\r\nrequest.\r\n\r\n### To verify the fix:\r\n\r\n1. Create a rule\r\n2. Add a conditional action\r\n3. Assert that filters can be added to the rule\r\n4. Rule is saved\r\n5. Repeat 1 - 4 but this time, update the rule. \r\n\r\n### Checklist\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>","sha":"fbb232815b85961ac09b6abbe369eb7b3760752d","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:ResponseOps","Feature:Alerting/RulesManagement","v8.12.0","v8.11.1","v8.10.5"],"number":171048,"url":"https://github.com/elastic/kibana/pull/171048","mergeCommit":{"message":"[RAM][Bug] Fix bug preventing filters from being added to conditional actions (#171048)\n\n## Summary\r\nResolves: https://github.com/elastic/kibana/issues/171036\r\n\r\nFixes a bug where the schema name for the conditional action filter\r\n`$state` was incorrectly name. This prevented the user from adding\r\nfilters to conditional actions as the schema validation would reject the\r\nrequest.\r\n\r\n### To verify the fix:\r\n\r\n1. Create a rule\r\n2. Add a conditional action\r\n3. Assert that filters can be added to the rule\r\n4. Rule is saved\r\n5. Repeat 1 - 4 but this time, update the rule. \r\n\r\n### Checklist\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>","sha":"fbb232815b85961ac09b6abbe369eb7b3760752d"}},"sourceBranch":"main","suggestedTargetBranches":["8.11","8.10"],"targetPullRequestStates":[{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/171048","number":171048,"mergeCommit":{"message":"[RAM][Bug] Fix bug preventing filters from being added to conditional actions (#171048)\n\n## Summary\r\nResolves: https://github.com/elastic/kibana/issues/171036\r\n\r\nFixes a bug where the schema name for the conditional action filter\r\n`$state` was incorrectly name. This prevented the user from adding\r\nfilters to conditional actions as the schema validation would reject the\r\nrequest.\r\n\r\n### To verify the fix:\r\n\r\n1. Create a rule\r\n2. Add a conditional action\r\n3. Assert that filters can be added to the rule\r\n4. Rule is saved\r\n5. Repeat 1 - 4 but this time, update the rule. \r\n\r\n### Checklist\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>","sha":"fbb232815b85961ac09b6abbe369eb7b3760752d"}},{"branch":"8.11","label":"v8.11.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.10","label":"v8.10.5","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
This commit is contained in:
parent
94d47b38ba
commit
46e0cda150
10 changed files with 69 additions and 7 deletions
|
@ -7,6 +7,7 @@
|
|||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { ruleNotifyWhenV1 } from '../../../response';
|
||||
import { filterStateStore as filterStateStoreV1 } from '../../../response/constants/v1';
|
||||
import {
|
||||
validateNotifyWhenV1,
|
||||
validateDurationV1,
|
||||
|
@ -37,7 +38,14 @@ export const actionAlertsFilterSchema = schema.object({
|
|||
schema.object({
|
||||
query: schema.maybe(schema.recordOf(schema.string(), schema.any())),
|
||||
meta: schema.recordOf(schema.string(), schema.any()),
|
||||
state$: schema.maybe(schema.object({ store: schema.string() })),
|
||||
$state: schema.maybe(
|
||||
schema.object({
|
||||
store: schema.oneOf([
|
||||
schema.literal(filterStateStoreV1.APP_STATE),
|
||||
schema.literal(filterStateStoreV1.GLOBAL_STATE),
|
||||
]),
|
||||
})
|
||||
),
|
||||
})
|
||||
),
|
||||
dsl: schema.maybe(schema.string()),
|
||||
|
|
|
@ -43,6 +43,11 @@ export const ruleExecutionStatusWarningReason = {
|
|||
MAX_QUEUED_ACTIONS: 'maxQueuedActions',
|
||||
} as const;
|
||||
|
||||
export const filterStateStore = {
|
||||
APP_STATE: 'appState',
|
||||
GLOBAL_STATE: 'globalState',
|
||||
} as const;
|
||||
|
||||
export type RuleNotifyWhen = typeof ruleNotifyWhen[keyof typeof ruleNotifyWhen];
|
||||
export type RuleLastRunOutcomeValues =
|
||||
typeof ruleLastRunOutcomeValues[keyof typeof ruleLastRunOutcomeValues];
|
||||
|
@ -52,3 +57,4 @@ export type RuleExecutionStatusErrorReason =
|
|||
typeof ruleExecutionStatusErrorReason[keyof typeof ruleExecutionStatusErrorReason];
|
||||
export type RuleExecutionStatusWarningReason =
|
||||
typeof ruleExecutionStatusWarningReason[keyof typeof ruleExecutionStatusWarningReason];
|
||||
export type FilterStateStore = typeof filterStateStore[keyof typeof filterStateStore];
|
||||
|
|
|
@ -13,6 +13,7 @@ import {
|
|||
ruleExecutionStatusErrorReason as ruleExecutionStatusErrorReasonV1,
|
||||
ruleExecutionStatusWarningReason as ruleExecutionStatusWarningReasonV1,
|
||||
ruleLastRunOutcomeValues as ruleLastRunOutcomeValuesV1,
|
||||
filterStateStore as filterStateStoreV1,
|
||||
} from '../constants/v1';
|
||||
|
||||
export const ruleParamsSchema = schema.recordOf(schema.string(), schema.maybe(schema.any()));
|
||||
|
@ -43,7 +44,14 @@ const actionAlertsFilterSchema = schema.object({
|
|||
schema.object({
|
||||
query: schema.maybe(schema.recordOf(schema.string(), schema.any())),
|
||||
meta: schema.recordOf(schema.string(), schema.any()),
|
||||
state$: schema.maybe(schema.object({ store: schema.string() })),
|
||||
$state: schema.maybe(
|
||||
schema.object({
|
||||
store: schema.oneOf([
|
||||
schema.literal(filterStateStoreV1.APP_STATE),
|
||||
schema.literal(filterStateStoreV1.GLOBAL_STATE),
|
||||
]),
|
||||
})
|
||||
),
|
||||
})
|
||||
),
|
||||
})
|
||||
|
|
|
@ -42,3 +42,8 @@ export const ruleExecutionStatusWarningReason = {
|
|||
MAX_ALERTS: 'maxAlerts',
|
||||
MAX_QUEUED_ACTIONS: 'maxQueuedActions',
|
||||
} as const;
|
||||
|
||||
export const filterStateStore = {
|
||||
APP_STATE: 'appState',
|
||||
GLOBAL_STATE: 'globalState',
|
||||
} as const;
|
||||
|
|
|
@ -23,7 +23,7 @@ import {
|
|||
} from '../../../../rules_client/lib';
|
||||
import { generateAPIKeyName, apiKeyAsRuleDomainProperties } from '../../../../rules_client/common';
|
||||
import { ruleAuditEvent, RuleAuditAction } from '../../../../rules_client/common/audit_events';
|
||||
import { RulesClientContext } from '../../../../rules_client/types';
|
||||
import { RulesClientContext, NormalizedAlertAction } from '../../../../rules_client/types';
|
||||
import { RuleDomain, RuleParams } from '../../types';
|
||||
import { SanitizedRule } from '../../../../types';
|
||||
import {
|
||||
|
@ -55,7 +55,11 @@ export async function createRule<Params extends RuleParams = never>(
|
|||
): Promise<SanitizedRule<Params>> {
|
||||
const { data: initialData, options, allowMissingConnectorSecrets } = createParams;
|
||||
|
||||
const data = { ...initialData, actions: addGeneratedActionValues(initialData.actions) };
|
||||
// TODO (http-versioning): Remove this cast when we fix addGeneratedActionValues
|
||||
const data = {
|
||||
...initialData,
|
||||
actions: addGeneratedActionValues(initialData.actions as NormalizedAlertAction[]),
|
||||
};
|
||||
|
||||
const id = options?.id || SavedObjectsUtils.generateId();
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { notifyWhenSchema } from './notify_when_schema';
|
||||
import { filterStateStore } from '../constants';
|
||||
|
||||
export const actionParamsSchema = schema.recordOf(schema.string(), schema.maybe(schema.any()));
|
||||
|
||||
|
@ -14,7 +15,14 @@ const actionAlertsFilterQueryFiltersSchema = schema.arrayOf(
|
|||
schema.object({
|
||||
query: schema.maybe(schema.recordOf(schema.string(), schema.any())),
|
||||
meta: schema.recordOf(schema.string(), schema.any()),
|
||||
state$: schema.maybe(schema.object({ store: schema.string() })),
|
||||
$state: schema.maybe(
|
||||
schema.object({
|
||||
store: schema.oneOf([
|
||||
schema.literal(filterStateStore.APP_STATE),
|
||||
schema.literal(filterStateStore.GLOBAL_STATE),
|
||||
]),
|
||||
})
|
||||
),
|
||||
})
|
||||
);
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
ruleExecutionStatusValues,
|
||||
ruleExecutionStatusErrorReason,
|
||||
ruleExecutionStatusWarningReason,
|
||||
filterStateStore,
|
||||
} from '../constants';
|
||||
import {
|
||||
ruleParamsSchema,
|
||||
|
@ -33,6 +34,7 @@ export type RuleExecutionStatusErrorReason =
|
|||
typeof ruleExecutionStatusErrorReason[keyof typeof ruleExecutionStatusErrorReason];
|
||||
export type RuleExecutionStatusWarningReason =
|
||||
typeof ruleExecutionStatusWarningReason[keyof typeof ruleExecutionStatusWarningReason];
|
||||
export type FilterStateStore = typeof filterStateStore[keyof typeof filterStateStore];
|
||||
|
||||
export type RuleParams = TypeOf<typeof ruleParamsSchema>;
|
||||
export type RuleSnoozeSchedule = TypeOf<typeof snoozeScheduleSchema>;
|
||||
|
|
|
@ -169,7 +169,7 @@ const rawRuleAlertsFilterSchema = schema.object({
|
|||
params: schema.maybe(schema.recordOf(schema.string(), schema.any())), // better type?
|
||||
value: schema.maybe(schema.string()),
|
||||
}),
|
||||
state$: schema.maybe(
|
||||
$state: schema.maybe(
|
||||
schema.object({
|
||||
store: schema.oneOf([schema.literal('appState'), schema.literal('globalState')]),
|
||||
})
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { FilterStateStore } from '@kbn/es-query';
|
||||
import { validateTimezone } from './validate_timezone';
|
||||
import { validateDurationSchema } from '../../lib';
|
||||
import { validateHours } from './validate_hours';
|
||||
|
@ -36,7 +37,14 @@ export const actionsSchema = schema.arrayOf(
|
|||
schema.object({
|
||||
query: schema.maybe(schema.recordOf(schema.string(), schema.any())),
|
||||
meta: schema.recordOf(schema.string(), schema.any()),
|
||||
state$: schema.maybe(schema.object({ store: schema.string() })),
|
||||
$state: schema.maybe(
|
||||
schema.object({
|
||||
store: schema.oneOf([
|
||||
schema.literal(FilterStateStore.APP_STATE),
|
||||
schema.literal(FilterStateStore.GLOBAL_STATE),
|
||||
]),
|
||||
})
|
||||
),
|
||||
})
|
||||
),
|
||||
dsl: schema.maybe(schema.string()),
|
||||
|
|
|
@ -141,6 +141,19 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
|
|||
await testSubjects.click('notifyWhenSelect');
|
||||
await testSubjects.click('onThrottleInterval');
|
||||
await testSubjects.setValue('throttleInput', '10');
|
||||
|
||||
// Alerts search bar (conditional actions)
|
||||
await testSubjects.click('alertsFilterQueryToggle');
|
||||
|
||||
await pageObjects.header.waitUntilLoadingHasFinished();
|
||||
await testSubjects.click('addFilter');
|
||||
await testSubjects.click('filterFieldSuggestionList');
|
||||
await comboBox.set('filterFieldSuggestionList', '_id');
|
||||
await comboBox.set('filterOperatorList', 'is not');
|
||||
await testSubjects.setValue('filterParams', 'fake-rule-id');
|
||||
await testSubjects.click('saveFilter');
|
||||
await testSubjects.setValue('queryInput', '_id: *');
|
||||
|
||||
const messageTextArea = await find.byCssSelector('[data-test-subj="messageTextArea"]');
|
||||
expect(await messageTextArea.getAttribute('value')).to.eql(
|
||||
`Rule '{{rule.name}}' is active for group '{{context.group}}':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue