-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Metrics UI] Prefill alerts from the global dropdown #68967
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
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
56dfd18
Add metric threshold global prefill
Zacqary ef863c6
Add inventory alert prefill
Zacqary 016442c
Fix jest
Zacqary 95081c0
Merge remote-tracking branch 'upstream/master' into 60659-alert-prefill
Zacqary 983b8f6
Merge remote-tracking branch 'upstream/master' into 60659-alert-prefill
Zacqary 3dc2522
Merge branch 'master' into 60659-alert-prefill
elasticmachine 2d78353
Add metric prefill test to useMetricExplorerOptions
Zacqary f0394e8
Switch thres metric options test to jest.mock; add waffle filter test
Zacqary 9148b35
Merge branch '60659-alert-prefill' of github.com:Zacqary/kibana into …
Zacqary e24405f
Merge remote-tracking branch 'upstream/master' into 60659-alert-prefill
Zacqary 5f00cc1
Add waffle options test
Zacqary bdf9b90
Commit missing files
Zacqary dd4eab4
Expression component test WIP
Zacqary d6200a1
Merge branch 'master' into 60659-alert-prefill
elasticmachine 8809d7c
Add Expression enzyme test for prefill
Zacqary 550e476
Fix typecheck
Zacqary e5f7318
Fix bad merge
Zacqary e730aa9
Fix bad merge and metrics explorer infinite loop
Zacqary 86b915f
Merge remote-tracking branch 'upstream/master' into 60659-alert-prefill
Zacqary 5c80011
Fix bad merge
Zacqary 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
24 changes: 24 additions & 0 deletions
24
x-pack/plugins/infra/public/alerting/inventory/hooks/use_inventory_alert_prefill.ts
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,24 @@ | ||
| /* | ||
| * 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 { useState } from 'react'; | ||
| import { SnapshotMetricInput } from '../../../../common/http_api/snapshot_api'; | ||
| import { InventoryItemType } from '../../../../common/inventory_models/types'; | ||
|
|
||
| export const useInventoryAlertPrefill = () => { | ||
| const [nodeType, setNodeType] = useState<InventoryItemType>('host'); | ||
| const [filterQuery, setFilterQuery] = useState<string | undefined>(); | ||
| const [metric, setMetric] = useState<SnapshotMetricInput>({ type: 'cpu' }); | ||
|
|
||
| return { | ||
| nodeType, | ||
| filterQuery, | ||
| metric, | ||
| setNodeType, | ||
| setFilterQuery, | ||
| setMetric, | ||
| }; | ||
| }; |
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
118 changes: 118 additions & 0 deletions
118
x-pack/plugins/infra/public/alerting/metric_threshold/components/expression.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,118 @@ | ||
| /* | ||
| * 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 { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers'; | ||
| import { actionTypeRegistryMock } from '../../../../../triggers_actions_ui/public/application/action_type_registry.mock'; | ||
| import { alertTypeRegistryMock } from '../../../../../triggers_actions_ui/public/application/alert_type_registry.mock'; | ||
| import { coreMock } from '../../../../../../../src/core/public/mocks'; | ||
| import { AlertsContextValue } from '../../../../../triggers_actions_ui/public/application/context/alerts_context'; | ||
| import { AlertContextMeta } from '../types'; | ||
| import { MetricsExplorerMetric } from '../../../../common/http_api/metrics_explorer'; | ||
| import React from 'react'; | ||
| import { Expressions } from './expression'; | ||
| import { act } from 'react-dom/test-utils'; | ||
| // eslint-disable-next-line @kbn/eslint/no-restricted-paths | ||
| import { Comparator } from '../../../../server/lib/alerting/metric_threshold/types'; | ||
|
|
||
| jest.mock('../../../containers/source/use_source_via_http', () => ({ | ||
| useSourceViaHttp: () => ({ | ||
| source: { id: 'default' }, | ||
| createDerivedIndexPattern: () => ({ fields: [], title: 'metricbeat-*' }), | ||
| }), | ||
| })); | ||
|
|
||
| describe('Expression', () => { | ||
| async function setup(currentOptions: { | ||
| metrics?: MetricsExplorerMetric[]; | ||
| filterQuery?: string; | ||
| groupBy?: string; | ||
| }) { | ||
| const alertParams = { | ||
| criteria: [], | ||
| groupBy: undefined, | ||
| filterQueryText: '', | ||
| }; | ||
|
|
||
| const mocks = coreMock.createSetup(); | ||
| const [ | ||
| { | ||
| application: { capabilities }, | ||
| }, | ||
| ] = await mocks.getStartServices(); | ||
|
|
||
| const context: AlertsContextValue<AlertContextMeta> = { | ||
| http: mocks.http, | ||
| toastNotifications: mocks.notifications.toasts, | ||
| actionTypeRegistry: actionTypeRegistryMock.create() as any, | ||
| alertTypeRegistry: alertTypeRegistryMock.create() as any, | ||
| docLinks: mocks.docLinks, | ||
| capabilities: { | ||
| ...capabilities, | ||
| actions: { | ||
| delete: true, | ||
| save: true, | ||
| show: true, | ||
| }, | ||
| }, | ||
| metadata: { | ||
| currentOptions, | ||
| }, | ||
| }; | ||
|
|
||
| const wrapper = mountWithIntl( | ||
| <Expressions | ||
| alertsContext={context} | ||
| alertInterval="1m" | ||
| alertParams={alertParams} | ||
| errors={[]} | ||
| setAlertParams={(key, value) => Reflect.set(alertParams, key, value)} | ||
| setAlertProperty={() => {}} | ||
| /> | ||
| ); | ||
|
|
||
| const update = async () => | ||
| await act(async () => { | ||
| await nextTick(); | ||
| wrapper.update(); | ||
| }); | ||
|
|
||
| await update(); | ||
|
|
||
| return { wrapper, update, alertParams }; | ||
| } | ||
|
|
||
| it('should prefill the alert using the context metadata', async () => { | ||
| const currentOptions = { | ||
| groupBy: 'host.hostname', | ||
| filterQuery: 'foo', | ||
| metrics: [ | ||
| { aggregation: 'avg', field: 'system.load.1' }, | ||
| { aggregation: 'cardinality', field: 'system.cpu.user.pct' }, | ||
| ] as MetricsExplorerMetric[], | ||
| }; | ||
| const { alertParams } = await setup(currentOptions); | ||
| expect(alertParams.groupBy).toBe('host.hostname'); | ||
| expect(alertParams.filterQueryText).toBe('foo'); | ||
| expect(alertParams.criteria).toEqual([ | ||
| { | ||
| metric: 'system.load.1', | ||
| comparator: Comparator.GT, | ||
| threshold: [], | ||
| timeSize: 1, | ||
| timeUnit: 'm', | ||
| aggType: 'avg', | ||
| }, | ||
| { | ||
| metric: 'system.cpu.user.pct', | ||
| comparator: Comparator.GT, | ||
| threshold: [], | ||
| timeSize: 1, | ||
| timeUnit: 'm', | ||
| aggType: 'cardinality', | ||
| }, | ||
| ]); | ||
| }); | ||
| }); |
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
34 changes: 34 additions & 0 deletions
34
...lugins/infra/public/alerting/metric_threshold/hooks/use_metric_threshold_alert_prefill.ts
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,34 @@ | ||
| /* | ||
| * 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 { isEqual } from 'lodash'; | ||
| import { useState } from 'react'; | ||
| import { MetricsExplorerMetric } from '../../../../common/http_api/metrics_explorer'; | ||
|
|
||
| interface MetricThresholdPrefillOptions { | ||
| groupBy: string | string[] | undefined; | ||
| filterQuery: string | undefined; | ||
| metrics: MetricsExplorerMetric[]; | ||
| } | ||
|
|
||
| export const useMetricThresholdAlertPrefill = () => { | ||
| const [prefillOptionsState, setPrefillOptionsState] = useState<MetricThresholdPrefillOptions>({ | ||
| groupBy: undefined, | ||
| filterQuery: undefined, | ||
| metrics: [], | ||
| }); | ||
|
|
||
| const { groupBy, filterQuery, metrics } = prefillOptionsState; | ||
|
|
||
| return { | ||
| groupBy, | ||
| filterQuery, | ||
| metrics, | ||
| setPrefillOptions(newState: MetricThresholdPrefillOptions) { | ||
| if (!isEqual(newState, prefillOptionsState)) setPrefillOptionsState(newState); | ||
| }, | ||
| }; | ||
| }; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* | ||
| * 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 createContainer from 'constate'; | ||
| import { useMetricThresholdAlertPrefill } from './metric_threshold/hooks/use_metric_threshold_alert_prefill'; | ||
| import { useInventoryAlertPrefill } from './inventory/hooks/use_inventory_alert_prefill'; | ||
|
|
||
| const useAlertPrefill = () => { | ||
| const metricThresholdPrefill = useMetricThresholdAlertPrefill(); | ||
| const inventoryPrefill = useInventoryAlertPrefill(); | ||
|
|
||
| return { metricThresholdPrefill, inventoryPrefill }; | ||
| }; | ||
|
|
||
| export const [AlertPrefillProvider, useAlertPrefillContext] = createContainer(useAlertPrefill); |
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.