forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SLO] Enable burn rate alert by default during creation via UI (elast…
…ic#176317) ## Summary This PR changes the SLO creation behavior via the UI. Instead of having a checkbox to create the Burn Rate rule, with this PR, the Burn Rate Rule will be created by default. The Burn Rate rule is only created by default when using the UI, the create SLO API does not create a rule by default.
- Loading branch information
1 parent
83c11b5
commit 643d3bc
Showing
9 changed files
with
154 additions
and
194 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
64 changes: 64 additions & 0 deletions
64
x-pack/plugins/observability/public/hooks/use_create_rule.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,64 @@ | ||
/* | ||
* 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 { useMutation } from '@tanstack/react-query'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { BASE_ALERTING_API_PATH, RuleTypeParams } from '@kbn/alerting-plugin/common'; | ||
import { v4 } from 'uuid'; | ||
import { | ||
CreateRuleRequestBody, | ||
CreateRuleResponse, | ||
} from '@kbn/alerting-plugin/common/routes/rule/apis/create'; | ||
import { useKibana } from '../utils/kibana_react'; | ||
|
||
export function useCreateRule<Params extends RuleTypeParams = never>() { | ||
const { | ||
http, | ||
notifications: { toasts }, | ||
} = useKibana().services; | ||
|
||
const createRule = useMutation< | ||
CreateRuleResponse<Params>, | ||
Error, | ||
{ rule: CreateRuleRequestBody<Params> } | ||
>( | ||
['createRule'], | ||
({ rule }) => { | ||
try { | ||
const ruleId = v4(); | ||
const body = JSON.stringify(rule); | ||
return http.post(`${BASE_ALERTING_API_PATH}/rule/${ruleId}`, { | ||
body, | ||
}); | ||
} catch (e) { | ||
throw new Error(`Unable to create rule: ${e}`); | ||
} | ||
}, | ||
{ | ||
onError: (_err) => { | ||
toasts.addDanger( | ||
i18n.translate('xpack.observability.rules.createRule.errorNotification.descriptionText', { | ||
defaultMessage: 'Failed to create rule', | ||
}) | ||
); | ||
}, | ||
|
||
onSuccess: () => { | ||
toasts.addSuccess( | ||
i18n.translate( | ||
'xpack.observability.rules.createRule.successNotification.descriptionText', | ||
{ | ||
defaultMessage: 'Rule created', | ||
} | ||
) | ||
); | ||
}, | ||
} | ||
); | ||
|
||
return createRule; | ||
} |
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.