-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[APM] Alerting: Add global option to create all alert types #78151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cauemarcondes
merged 7 commits into
elastic:master
from
cauemarcondes:apm-alerts-service
Sep 28, 2020
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
94f9730
adding alert to service page
cauemarcondes 4d1b3d3
Merge branch 'master' into apm-alerts-service
elasticmachine bebf673
sending on alert per service environment and transaction type
cauemarcondes bf09733
Merge branch 'master' into apm-alerts-service
elasticmachine 0f12597
addressing PR comment
cauemarcondes 2283497
Merge branch 'apm-alerts-service' of github.com:cauemarcondes/kibana …
cauemarcondes dcf8e85
addressing PR comment
cauemarcondes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
50 changes: 50 additions & 0 deletions
50
x-pack/plugins/apm/public/components/alerting/fields.test.tsx
This file contains hidden or 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,50 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
| import React from 'react'; | ||
| import { ServiceField, TransactionTypeField } from './fields'; | ||
| import { render } from '@testing-library/react'; | ||
| import { expectTextsInDocument } from '../../utils/testHelpers'; | ||
|
|
||
| describe('alerting fields', () => { | ||
| describe('Service Fiels', () => { | ||
| it('renders with value', () => { | ||
| const component = render(<ServiceField value="foo" />); | ||
| expectTextsInDocument(component, ['foo']); | ||
| }); | ||
| it('renders with All when value is not defined', () => { | ||
| const component = render(<ServiceField />); | ||
| expectTextsInDocument(component, ['All']); | ||
| }); | ||
| }); | ||
cauemarcondes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| describe('Transaction Type Field', () => { | ||
| it('renders select field when multiple options available', () => { | ||
| const options = [ | ||
| { text: 'Foo', value: 'foo' }, | ||
| { text: 'Bar', value: 'bar' }, | ||
| ]; | ||
| const component = render( | ||
| <TransactionTypeField currentValue="Foo" options={options} /> | ||
| ); | ||
| expectTextsInDocument(component, ['Foo']); | ||
| }); | ||
cauemarcondes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| it('renders read-only field when single option available', () => { | ||
| const options = [{ text: 'Bar', value: 'bar' }]; | ||
| const component = render( | ||
| <TransactionTypeField currentValue="Bar" options={options} /> | ||
| ); | ||
| expectTextsInDocument(component, ['Bar']); | ||
| }); | ||
| it('renders read-only All option when no option available', () => { | ||
| const component = render(<TransactionTypeField currentValue="" />); | ||
| expectTextsInDocument(component, ['All']); | ||
| }); | ||
|
|
||
| it('renders current value when available', () => { | ||
| const component = render(<TransactionTypeField currentValue="foo" />); | ||
| expectTextsInDocument(component, ['foo']); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or 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
186 changes: 186 additions & 0 deletions
186
x-pack/plugins/apm/public/components/app/Home/AlertIntegrations/index.tsx
This file contains hidden or 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,186 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { | ||
| EuiButtonEmpty, | ||
| EuiContextMenu, | ||
| EuiContextMenuPanelDescriptor, | ||
| EuiPopover, | ||
| } from '@elastic/eui'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import React, { useState } from 'react'; | ||
| import { AlertType } from '../../../../../common/alert_types'; | ||
| import { useApmPluginContext } from '../../../../hooks/useApmPluginContext'; | ||
| import { AlertingFlyout } from '../../../alerting/AlertingFlyout'; | ||
|
|
||
| const alertLabel = i18n.translate('xpack.apm.home.alertsMenu.alerts', { | ||
| defaultMessage: 'Alerts', | ||
| }); | ||
| const transactionDurationLabel = i18n.translate( | ||
| 'xpack.apm.home.alertsMenu.transactionDuration', | ||
| { defaultMessage: 'Transaction duration' } | ||
| ); | ||
| const transactionErrorRateLabel = i18n.translate( | ||
| 'xpack.apm.home.alertsMenu.transactionErrorRate', | ||
| { defaultMessage: 'Transaction error rate' } | ||
| ); | ||
| const errorCountLabel = i18n.translate('xpack.apm.home.alertsMenu.errorCount', { | ||
| defaultMessage: 'Error count', | ||
| }); | ||
| const createThresholdAlertLabel = i18n.translate( | ||
| 'xpack.apm.home.alertsMenu.createThresholdAlert', | ||
| { defaultMessage: 'Create threshold alert' } | ||
| ); | ||
| const createAnomalyAlertAlertLabel = i18n.translate( | ||
| 'xpack.apm.home.alertsMenu.createAnomalyAlert', | ||
| { defaultMessage: 'Create anomaly alert' } | ||
| ); | ||
|
|
||
| const CREATE_TRANSACTION_DURATION_ALERT_PANEL_ID = | ||
| 'create_transaction_duration_panel'; | ||
| const CREATE_TRANSACTION_ERROR_RATE_ALERT_PANEL_ID = | ||
| 'create_transaction_error_rate_panel'; | ||
| const CREATE_ERROR_COUNT_ALERT_PANEL_ID = 'create_error_count_panel'; | ||
|
|
||
| interface Props { | ||
| canReadAlerts: boolean; | ||
| canSaveAlerts: boolean; | ||
| canReadAnomalies: boolean; | ||
| } | ||
|
|
||
| export function AlertIntegrations(props: Props) { | ||
| const { canSaveAlerts, canReadAlerts, canReadAnomalies } = props; | ||
|
|
||
| const plugin = useApmPluginContext(); | ||
|
|
||
| const [popoverOpen, setPopoverOpen] = useState(false); | ||
|
|
||
| const [alertType, setAlertType] = useState<AlertType | null>(null); | ||
|
|
||
| const button = ( | ||
| <EuiButtonEmpty | ||
| iconType="arrowDown" | ||
| iconSide="right" | ||
| onClick={() => setPopoverOpen(true)} | ||
| > | ||
| {alertLabel} | ||
| </EuiButtonEmpty> | ||
| ); | ||
|
|
||
| const panels: EuiContextMenuPanelDescriptor[] = [ | ||
| { | ||
| id: 0, | ||
| title: alertLabel, | ||
| items: [ | ||
| ...(canSaveAlerts | ||
| ? [ | ||
| { | ||
| name: transactionDurationLabel, | ||
| panel: CREATE_TRANSACTION_DURATION_ALERT_PANEL_ID, | ||
| }, | ||
| { | ||
| name: transactionErrorRateLabel, | ||
| panel: CREATE_TRANSACTION_ERROR_RATE_ALERT_PANEL_ID, | ||
| }, | ||
| { | ||
| name: errorCountLabel, | ||
| panel: CREATE_ERROR_COUNT_ALERT_PANEL_ID, | ||
| }, | ||
| ] | ||
| : []), | ||
| ...(canReadAlerts | ||
| ? [ | ||
| { | ||
| name: i18n.translate( | ||
| 'xpack.apm.home.alertsMenu.viewActiveAlerts', | ||
| { defaultMessage: 'View active alerts' } | ||
| ), | ||
| href: plugin.core.http.basePath.prepend( | ||
| '/app/management/insightsAndAlerting/triggersActions/alerts' | ||
| ), | ||
| icon: 'tableOfContents', | ||
| }, | ||
| ] | ||
| : []), | ||
| ], | ||
| }, | ||
|
|
||
| // transaction duration panel | ||
| { | ||
| id: CREATE_TRANSACTION_DURATION_ALERT_PANEL_ID, | ||
| title: transactionDurationLabel, | ||
| items: [ | ||
| // anomaly alerts | ||
| ...(canReadAnomalies | ||
| ? [ | ||
| { | ||
| name: createAnomalyAlertAlertLabel, | ||
| onClick: () => { | ||
| setAlertType(AlertType.TransactionDurationAnomaly); | ||
| setPopoverOpen(false); | ||
| }, | ||
| }, | ||
| ] | ||
| : []), | ||
| ], | ||
| }, | ||
|
|
||
| // transaction error rate panel | ||
| { | ||
| id: CREATE_TRANSACTION_ERROR_RATE_ALERT_PANEL_ID, | ||
| title: transactionErrorRateLabel, | ||
| items: [ | ||
| // threshold alerts | ||
| { | ||
| name: createThresholdAlertLabel, | ||
| onClick: () => { | ||
| setAlertType(AlertType.TransactionErrorRate); | ||
| setPopoverOpen(false); | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
|
|
||
| // error alerts panel | ||
| { | ||
| id: CREATE_ERROR_COUNT_ALERT_PANEL_ID, | ||
| title: errorCountLabel, | ||
| items: [ | ||
| { | ||
| name: createThresholdAlertLabel, | ||
| onClick: () => { | ||
| setAlertType(AlertType.ErrorCount); | ||
| setPopoverOpen(false); | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| ]; | ||
|
|
||
| return ( | ||
| <> | ||
| <EuiPopover | ||
| id="integrations-menu" | ||
| button={button} | ||
| isOpen={popoverOpen} | ||
| closePopover={() => setPopoverOpen(false)} | ||
| panelPaddingSize="none" | ||
| anchorPosition="downRight" | ||
| > | ||
| <EuiContextMenu initialPanelId={0} panels={panels} /> | ||
| </EuiPopover> | ||
| <AlertingFlyout | ||
| alertType={alertType} | ||
| addFlyoutVisible={!!alertType} | ||
| setAddFlyoutVisibility={(visible) => { | ||
| if (!visible) { | ||
| setAlertType(null); | ||
| } | ||
| }} | ||
| /> | ||
| </> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.