Skip to content
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

[Discover][Alerting] Use Discover locator for alert results link #146403

Merged
merged 54 commits into from Jan 4, 2023

Conversation

dimaanj
Copy link
Contributor

@dimaanj dimaanj commented Nov 28, 2022

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
Query to use
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" }
        }
    }
}
  • 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

@dimaanj dimaanj added Feature:Discover Discover Application Team:DataDiscovery Discover App Team (Document Explorer, Saved Search, Surrounding documents, Graph) labels Nov 28, 2022
@dimaanj dimaanj self-assigned this Nov 28, 2022
@dimaanj
Copy link
Contributor Author

dimaanj commented Dec 1, 2022

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

expected head sha didn’t match current head ref.

…cover-locator-for-alert-results

# Conflicts:
#	src/plugins/discover/public/application/main/components/sidebar/discover_sidebar.test.tsx
#	src/plugins/discover/public/application/main/components/sidebar/discover_sidebar.tsx
#	src/plugins/discover/public/application/main/components/sidebar/discover_sidebar_responsive.test.tsx
#	src/plugins/discover/public/application/main/components/sidebar/discover_sidebar_responsive.tsx
@dimaanj dimaanj changed the title [Discover][Alerting] Use Discover locator for alert results link POC [Discover][Alerting] Use Discover locator for alert results link Dec 1, 2022
…cover-locator-for-alert-results

# Conflicts:
#	src/plugins/kibana_utils/common/state_management/state_hash.test.ts
#	src/plugins/kibana_utils/public/state_management/state_encoder/encode_decode_state.ts
@dimaanj dimaanj marked this pull request as ready for review December 1, 2022 19:51
@dimaanj dimaanj requested review from a team as code owners December 1, 2022 19:51
services.share.url.locators.get<DiscoverAppLocatorParams>('DISCOVER_APP_LOCATOR')!,
services.dataViews,
index,
dateStart,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So here's the hopefully last thing I've found. When using dataStart to generate the link, this doesn't take
excludeHitsFromPreviousRun into consideration (L120)

updateSearchSource on L95 returns dataStart always the full time range. But given excludeHitsFromPreviousRun is set, there can be an additional filter to prevent to have documents counted twice. This leads to the following mismatch of count when clicking the link in the notification:

Discover_-Elastic_und_kibana-alerting-slack-tests-Elastic-4_new_items-Slack_und__Discover__Alerting__Use_Discover_locator_for_alert_results_link_by_dimaanj·Pull_Request__146403·_elastic_kibana
Correct me if I'm wrong but I think this was already broken before this PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, this ain't an issue of this PR, just tried out on a previous version, works the same ... we should open an issue for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #148282

@kertal kertal self-requested a review December 30, 2022 07:30
Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Tested again on the cloud. The issue I've found, that the timerange of the notification doesn't take Exclude matches from previous runs into consideration, works the same on previous versions, so it can be fixed in a follow up

Great idea and work to use locators for the link 👍

…cover-locator-for-alert-results

# Conflicts:
#	src/plugins/discover/public/application/main/components/layout/discover_layout.tsx
#	src/plugins/discover/public/application/main/components/sidebar/discover_sidebar.test.tsx
#	src/plugins/discover/public/application/main/components/sidebar/discover_sidebar_responsive.tsx
#	src/plugins/discover/public/application/main/discover_main_route.tsx
#	src/plugins/discover/public/application/main/services/discover_state.ts
@dimaanj
Copy link
Contributor Author

dimaanj commented Dec 30, 2022

@elasticmachine merge upstream

@dimaanj
Copy link
Contributor Author

dimaanj commented Jan 3, 2023

@elasticmachine merge upstream

@dimaanj dimaanj removed ci:cloud-deploy Create or update a Cloud deployment ci:cloud-redeploy Always create a new Cloud deployment labels Jan 3, 2023
@dimaanj
Copy link
Contributor Author

dimaanj commented Jan 3, 2023

@elasticmachine merge upstream

@dimaanj
Copy link
Contributor Author

dimaanj commented Jan 3, 2023

@elasticmachine merge upstream

@dimaanj
Copy link
Contributor Author

dimaanj commented Jan 4, 2023

@elasticmachine merge upstream

@dimaanj
Copy link
Contributor Author

dimaanj commented Jan 4, 2023

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Security Solution Tests #4 / Add exception using data views from rule details Creates an exception item from alert actions overflow menu

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
discover 448 446 -2
kibanaUtils 165 168 +3
total +1

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
alerting 418 420 +2
discover 82 88 +6
kibanaUtils 424 418 -6
total +2

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
dashboard 365.3KB 365.4KB +39.0B
dataViewManagement 116.1KB 116.2KB +92.0B
discover 407.1KB 395.4KB -11.7KB
kibanaUtils 60.8KB 60.8KB +5.0B
transform 347.9KB 347.9KB +2.0B
total -11.6KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
discover 4 7 +3
kibanaUtils 8 9 +1
total +4

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
dashboard 25.4KB 25.5KB +149.0B
discover 28.0KB 28.1KB +73.0B
kibanaUtils 68.7KB 69.7KB +932.0B
transform 15.3KB 15.4KB +138.0B
visualizations 56.6KB 56.6KB +10.0B
total +1.3KB
Unknown metric groups

API count

id before after diff
alerting 427 429 +2
discover 100 107 +7
kibanaUtils 624 619 -5
total +4

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @dimaanj

Copy link
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Response Ops changes LGTM

@dimaanj dimaanj merged commit 503b466 into elastic:main Jan 4, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jan 4, 2023
jughosta added a commit that referenced this pull request May 31, 2023
- Addresses #158262

## Summary

This PR makes alert links shorter by removing redundant props from the
encoded state. We should trim it down more in the future. Backporting a
small fix for now.

For testing:
Please follow instructions from this PR description
#146403
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request May 31, 2023
- Addresses elastic#158262

## Summary

This PR makes alert links shorter by removing redundant props from the
encoded state. We should trim it down more in the future. Backporting a
small fix for now.

For testing:
Please follow instructions from this PR description
elastic#146403

(cherry picked from commit ef07c97)
kibanamachine added a commit that referenced this pull request May 31, 2023
# Backport

This will backport the following commits from `main` to `8.8`:
- [[Discover][Alerts] Make alert links shorter
(#158582)](#158582)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Julia
Rechkunova","email":"julia.rechkunova@elastic.co"},"sourceCommit":{"committedDate":"2023-05-31T05:28:35Z","message":"[Discover][Alerts]
Make alert links shorter (#158582)\n\n- Addresses
#158262
Summary\r\n\r\nThis PR makes alert links shorter by removing redundant
props from the\r\nencoded state. We should trim it down more in the
future. Backporting a\r\nsmall fix for now.\r\n\r\nFor
testing:\r\nPlease follow instructions from this PR
description\r\nhttps://github.com//pull/146403","sha":"ef07c978689872d2ae3037aa06a0f2f7b23c3582","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:DataDiscovery","backport:prev-minor","v8.9.0"],"number":158582,"url":"#158582
Make alert links shorter (#158582)\n\n- Addresses
#158262
Summary\r\n\r\nThis PR makes alert links shorter by removing redundant
props from the\r\nencoded state. We should trim it down more in the
future. Backporting a\r\nsmall fix for now.\r\n\r\nFor
testing:\r\nPlease follow instructions from this PR
description\r\nhttps://github.com//pull/146403","sha":"ef07c978689872d2ae3037aa06a0f2f7b23c3582"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"#158582
Make alert links shorter (#158582)\n\n- Addresses
#158262
Summary\r\n\r\nThis PR makes alert links shorter by removing redundant
props from the\r\nencoded state. We should trim it down more in the
future. Backporting a\r\nsmall fix for now.\r\n\r\nFor
testing:\r\nPlease follow instructions from this PR
description\r\nhttps://github.com//pull/146403","sha":"ef07c978689872d2ae3037aa06a0f2f7b23c3582"}}]}]
BACKPORT-->

Co-authored-by: Julia Rechkunova <julia.rechkunova@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Discover Discover Application release_note:fix Team:DataDiscovery Discover App Team (Document Explorer, Saved Search, Surrounding documents, Graph) v8.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Discover][Alerting] Use Discover locator for EsQuery alert results navigation