-
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 Logs history chart to the Logs Alert Details page (#153930)
## Summary It closes #150854 by - Add optional annotations to the prereview chart - Add the Logs history chart <img width="941" alt="Screenshot 2023-03-29 at 17 09 36" src="https://user-images.githubusercontent.com/6838659/228584016-f73efef0-03e6-4777-b2df-17f13166c77b.png"> ### Checklist - [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)
- Loading branch information
Showing
6 changed files
with
416 additions
and
6 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...erting/log_threshold/components/alert_details_app_section/components/alert_annotation.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,43 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { AnnotationDomainType, LineAnnotation, Position } from '@elastic/charts'; | ||
import moment from 'moment'; | ||
import { EuiIcon } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { euiThemeVars } from '@kbn/ui-theme'; | ||
import { UI_SETTINGS } from '@kbn/data-plugin/public'; | ||
import { useKibanaContextForPlugin } from '../../../../../hooks/use_kibana'; | ||
export function AlertAnnotation({ alertStarted }: { alertStarted: number }) { | ||
const { uiSettings } = useKibanaContextForPlugin().services; | ||
|
||
return ( | ||
<LineAnnotation | ||
id="annotation_alert_started" | ||
domainType={AnnotationDomainType.XDomain} | ||
dataValues={[ | ||
{ | ||
dataValue: alertStarted, | ||
header: moment(alertStarted).format(uiSettings.get(UI_SETTINGS.DATE_FORMAT)), | ||
details: i18n.translate('xpack.infra.logs.alertDetails.chartAnnotation.alertStarted', { | ||
defaultMessage: 'Alert started', | ||
}), | ||
}, | ||
]} | ||
style={{ | ||
line: { | ||
strokeWidth: 3, | ||
stroke: euiThemeVars.euiColorDangerText, | ||
opacity: 1, | ||
}, | ||
}} | ||
marker={<EuiIcon type="warning" color="danger" />} | ||
markerPosition={Position.Top} | ||
/> | ||
); | ||
} |
164 changes: 164 additions & 0 deletions
164
...ting/log_threshold/components/alert_details_app_section/components/logs_history_chart.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,164 @@ | ||
/* | ||
* 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 moment from 'moment'; | ||
import React from 'react'; | ||
import { Rule } from '@kbn/alerting-plugin/common'; | ||
import { EuiPanel, EuiFlexGroup, EuiFlexItem, EuiTitle, EuiText, EuiSpacer } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { convertTo, TopAlert } from '@kbn/observability-plugin/public'; | ||
import { AnnotationDomainType, LineAnnotation, Position } from '@elastic/charts'; | ||
import { EuiIcon, EuiBadge } from '@elastic/eui'; | ||
import { euiThemeVars } from '@kbn/ui-theme'; | ||
import { AlertConsumers } from '@kbn/rule-data-utils'; | ||
import DateMath from '@kbn/datemath'; | ||
import { useAlertsHistory } from '../../../../../hooks/use_alerts_history'; | ||
import { type PartialCriterion } from '../../../../../../common/alerting/logs/log_threshold'; | ||
import { CriterionPreview } from '../../expression_editor/criterion_preview_chart'; | ||
import { PartialRuleParams } from '../../../../../../common/alerting/logs/log_threshold'; | ||
|
||
const LogsHistoryChart = ({ | ||
rule, | ||
alert, | ||
}: { | ||
rule: Rule<PartialRuleParams>; | ||
alert: TopAlert<Record<string, any>>; | ||
}) => { | ||
// Show the Logs History Chart ONLY if we have one criteria | ||
// So always pull the first criteria | ||
const criteria = rule.params.criteria[0]; | ||
|
||
const dateRange = { | ||
from: 'now-30d', | ||
to: 'now', | ||
}; | ||
const executionTimeRange = { | ||
gte: DateMath.parse(dateRange.from)!.valueOf(), | ||
lte: DateMath.parse(dateRange.to, { roundUp: true })!.valueOf(), | ||
}; | ||
|
||
const { alertsHistory } = useAlertsHistory({ | ||
featureIds: [AlertConsumers.LOGS], | ||
ruleId: rule.id, | ||
dateRange, | ||
}); | ||
const alertHistoryAnnotations = | ||
alertsHistory?.histogramTriggeredAlerts | ||
.filter((annotation) => annotation.doc_count > 0) | ||
.map((annotation) => { | ||
return { | ||
dataValue: annotation.key, | ||
header: String(annotation.doc_count), | ||
// Only the date(without time) is needed here, uiSettings don't provide that | ||
details: moment(annotation.key_as_string).format('yyyy-MM-DD'), | ||
}; | ||
}) || []; | ||
|
||
return ( | ||
<EuiPanel hasBorder={true} data-test-subj="logsHistoryChartAlertDetails"> | ||
<EuiFlexGroup direction="column" gutterSize="none" responsive={false}> | ||
<EuiFlexItem grow={false}> | ||
<EuiTitle size="xs"> | ||
<h2> | ||
{i18n.translate('xpack.infra.logs.alertDetails.chartHistory.chartTitle', { | ||
defaultMessage: 'Logs threshold alerts history', | ||
})} | ||
</h2> | ||
</EuiTitle> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiText size="s" color="subdued"> | ||
{i18n.translate('xpack.infra.logs.alertDetails.chartHistory.last30days', { | ||
defaultMessage: 'Last 30 days', | ||
})} | ||
</EuiText> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
<EuiSpacer size="s" /> | ||
<EuiFlexGroup gutterSize="l"> | ||
<EuiFlexItem grow={false}> | ||
<EuiFlexGroup gutterSize="xs" direction="column"> | ||
<EuiFlexItem grow={false}> | ||
<EuiText color="danger"> | ||
<EuiTitle size="s"> | ||
<h3>{alertsHistory?.totalTriggeredAlerts || '-'}</h3> | ||
</EuiTitle> | ||
</EuiText> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiText size="s" color="subdued"> | ||
{i18n.translate('xpack.infra.logs.alertDetails.chartHistory.alertsTriggered', { | ||
defaultMessage: 'Alerts triggered', | ||
})} | ||
</EuiText> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiFlexItem> | ||
<EuiFlexGroup gutterSize="xs" direction="column"> | ||
<EuiFlexItem grow={false}> | ||
<EuiText> | ||
<EuiTitle size="s"> | ||
<h3> | ||
{alertsHistory?.avgTimeToRecoverUS | ||
? convertTo({ | ||
unit: 'minutes', | ||
microseconds: alertsHistory?.avgTimeToRecoverUS, | ||
extended: true, | ||
}).formatted | ||
: '-'} | ||
</h3> | ||
</EuiTitle> | ||
</EuiText> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiText size="s" color="subdued"> | ||
{i18n.translate('xpack.infra.logs.alertDetails.chartHistory.avgTimeToRecover', { | ||
defaultMessage: 'Avg time to recover', | ||
})} | ||
</EuiText> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiFlexGroup> | ||
<EuiSpacer size="s" /> | ||
<CriterionPreview | ||
annotations={[ | ||
<LineAnnotation | ||
id="annotations" | ||
key={'annotationsAlertHistory'} | ||
domainType={AnnotationDomainType.XDomain} | ||
dataValues={alertHistoryAnnotations} | ||
style={{ | ||
line: { | ||
strokeWidth: 3, | ||
stroke: euiThemeVars.euiColorDangerText, | ||
opacity: 1, | ||
}, | ||
}} | ||
marker={<EuiIcon type="warning" color="danger" />} | ||
markerBody={(annotationData) => ( | ||
<> | ||
<EuiBadge color="danger"> | ||
<EuiText size="xs" color="white"> | ||
{annotationData.header} | ||
</EuiText> | ||
</EuiBadge> | ||
<EuiSpacer size="xs" /> | ||
</> | ||
)} | ||
markerPosition={Position.Top} | ||
/>, | ||
]} | ||
ruleParams={rule.params} | ||
logViewReference={rule.params.logView} | ||
chartCriterion={criteria as PartialCriterion} | ||
showThreshold={true} | ||
executionTimeRange={executionTimeRange} | ||
/> | ||
</EuiPanel> | ||
); | ||
}; | ||
// eslint-disable-next-line import/no-default-export | ||
export default LogsHistoryChart; |
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.