-
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.
[Discover][Alerting] Use Discover locator for alert results link (#14…
…6403) ## Summary Closes #145815, #134232 - Moves Discover locator to common area - Builds alerts results link from the server - Now there are two implementations of `setStateToKbnUrl` which is used in locator. New one in common are lost `HashedItemStore` support, since sessions storage are actual only for browser - Toasts `Alert rule has changed`, `Data View has changed` removed - link generated per each alert will be unique representation of those `rule params` and `data view state` which were at the time of invocation - Restuls link will live even after data view and rule removal ### How to create rule - Create an output index and data view `test` <details> <summary>Query to use</summary> ``` PUT test { "settings" : { "number_of_shards" : 1 }, "mappings" : { "properties" : { "rule_id" : { "type" : "text" }, "rule_name" : { "type" : "text" }, "alert_id" : { "type" : "text" }, "context_message": { "type" : "text" } } } } ``` </details> - Create alerts connector using `test` index - Open `Elasticsearch query` alert in `KQL or Lucene` mode or just using Discover `Alerts` button - Specify the following params: `IS ABOVE: 1`, `FOR THE LAST: 30 min` - Try execute it by clicking `Test query`. It should match some results - When choosing connector, use the following config ``` { "rule_id": "{{rule.id}}", "rule_name": "{{rule.name}}", "alert_id": "{{alert.id}}", "context_message": "{{context.message}}" } ``` - Create the alert ### How to test - Create `Elasticsearch query` rule in `KQL or Lucene` mode like described above - Wait for some seconds and find the triggered alert document by browsing `test` data view in Discover. There should be a link to results in `context_message` field. Save the link somewhere - Change rule params by adding/removing filters / changing query / changing data view - Follow saved link, you should see previous filters, query and data view state - Open rule in management and click `View in app`, you should see actual state of rule - Try to remove used data view and then follow saved link, you should still see the results - Try to remove rule and then follow saved link, you should still see the results. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [x] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) Co-authored-by: Davis McPhee <[email protected]>
- Loading branch information
1 parent
4e11ef1
commit 503b466
Showing
90 changed files
with
924 additions
and
451 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 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
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
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
41 changes: 41 additions & 0 deletions
41
src/plugins/discover/public/application/main/hooks/use_alert_results_toast.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,41 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { ToastsStart } from '@kbn/core/public'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { MarkdownSimple, toMountPoint } from '@kbn/kibana-react-plugin/public'; | ||
import React, { useEffect } from 'react'; | ||
|
||
export const displayPossibleDocsDiffInfoAlert = (toastNotifications: ToastsStart) => { | ||
const infoTitle = i18n.translate('discover.viewAlert.documentsMayVaryInfoTitle', { | ||
defaultMessage: 'Displayed documents may vary', | ||
}); | ||
const infoDescription = i18n.translate('discover.viewAlert.documentsMayVaryInfoDescription', { | ||
defaultMessage: `The displayed documents might differ from the documents that triggered the alert. | ||
Some documents might have been added or deleted.`, | ||
}); | ||
|
||
toastNotifications.addInfo({ | ||
title: infoTitle, | ||
text: toMountPoint(<MarkdownSimple>{infoDescription}</MarkdownSimple>), | ||
}); | ||
}; | ||
|
||
export const useAlertResultsToast = ({ | ||
isAlertResults, | ||
toastNotifications, | ||
}: { | ||
isAlertResults?: boolean; | ||
toastNotifications: ToastsStart; | ||
}) => { | ||
useEffect(() => { | ||
if (isAlertResults) { | ||
displayPossibleDocsDiffInfoAlert(toastNotifications); | ||
} | ||
}, [isAlertResults, toastNotifications]); | ||
}; |
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.