-
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.
[Logs UI] Register log threshold rule as lifecycle rule (#104341)
Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
8c9de0b
commit e9f42d2
Showing
28 changed files
with
844 additions
and
342 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
9 changes: 9 additions & 0 deletions
9
x-pack/plugins/infra/common/alerting/logs/log_threshold/index.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,9 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export * from './rule_data'; | ||
export * from './types'; |
19 changes: 19 additions & 0 deletions
19
x-pack/plugins/infra/common/alerting/logs/log_threshold/rule_data.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,19 @@ | ||
/* | ||
* 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 { jsonRt } from '@kbn/io-ts-utils/target/json_rt'; | ||
import * as rt from 'io-ts'; | ||
import { alertParamsRT as logThresholdAlertParamsRT } from './types'; | ||
|
||
export const serializedParamsKey = 'serialized_params'; | ||
|
||
export const logThresholdRuleDataNamespace = 'log_threshold_rule'; | ||
export const logThresholdRuleDataSerializedParamsKey = `${logThresholdRuleDataNamespace}.${serializedParamsKey}` as const; | ||
|
||
export const logThresholdRuleDataRT = rt.type({ | ||
[logThresholdRuleDataSerializedParamsKey]: rt.array(jsonRt.pipe(logThresholdAlertParamsRT)), | ||
}); |
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
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
87 changes: 87 additions & 0 deletions
87
x-pack/plugins/infra/public/alerting/log_threshold/rule_data_formatters.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,87 @@ | ||
/* | ||
* 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'; | ||
import { | ||
ALERT_EVALUATION_THRESHOLD, | ||
ALERT_EVALUATION_VALUE, | ||
ALERT_ID, | ||
ALERT_START, | ||
} from '@kbn/rule-data-utils'; | ||
import { modifyUrl } from '@kbn/std'; | ||
import { fold } from 'fp-ts/lib/Either'; | ||
import { pipe } from 'fp-ts/lib/function'; | ||
import { ObservabilityRuleTypeFormatter } from '../../../../observability/public'; | ||
import { | ||
ComparatorToi18nMap, | ||
logThresholdRuleDataRT, | ||
logThresholdRuleDataSerializedParamsKey, | ||
ratioAlertParamsRT, | ||
} from '../../../common/alerting/logs/log_threshold'; | ||
|
||
export const formatReason: ObservabilityRuleTypeFormatter = ({ fields }) => { | ||
const reason = pipe( | ||
logThresholdRuleDataRT.decode(fields), | ||
fold( | ||
() => | ||
i18n.translate('xpack.infra.logs.alerting.threshold.unknownReasonDescription', { | ||
defaultMessage: 'unknown reason', | ||
}), | ||
(logThresholdRuleData) => { | ||
const params = logThresholdRuleData[logThresholdRuleDataSerializedParamsKey][0]; | ||
|
||
const actualCount = fields[ALERT_EVALUATION_VALUE]; | ||
const groupName = fields[ALERT_ID]; | ||
const isGrouped = (params.groupBy?.length ?? 0) > 0; | ||
const isRatio = ratioAlertParamsRT.is(params); | ||
const thresholdCount = fields[ALERT_EVALUATION_THRESHOLD]; | ||
const translatedComparator = ComparatorToi18nMap[params.count.comparator]; | ||
|
||
if (isRatio) { | ||
return i18n.translate('xpack.infra.logs.alerting.threshold.ratioAlertReasonDescription', { | ||
defaultMessage: | ||
'{isGrouped, select, true{{groupName}: } false{}}The log entries ratio is {actualCount} ({translatedComparator} {thresholdCount}).', | ||
values: { | ||
actualCount, | ||
translatedComparator, | ||
groupName, | ||
isGrouped, | ||
thresholdCount, | ||
}, | ||
}); | ||
} else { | ||
return i18n.translate('xpack.infra.logs.alerting.threshold.countAlertReasonDescription', { | ||
defaultMessage: | ||
'{isGrouped, select, true{{groupName}: } false{}}{actualCount, plural, one {{actualCount} log entry} other {{actualCount} log entries} } ({translatedComparator} {thresholdCount}) match the configured conditions.', | ||
values: { | ||
actualCount, | ||
translatedComparator, | ||
groupName, | ||
isGrouped, | ||
thresholdCount, | ||
}, | ||
}); | ||
} | ||
} | ||
) | ||
); | ||
|
||
const alertStartDate = fields[ALERT_START]; | ||
const timestamp = alertStartDate != null ? new Date(alertStartDate).valueOf() : null; | ||
const link = modifyUrl('/app/logs/link-to/default/logs', ({ query, ...otherUrlParts }) => ({ | ||
...otherUrlParts, | ||
query: { | ||
...query, | ||
...(timestamp != null ? { time: `${timestamp}` } : {}), | ||
}, | ||
})); | ||
|
||
return { | ||
reason, | ||
link, // TODO: refactor to URL generators | ||
}; | ||
}; |
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
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.