[8.x] [ML][Rules] Fixes deletion in Check interval input for anomaly detection rule (#193420) (#193731)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ML][Rules] Fixes deletion in Check interval input for anomaly
detection rule (#193420)](https://github.com/elastic/kibana/pull/193420)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Robert
Jaszczurek","email":"92210485+rbrtj@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-09-23T14:27:01Z","message":"[ML][Rules]
Fixes deletion in Check interval input for anomaly detection rule
(#193420)\n\n## Summary\r\n\r\nIt was trying to parse `null`
values.\r\nAfter:\r\n\r\n![image](https://github.com/user-attachments/assets/82d24663-a895-4ad4-bc01-fb76b883bc66)\r\n\r\nFixes
[#190732](https://github.com/elastic/kibana/issues/190732)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"65b7bf9586480b522393905ff21324f473ee90ed","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","v9.0.0","Team:ML","backport:prev-major"],"title":"[ML][Rules]
Fixes deletion in Check interval input for anomaly detection
rule","number":193420,"url":"https://github.com/elastic/kibana/pull/193420","mergeCommit":{"message":"[ML][Rules]
Fixes deletion in Check interval input for anomaly detection rule
(#193420)\n\n## Summary\r\n\r\nIt was trying to parse `null`
values.\r\nAfter:\r\n\r\n![image](https://github.com/user-attachments/assets/82d24663-a895-4ad4-bc01-fb76b883bc66)\r\n\r\nFixes
[#190732](https://github.com/elastic/kibana/issues/190732)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"65b7bf9586480b522393905ff21324f473ee90ed"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/193420","number":193420,"mergeCommit":{"message":"[ML][Rules]
Fixes deletion in Check interval input for anomaly detection rule
(#193420)\n\n## Summary\r\n\r\nIt was trying to parse `null`
values.\r\nAfter:\r\n\r\n![image](https://github.com/user-attachments/assets/82d24663-a895-4ad4-bc01-fb76b883bc66)\r\n\r\nFixes
[#190732](https://github.com/elastic/kibana/issues/190732)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"65b7bf9586480b522393905ff21324f473ee90ed"}}]}]
BACKPORT-->

Co-authored-by: Robert Jaszczurek <92210485+rbrtj@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2024-09-24 02:21:32 +10:00 committed by GitHub
parent 1143a10f14
commit 49051eae6d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -32,13 +32,15 @@ export const ConfigValidator: FC<ConfigValidatorProps> = React.memo(
({ jobConfigs = [], alertInterval, alertParams, alertNotifyWhen, maxNumberOfBuckets }) => {
if (jobConfigs.length === 0) return null;
const alertIntervalInSeconds = parseInterval(alertInterval)!.asSeconds();
const alertIntervalInSeconds = parseInterval(alertInterval)?.asSeconds();
const lookbackIntervalInSeconds =
!!alertParams.lookbackInterval && parseInterval(alertParams.lookbackInterval)?.asSeconds();
const isAlertIntervalTooHigh =
lookbackIntervalInSeconds && lookbackIntervalInSeconds < alertIntervalInSeconds;
lookbackIntervalInSeconds &&
alertIntervalInSeconds &&
lookbackIntervalInSeconds < alertIntervalInSeconds;
const jobWithoutStartedDatafeed = jobConfigs
.filter((job) => job.datafeed_config.state !== DATAFEED_STATE.STARTED)
@ -49,6 +51,7 @@ export const ConfigValidator: FC<ConfigValidatorProps> = React.memo(
const notifyWhenWarning =
alertNotifyWhen === 'onActiveAlert' &&
lookbackIntervalInSeconds &&
alertIntervalInSeconds &&
alertIntervalInSeconds < lookbackIntervalInSeconds;
const bucketSpanDuration = parseInterval(jobConfigs[0].analysis_config.bucket_span!);