-
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.
[SLO] Allow users to define burn rate windows using budget consumed (#…
…170996) ## Summary This PR fixes #170854 and #170859 by allowing the user to define the burn rate windows using either a burn rate threshold or the % of budget consumed by the time the alert triggers. This PR also adds the budget consumed to the help text below the burn rate window definition. I also changed the behavior to hide the window definitions until the Selected SLO is chosen since we need the SLO for the calculations. https://github.com/elastic/kibana/assets/41702/26f795f3-47cb-45c6-8ba3-528c2d9c4094
- Loading branch information
1 parent
b704db8
commit 7923a96
Showing
9 changed files
with
199 additions
and
60 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
x-pack/plugins/observability/public/components/burn_rate_rule_editor/budget_consumed.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,69 @@ | ||
/* | ||
* 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 { EuiFieldNumber, EuiFormRow, EuiIconTip } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import React, { ChangeEvent, useState } from 'react'; | ||
import numeral from '@elastic/numeral'; | ||
|
||
interface Props { | ||
initialBurnRate?: number; | ||
errors?: string[]; | ||
onChange: (burnRate: number) => void; | ||
longLookbackWindowInHours: number; | ||
sloTimeWindowInHours: number; | ||
} | ||
|
||
export function BudgetConsumed({ | ||
onChange, | ||
initialBurnRate = 1, | ||
longLookbackWindowInHours, | ||
sloTimeWindowInHours, | ||
errors, | ||
}: Props) { | ||
const [budgetConsumed, setBudgetConsumed] = useState<number>( | ||
((initialBurnRate * longLookbackWindowInHours) / sloTimeWindowInHours) * 100 | ||
); | ||
const hasError = errors !== undefined && errors.length > 0; | ||
|
||
const onBudgetConsumedChanged = (event: ChangeEvent<HTMLInputElement>) => { | ||
const value = Number(event.target.value); | ||
setBudgetConsumed(value); | ||
const burnRate = sloTimeWindowInHours * (value / 100 / longLookbackWindowInHours); | ||
onChange(burnRate); | ||
}; | ||
|
||
return ( | ||
<EuiFormRow | ||
label={ | ||
<> | ||
{i18n.translate('xpack.observability.slo.rules.budgetConsumed.rowLabel', { | ||
defaultMessage: '% Budget consumed', | ||
})}{' '} | ||
<EuiIconTip | ||
position="top" | ||
content={i18n.translate('xpack.observability.slo.rules.budgetConsumed.tooltip', { | ||
defaultMessage: 'How much budget is consumed before the first alert is fired.', | ||
})} | ||
/> | ||
</> | ||
} | ||
fullWidth | ||
isInvalid={hasError} | ||
> | ||
<EuiFieldNumber | ||
fullWidth | ||
step={0.01} | ||
min={0.01} | ||
max={100} | ||
value={numeral(budgetConsumed).format('0[.0]')} | ||
onChange={(event) => onBudgetConsumedChanged(event)} | ||
data-test-subj="budgetConsumed" | ||
/> | ||
</EuiFormRow> | ||
); | ||
} |
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.