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

Makes alerting and actions optional properties for interface RequestH… #59264

Conversation

YulNaumenko
Copy link
Contributor

Resolves #59239

@YulNaumenko YulNaumenko added Feature:Alerting v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.7.0 Feature:Actions Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) labels Mar 4, 2020
@YulNaumenko YulNaumenko requested a review from a team as a code owner March 4, 2020 03:52
@YulNaumenko YulNaumenko self-assigned this Mar 4, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-alerting-services (Team:Alerting Services)

@YulNaumenko YulNaumenko requested a review from rudolf March 4, 2020 03:53
Copy link
Member

@pmuellr pmuellr left a comment

Choose a reason for hiding this comment

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

Interesting! Technically correct, but given the type-check errors in CI, we'll need to guard our own usage of these :-)

I worry that other users will need such guards, which is going to get noisy/boiler-platey.

One thing we could do instead, is add a function to the request handler, to get the actions/alerts client. Which returned the type expected, and throws an error if the relevant client wasn't available.

I guess there must be some other common pattern to access these request context properties other plugins are using?

Copy link
Contributor

@mikecote mikecote left a comment

Choose a reason for hiding this comment

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

Changes LGTM, thanks for doing this!

@pmuellr

One thing we could do instead, is add a function to the request handler, to get the actions/alerts client. Which returned the type expected, and throws an error if the relevant client wasn't available.

It is strange for sure. The actions and alerting objects will be null when the plugin is disabled. When disabled, we won’t be able to register the function to the request context that returns the type expected. Maybe platform team has suggestions for this?

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

Copy link
Member

@pmuellr pmuellr left a comment

Choose a reason for hiding this comment

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

LGTM

@YulNaumenko YulNaumenko merged commit 755439d into elastic:master Mar 5, 2020
YulNaumenko added a commit to YulNaumenko/kibana that referenced this pull request Mar 5, 2020
elastic#59264)

* Makes alerting and actions optional properties for interface RequestHandlerContext

* Added an error response result if context for actions and alerting is not registered
spalger added a commit that referenced this pull request Mar 5, 2020
@spalger
Copy link
Contributor

spalger commented Mar 5, 2020

This PR was causing type errors after being merged: https://kibana-ci.elastic.co/job/elastic+kibana+master/3430/execution/node/146/log/

19:43:03  ERROR x-pack failed
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/add_prepackaged_rules_route.test.ts:66:7 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        66       context.alerting.getAlertsClient = jest.fn();
19:43:03                 ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/add_prepackaged_rules_route.ts:36:30 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        36         const alertsClient = context.alerting.getAlertsClient();
19:43:03                                        ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/add_prepackaged_rules_route.ts:37:31 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        37         const actionsClient = context.actions.getActionsClient();
19:43:03                                         ~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/create_rules_bulk_route.test.ts:42:7 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        42       context.alerting.getAlertsClient = jest.fn();
19:43:03                 ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/create_rules_bulk_route.ts:38:28 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        38       const alertsClient = context.alerting.getAlertsClient();
19:43:03                                      ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/create_rules_bulk_route.ts:39:29 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        39       const actionsClient = context.actions.getActionsClient();
19:43:03                                       ~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/create_rules_route.test.ts:44:7 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        44       context.alerting.getAlertsClient = jest.fn();
19:43:03                 ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/create_rules_route.ts:62:30 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        62         const alertsClient = context.alerting.getAlertsClient();
19:43:03                                        ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/create_rules_route.ts:63:31 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        63         const actionsClient = context.actions.getActionsClient();
19:43:03                                         ~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/delete_rules_bulk_route.test.ts:85:7 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        85       context.alerting.getAlertsClient = jest.fn();
19:43:03                 ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/delete_rules_bulk_route.ts:35:26 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        35     const alertsClient = context.alerting.getAlertsClient();
19:43:03                                    ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/delete_rules_bulk_route.ts:36:27 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        36     const actionsClient = context.actions.getActionsClient();
19:43:03                                     ~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/delete_rules_route.test.ts:59:7 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        59       context.alerting.getAlertsClient = jest.fn();
19:43:03                 ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/delete_rules_route.ts:37:30 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        37         const alertsClient = context.alerting.getAlertsClient();
19:43:03                                        ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/delete_rules_route.ts:38:31 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        38         const actionsClient = context.actions.getActionsClient();
19:43:03                                         ~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/export_rules_route.ts:30:28 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        30       const alertsClient = context.alerting.getAlertsClient();
19:43:03                                      ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/find_rules_route.test.ts:39:7 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        39       context.alerting.getAlertsClient = jest.fn();
19:43:03                 ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/find_rules_route.ts:35:30 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        35         const alertsClient = context.alerting.getAlertsClient();
19:43:03                                        ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/find_rules_status_route.test.ts:32:7 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        32       context.alerting.getAlertsClient = jest.fn();
19:43:03                 ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/find_rules_status_route.ts:37:28 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        37       const alertsClient = context.alerting.getAlertsClient();
19:43:03                                      ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/get_prepackaged_rules_status_route.test.ts:61:7 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        61       context.alerting.getAlertsClient = jest.fn();
19:43:03                 ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/get_prepackaged_rules_status_route.ts:31:28 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        31       const alertsClient = context.alerting.getAlertsClient();
19:43:03                                      ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/import_rules_route.test.ts:81:7 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        81       context.alerting.getAlertsClient = jest.fn();
19:43:03                 ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/import_rules_route.test.ts:88:7 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        88       context.actions.getActionsClient = jest.fn();
19:43:03                 ~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/import_rules_route.ts:57:28 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        57       const alertsClient = context.alerting.getAlertsClient();
19:43:03                                      ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/import_rules_route.ts:58:29 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        58       const actionsClient = context.actions.getActionsClient();
19:43:03                                       ~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/patch_rules_bulk_route.test.ts:51:7 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        51       context.alerting.getAlertsClient = jest.fn();
19:43:03                 ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/patch_rules_bulk_route.ts:33:28 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        33       const alertsClient = context.alerting.getAlertsClient();
19:43:03                                      ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/patch_rules_bulk_route.ts:34:29 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        34       const actionsClient = context.actions.getActionsClient();
19:43:03                                       ~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/patch_rules_route.test.ts:52:7 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        52       context.alerting.getAlertsClient = jest.fn();
19:43:03                 ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/patch_rules_route.ts:63:30 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        63         const alertsClient = context.alerting.getAlertsClient();
19:43:03                                        ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/patch_rules_route.ts:64:31 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        64         const actionsClient = context.actions.getActionsClient();
19:43:03                                         ~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/read_rules_route.test.ts:39:7 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        39       context.alerting.getAlertsClient = jest.fn();
19:43:03                 ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/read_rules_route.ts:33:28 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        33       const alertsClient = context.alerting.getAlertsClient();
19:43:03                                      ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/update_rules_bulk_route.test.ts:56:7 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        56       context.alerting.getAlertsClient = jest.fn();
19:43:03                 ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/update_rules_bulk_route.ts:33:28 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        33       const alertsClient = context.alerting.getAlertsClient();
19:43:03                                      ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/update_rules_bulk_route.ts:34:29 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        34       const actionsClient = context.actions.getActionsClient();
19:43:03                                       ~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/update_rules_route.test.ts:53:7 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        53       context.alerting.getAlertsClient = jest.fn();
19:43:03                 ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/update_rules_route.ts:63:30 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        63         const alertsClient = context.alerting.getAlertsClient();
19:43:03                                        ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/update_rules_route.ts:64:31 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        64         const actionsClient = context.actions.getActionsClient();
19:43:03                                         ~~~~~~~~~~~~~~~
19:43:03  
19:43:03        x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/tags/read_tags_route.ts:22:28 - error TS2532: Object is possibly 'undefined'.
19:43:03  
19:43:03        22       const alertsClient = context.alerting.getAlertsClient();
19:43:03                                      ~~~~~~~~~~~~~~~~
19:43:03  
19:43:03  
19:43:03        Found 41 errors.

jloleysens added a commit to jloleysens/kibana that referenced this pull request Mar 5, 2020
…re/files-and-filetree

* 'master' of github.com:elastic/kibana: (254 commits)
  Convert discover_page to ts, remove redundunt methods (elastic#59312)
  [Fix for Vis Editor] Revert setting time field to empty string when it's undefined (elastic#58873)
  Delete legacy search endpoint (elastic#59341)
  [Uptime] Improve duration chart (elastic#58404)
  [Snapshot & Restore] NP migration (elastic#59109)
  [ML] Add support for date_nanos time field in anomaly job wizard (elastic#59017)
  Revert "Makes alerting and actions optional properties for interface RequestH… (elastic#59264)"
  Change remote_clusters ID to remoteClusters (elastic#59246)
  Makes alerting and actions optional properties for interface RequestH… (elastic#59264)
  Clean up date histogram agg type. (elastic#58805)
  [ML] Management: fix license unsubscribe (elastic#59365)
  Remove documentation for server.cors settings (elastic#59096)
  Edit alert flyout (elastic#58964)
  [SIEM] Fix rule delete/duplicate actions (elastic#59306)
  move mouse to close obstructing tooltip (elastic#59214)
  Reset page after deleting (elastic#59310)
  Make sure phrases input filter triggers autosuggestons (elastic#59299)
  Add loading count source for http requests (elastic#59245)
  Revert "[ML] Transforms: Deprecate custom KibanaContext. (elastic#59133)"
  Expose metrics service to public API (elastic#59294)
  ...

# Conflicts:
#	src/plugins/console/public/application/containers/editor/legacy/console_editor/editor.tsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Actions Feature:Alerting release_note:skip Skip the PR/issue when compiling release notes reverted Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Alerting] Make RequestHandlerContext alerting property as optional
6 participants