-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RAM] Improve rule interval circuit breaker error message (#168173)
## Summary Improve rule interval circuit breaker error message to the following endpoints: - create - update - bulk edit - bulk enable ### Bulk modification ![Screenshot from 2023-10-06 10-11-24](https://github.com/elastic/kibana/assets/74562234/11271221-4d92-41a4-9c0a-f2f8972c452e) ### Modifying a single rule ![Screenshot from 2023-10-06 10-12-16](https://github.com/elastic/kibana/assets/74562234/4ad5f482-6b68-4eef-8989-3f0013c218b2) ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Xavier Mouligneau <[email protected]>
- Loading branch information
1 parent
e76e589
commit c66a86b
Showing
27 changed files
with
536 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
x-pack/plugins/alerting/common/rule_circuit_breaker_error_message.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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 { | ||
getRuleCircuitBreakerErrorMessage, | ||
parseRuleCircuitBreakerErrorMessage, | ||
} from './rule_circuit_breaker_error_message'; | ||
|
||
describe('getRuleCircuitBreakerErrorMessage', () => { | ||
it('should return the correct message', () => { | ||
expect( | ||
getRuleCircuitBreakerErrorMessage({ | ||
name: 'test rule', | ||
action: 'create', | ||
interval: 5, | ||
intervalAvailable: 4, | ||
}) | ||
).toMatchInlineSnapshot( | ||
`"Error validating circuit breaker - Rule 'test rule' cannot be created. The maximum number of runs per minute would be exceeded. - The rule has 5 runs per minute; there are only 4 runs per minute available. Before you can modify this rule, you must increase its check interval so that it runs less frequently. Alternatively, disable other rules or change their check intervals."` | ||
); | ||
|
||
expect( | ||
getRuleCircuitBreakerErrorMessage({ | ||
name: 'test rule', | ||
action: 'update', | ||
interval: 1, | ||
intervalAvailable: 1, | ||
}) | ||
).toMatchInlineSnapshot( | ||
`"Error validating circuit breaker - Rule 'test rule' cannot be updated. The maximum number of runs per minute would be exceeded. - The rule has 1 run per minute; there is only 1 run per minute available. Before you can modify this rule, you must increase its check interval so that it runs less frequently. Alternatively, disable other rules or change their check intervals."` | ||
); | ||
|
||
expect( | ||
getRuleCircuitBreakerErrorMessage({ | ||
name: 'test rule', | ||
action: 'bulkEdit', | ||
interval: 1, | ||
intervalAvailable: 1, | ||
rules: 5, | ||
}) | ||
).toMatchInlineSnapshot( | ||
`"Error validating circuit breaker - Rules cannot be bulk edited. The maximum number of runs per minute would be exceeded. - The rules have 1 run per minute; there is only 1 run per minute available. Before you can modify these rules, you must disable other rules or change their check intervals so they run less frequently."` | ||
); | ||
}); | ||
|
||
it('should parse the error message', () => { | ||
const message = getRuleCircuitBreakerErrorMessage({ | ||
name: 'test rule', | ||
action: 'create', | ||
interval: 5, | ||
intervalAvailable: 4, | ||
}); | ||
|
||
const parsedMessage = parseRuleCircuitBreakerErrorMessage(message); | ||
|
||
expect(parsedMessage.summary).toContain("Rule 'test rule' cannot be created"); | ||
expect(parsedMessage.details).toContain('The rule has 5 runs per minute'); | ||
}); | ||
|
||
it('should passthrough the message if it is not related to circuit breakers', () => { | ||
const parsedMessage = parseRuleCircuitBreakerErrorMessage('random message'); | ||
|
||
expect(parsedMessage.summary).toEqual('random message'); | ||
expect(parsedMessage.details).toBeUndefined(); | ||
}); | ||
}); |
136 changes: 136 additions & 0 deletions
136
x-pack/plugins/alerting/common/rule_circuit_breaker_error_message.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
|
||
const errorMessageHeader = 'Error validating circuit breaker'; | ||
|
||
const getCreateRuleErrorSummary = (name: string) => { | ||
return i18n.translate('xpack.alerting.ruleCircuitBreaker.error.createSummary', { | ||
defaultMessage: `Rule '{name}' cannot be created. The maximum number of runs per minute would be exceeded.`, | ||
values: { | ||
name, | ||
}, | ||
}); | ||
}; | ||
|
||
const getUpdateRuleErrorSummary = (name: string) => { | ||
return i18n.translate('xpack.alerting.ruleCircuitBreaker.error.updateSummary', { | ||
defaultMessage: `Rule '{name}' cannot be updated. The maximum number of runs per minute would be exceeded.`, | ||
values: { | ||
name, | ||
}, | ||
}); | ||
}; | ||
|
||
const getEnableRuleErrorSummary = (name: string) => { | ||
return i18n.translate('xpack.alerting.ruleCircuitBreaker.error.enableSummary', { | ||
defaultMessage: `Rule '{name}' cannot be enabled. The maximum number of runs per minute would be exceeded.`, | ||
values: { | ||
name, | ||
}, | ||
}); | ||
}; | ||
|
||
const getBulkEditRuleErrorSummary = () => { | ||
return i18n.translate('xpack.alerting.ruleCircuitBreaker.error.bulkEditSummary', { | ||
defaultMessage: `Rules cannot be bulk edited. The maximum number of runs per minute would be exceeded.`, | ||
}); | ||
}; | ||
|
||
const getBulkEnableRuleErrorSummary = () => { | ||
return i18n.translate('xpack.alerting.ruleCircuitBreaker.error.bulkEnableSummary', { | ||
defaultMessage: `Rules cannot be bulk enabled. The maximum number of runs per minute would be exceeded.`, | ||
}); | ||
}; | ||
|
||
const getRuleCircuitBreakerErrorDetail = ({ | ||
interval, | ||
intervalAvailable, | ||
rules, | ||
}: { | ||
interval: number; | ||
intervalAvailable: number; | ||
rules: number; | ||
}) => { | ||
if (rules === 1) { | ||
return i18n.translate('xpack.alerting.ruleCircuitBreaker.error.ruleDetail', { | ||
defaultMessage: `The rule has {interval, plural, one {{interval} run} other {{interval} runs}} per minute; there {intervalAvailable, plural, one {is only {intervalAvailable} run} other {are only {intervalAvailable} runs}} per minute available. Before you can modify this rule, you must increase its check interval so that it runs less frequently. Alternatively, disable other rules or change their check intervals.`, | ||
values: { | ||
interval, | ||
intervalAvailable, | ||
}, | ||
}); | ||
} | ||
return i18n.translate('xpack.alerting.ruleCircuitBreaker.error.multipleRuleDetail', { | ||
defaultMessage: `The rules have {interval, plural, one {{interval} run} other {{interval} runs}} per minute; there {intervalAvailable, plural, one {is only {intervalAvailable} run} other {are only {intervalAvailable} runs}} per minute available. Before you can modify these rules, you must disable other rules or change their check intervals so they run less frequently.`, | ||
values: { | ||
interval, | ||
intervalAvailable, | ||
}, | ||
}); | ||
}; | ||
|
||
export const getRuleCircuitBreakerErrorMessage = ({ | ||
name = '', | ||
interval, | ||
intervalAvailable, | ||
action, | ||
rules = 1, | ||
}: { | ||
name?: string; | ||
interval: number; | ||
intervalAvailable: number; | ||
action: 'update' | 'create' | 'enable' | 'bulkEdit' | 'bulkEnable'; | ||
rules?: number; | ||
}) => { | ||
let errorMessageSummary: string; | ||
|
||
switch (action) { | ||
case 'update': | ||
errorMessageSummary = getUpdateRuleErrorSummary(name); | ||
break; | ||
case 'create': | ||
errorMessageSummary = getCreateRuleErrorSummary(name); | ||
break; | ||
case 'enable': | ||
errorMessageSummary = getEnableRuleErrorSummary(name); | ||
break; | ||
case 'bulkEdit': | ||
errorMessageSummary = getBulkEditRuleErrorSummary(); | ||
break; | ||
case 'bulkEnable': | ||
errorMessageSummary = getBulkEnableRuleErrorSummary(); | ||
break; | ||
} | ||
|
||
return `Error validating circuit breaker - ${errorMessageSummary} - ${getRuleCircuitBreakerErrorDetail( | ||
{ | ||
interval, | ||
intervalAvailable, | ||
rules, | ||
} | ||
)}`; | ||
}; | ||
|
||
export const parseRuleCircuitBreakerErrorMessage = ( | ||
message: string | ||
): { | ||
summary: string; | ||
details?: string; | ||
} => { | ||
if (!message.includes(errorMessageHeader)) { | ||
return { | ||
summary: message, | ||
}; | ||
} | ||
const segments = message.split(' - '); | ||
return { | ||
summary: segments[1], | ||
details: segments[2], | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.