-
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.
Browse files
Browse the repository at this point in the history
Allow selecting any service name, transaction type (where appropriate), and environment when creating and editing rules, both in APM and Stack Management. - Create /internal/apm/suggestions endpoint that uses `terms_enum` - Use combo box for environment, service name, and transaction type with suggestions endpoint on all alerts - Remove "Go to APM" callouts on new alert creation - Wrap calls to `createCallApmApi` in alert triggers with `useEffect` - Use `getEnvironmentLabel` for value in environment field expression - Make all `AlertParams` fields optional (except in latency threshold alert) - Add e2e tests for creating an alert - Remove `NewAlertEmptyPrompt` component and `isNewApmRuleFromStackManagement` helper - Replace `maxServiceEnvironments` and `maxServiceSelections` config options with `maxSuggestions` advanced setting. ![CleanShot 2021-09-28 at 10 35 58](https://user-images.githubusercontent.com/9912/135119948-e247615a-d235-4feb-b197-b803f165ad1e.gif) Fixes #106786 Co-authored-by: Nathan L Smith <[email protected]>
- Loading branch information
1 parent
d5fb5a6
commit 0a41af9
Showing
48 changed files
with
1,062 additions
and
394 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
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 was deleted.
Oops, something went wrong.
108 changes: 108 additions & 0 deletions
108
x-pack/plugins/apm/ftr_e2e/cypress/integration/power_user/rules/error_count.spec.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,108 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
describe('Rules', () => { | ||
describe('Error count', () => { | ||
const ruleName = 'Error count threshold'; | ||
const comboBoxInputSelector = | ||
'.euiPopover__panel-isOpen [data-test-subj=comboBoxSearchInput]'; | ||
const confirmModalButtonSelector = | ||
'.euiModal button[data-test-subj=confirmModalConfirmButton]'; | ||
const deleteButtonSelector = | ||
'[data-test-subj=deleteActionHoverButton]:first'; | ||
const editButtonSelector = '[data-test-subj=editActionHoverButton]:first'; | ||
|
||
describe('when created from APM', () => { | ||
describe('when created from Service Inventory', () => { | ||
before(() => { | ||
cy.loginAsPowerUser(); | ||
}); | ||
|
||
it('creates and updates a rule', () => { | ||
// Create a rule in APM | ||
cy.visit('/app/apm/services'); | ||
cy.contains('Alerts and rules').click(); | ||
cy.contains('Error count').click(); | ||
cy.contains('Create threshold rule').click(); | ||
|
||
// Change the environment to "testing" | ||
cy.contains('Environment All').click(); | ||
cy.get(comboBoxInputSelector).type('testing{enter}'); | ||
|
||
// Save, with no actions | ||
cy.contains('button:not(:disabled)', 'Save').click(); | ||
cy.get(confirmModalButtonSelector).click(); | ||
|
||
cy.contains(`Created rule "${ruleName}`); | ||
|
||
// Go to Stack Management | ||
cy.contains('Alerts and rules').click(); | ||
cy.contains('Manage rules').click(); | ||
|
||
// Edit the rule, changing the environment to "All" | ||
cy.get(editButtonSelector).click(); | ||
cy.contains('Environment testing').click(); | ||
cy.get(comboBoxInputSelector).type('All{enter}'); | ||
cy.contains('button:not(:disabled)', 'Save').click(); | ||
|
||
cy.contains(`Updated '${ruleName}'`); | ||
|
||
// Wait for the table to be ready for next edit click | ||
cy.get('.euiBasicTable').not('.euiBasicTable-loading'); | ||
|
||
// Ensure the rule now shows "All" for the environment | ||
cy.get(editButtonSelector).click(); | ||
cy.contains('Environment All'); | ||
cy.contains('button', 'Cancel').click(); | ||
|
||
// Delete the rule | ||
cy.get(deleteButtonSelector).click(); | ||
cy.get(confirmModalButtonSelector).click(); | ||
|
||
// Ensure the table is empty | ||
cy.contains('Create your first rule'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when created from Stack management', () => { | ||
before(() => { | ||
cy.loginAsPowerUser(); | ||
}); | ||
|
||
it('creates a rule', () => { | ||
// Go to stack management | ||
cy.visit('/app/management/insightsAndAlerting/triggersActions/rules'); | ||
|
||
// Create a rule | ||
cy.contains('button', 'Create rule').click(); | ||
cy.get('[name=name]').type(ruleName); | ||
cy.contains('.euiFlyout button', ruleName).click(); | ||
|
||
// Change the environment to "testing" | ||
cy.contains('Environment All').click(); | ||
cy.get(comboBoxInputSelector).type('testing{enter}'); | ||
|
||
// Save, with no actions | ||
cy.contains('button:not(:disabled)', 'Save').click(); | ||
cy.get(confirmModalButtonSelector).click(); | ||
|
||
cy.contains(`Created rule "${ruleName}`); | ||
|
||
// Wait for the table to be ready for next delete click | ||
cy.get('.euiBasicTable').not('.euiBasicTable-loading'); | ||
|
||
// Delete the rule | ||
cy.get(deleteButtonSelector).click(); | ||
cy.get(confirmModalButtonSelector).click(); | ||
|
||
// Ensure the table is empty | ||
cy.contains('Create your first rule'); | ||
}); | ||
}); | ||
}); | ||
}); |
152 changes: 152 additions & 0 deletions
152
...ublic/components/alerting/error_count_alert_trigger/error_count_alert_trigger.stories.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,152 @@ | ||
/* | ||
* 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 { Meta, Story } from '@storybook/react'; | ||
import React, { useState } from 'react'; | ||
import { AlertParams, ErrorCountAlertTrigger } from '.'; | ||
import { CoreStart } from '../../../../../../../src/core/public'; | ||
import { createKibanaReactContext } from '../../../../../../../src/plugins/kibana_react/public'; | ||
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values'; | ||
import { AlertMetadata } from '../helper'; | ||
|
||
const KibanaReactContext = createKibanaReactContext({ | ||
notifications: { toasts: { add: () => {} } }, | ||
} as unknown as Partial<CoreStart>); | ||
|
||
interface Args { | ||
alertParams: AlertParams; | ||
metadata?: AlertMetadata; | ||
} | ||
|
||
const stories: Meta<{}> = { | ||
title: 'alerting/ErrorCountAlertTrigger', | ||
component: ErrorCountAlertTrigger, | ||
decorators: [ | ||
(StoryComponent) => { | ||
return ( | ||
<KibanaReactContext.Provider> | ||
<div style={{ width: 400 }}> | ||
<StoryComponent /> | ||
</div> | ||
</KibanaReactContext.Provider> | ||
); | ||
}, | ||
], | ||
}; | ||
export default stories; | ||
|
||
export const CreatingInApmFromInventory: Story<Args> = ({ | ||
alertParams, | ||
metadata, | ||
}) => { | ||
const [params, setParams] = useState<AlertParams>(alertParams); | ||
|
||
function setAlertParams(property: string, value: any) { | ||
setParams({ ...params, [property]: value }); | ||
} | ||
|
||
return ( | ||
<ErrorCountAlertTrigger | ||
alertParams={params} | ||
metadata={metadata} | ||
setAlertParams={setAlertParams} | ||
setAlertProperty={() => {}} | ||
/> | ||
); | ||
}; | ||
CreatingInApmFromInventory.args = { | ||
alertParams: {}, | ||
metadata: { | ||
end: '2021-09-10T14:14:04.789Z', | ||
environment: ENVIRONMENT_ALL.value, | ||
serviceName: undefined, | ||
start: '2021-09-10T13:59:00.000Z', | ||
}, | ||
}; | ||
|
||
export const CreatingInApmFromService: Story<Args> = ({ | ||
alertParams, | ||
metadata, | ||
}) => { | ||
const [params, setParams] = useState<AlertParams>(alertParams); | ||
|
||
function setAlertParams(property: string, value: any) { | ||
setParams({ ...params, [property]: value }); | ||
} | ||
|
||
return ( | ||
<ErrorCountAlertTrigger | ||
alertParams={params} | ||
metadata={metadata} | ||
setAlertParams={setAlertParams} | ||
setAlertProperty={() => {}} | ||
/> | ||
); | ||
}; | ||
CreatingInApmFromService.args = { | ||
alertParams: {}, | ||
metadata: { | ||
end: '2021-09-10T14:14:04.789Z', | ||
environment: 'testEnvironment', | ||
serviceName: 'testServiceName', | ||
start: '2021-09-10T13:59:00.000Z', | ||
}, | ||
}; | ||
|
||
export const EditingInStackManagement: Story<Args> = ({ | ||
alertParams, | ||
metadata, | ||
}) => { | ||
const [params, setParams] = useState<AlertParams>(alertParams); | ||
|
||
function setAlertParams(property: string, value: any) { | ||
setParams({ ...params, [property]: value }); | ||
} | ||
|
||
return ( | ||
<ErrorCountAlertTrigger | ||
alertParams={params} | ||
metadata={metadata} | ||
setAlertParams={setAlertParams} | ||
setAlertProperty={() => {}} | ||
/> | ||
); | ||
}; | ||
EditingInStackManagement.args = { | ||
alertParams: { | ||
environment: 'testEnvironment', | ||
serviceName: 'testServiceName', | ||
threshold: 25, | ||
windowSize: 1, | ||
windowUnit: 'm', | ||
}, | ||
metadata: undefined, | ||
}; | ||
|
||
export const CreatingInStackManagement: Story<Args> = ({ | ||
alertParams, | ||
metadata, | ||
}) => { | ||
const [params, setParams] = useState<AlertParams>(alertParams); | ||
|
||
function setAlertParams(property: string, value: any) { | ||
setParams({ ...params, [property]: value }); | ||
} | ||
|
||
return ( | ||
<ErrorCountAlertTrigger | ||
alertParams={params} | ||
metadata={metadata} | ||
setAlertParams={setAlertParams} | ||
setAlertProperty={() => {}} | ||
/> | ||
); | ||
}; | ||
CreatingInStackManagement.args = { | ||
alertParams: {}, | ||
metadata: undefined, | ||
}; |
19 changes: 19 additions & 0 deletions
19
...m/public/components/alerting/error_count_alert_trigger/error_count_alert_trigger.test.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,19 @@ | ||
/* | ||
* 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 { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import * as stories from './error_count_alert_trigger.stories'; | ||
import { composeStories } from '@storybook/testing-react'; | ||
|
||
const { CreatingInApmFromService } = composeStories(stories); | ||
|
||
describe('ErrorCountAlertTrigger', () => { | ||
it('renders', () => { | ||
expect(() => render(<CreatingInApmFromService />)).not.toThrowError(); | ||
}); | ||
}); |
51 changes: 0 additions & 51 deletions
51
x-pack/plugins/apm/public/components/alerting/error_count_alert_trigger/index.stories.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.