-
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.
[AO] - Add scaffolding and the main chart to the Logs threshold Alert…
… Details page (#153081) ## Summary ### This is a kickoff PR; more PRs will follow up. It closes #152738 <img width="1191" alt="Screenshot 2023-03-23 at 13 10 09" src="https://user-images.githubusercontent.com/6838659/227239913-4516cf44-92f6-454c-a7af-72dafb12cfb6.png"> ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [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
- Loading branch information
Showing
12 changed files
with
147 additions
and
27 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
57 changes: 57 additions & 0 deletions
57
...lugins/infra/public/alerting/log_threshold/components/alert_details_app_section/index.tsx
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,57 @@ | ||
/* | ||
* 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 { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; | ||
import { ALERT_DURATION, ALERT_END } from '@kbn/rule-data-utils'; | ||
import moment from 'moment'; | ||
import React from 'react'; | ||
import { type PartialCriterion } from '../../../../../common/alerting/logs/log_threshold'; | ||
import { CriterionPreview } from '../expression_editor/criterion_preview_chart'; | ||
import { AlertDetailsAppSectionProps } from './types'; | ||
|
||
const AlertDetailsAppSection = ({ rule, alert }: AlertDetailsAppSectionProps) => { | ||
const ruleWindowSizeMS = moment | ||
.duration(rule.params.timeSize, rule.params.timeUnit) | ||
.asMilliseconds(); | ||
const alertDurationMS = alert.fields[ALERT_DURATION]! / 1000; | ||
const TWENTY_TIMES_RULE_WINDOW_MS = 20 * ruleWindowSizeMS; | ||
/** | ||
* This is part or the requirements (RFC). | ||
* If the alert is less than 20 units of `FOR THE LAST <x> <units>` then we should draw a time range of 20 units. | ||
* IE. The user set "FOR THE LAST 5 minutes" at a minimum we should show 100 minutes. | ||
*/ | ||
const rangeFrom = | ||
alertDurationMS < TWENTY_TIMES_RULE_WINDOW_MS | ||
? Number(moment(alert.start).subtract(TWENTY_TIMES_RULE_WINDOW_MS, 'millisecond').format('x')) | ||
: Number(moment(alert.start).subtract(ruleWindowSizeMS, 'millisecond').format('x')); | ||
|
||
const rangeTo = alert.active | ||
? Date.now() | ||
: Number(moment(alert.fields[ALERT_END]).add(ruleWindowSizeMS, 'millisecond').format('x')); | ||
|
||
return ( | ||
// Create a chart per-criteria | ||
<EuiFlexGroup> | ||
{rule.params.criteria.map((criteria) => { | ||
const chartCriterion = criteria as PartialCriterion; | ||
return ( | ||
<EuiFlexItem> | ||
<CriterionPreview | ||
key={chartCriterion.field} | ||
ruleParams={rule.params} | ||
sourceId={rule.params.logView.logViewId} | ||
chartCriterion={chartCriterion} | ||
showThreshold={true} | ||
executionTimeRange={{ gte: rangeFrom, lte: rangeTo }} | ||
/> | ||
</EuiFlexItem> | ||
); | ||
})} | ||
</EuiFlexGroup> | ||
); | ||
}; | ||
// eslint-disable-next-line import/no-default-export | ||
export default AlertDetailsAppSection; |
15 changes: 15 additions & 0 deletions
15
...plugins/infra/public/alerting/log_threshold/components/alert_details_app_section/types.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,15 @@ | ||
/* | ||
* 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 { Rule } from '@kbn/alerting-plugin/common'; | ||
import { TopAlert } from '@kbn/observability-plugin/public'; | ||
import { PartialRuleParams } from '../../../../../common/alerting/logs/log_threshold'; | ||
|
||
export interface AlertDetailsAppSectionProps { | ||
rule: Rule<PartialRuleParams>; | ||
alert: TopAlert; | ||
} |
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
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.