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

[Watcher] Migrate to new ES client #97260

Merged
merged 14 commits into from
Apr 30, 2021

Conversation

jloleysens
Copy link
Contributor

@jloleysens jloleysens commented Apr 15, 2021

Summary

See #73973

How to test

  1. Start Kibana and ES and activate your trial license in the License Management
  2. Follow the UI for creating both an advanced watch and a threshold watch
    • For the threshold set a very low document count threshold for the .kibana index so that the alert will fire
    • Add a logging action for the threshold watch
    • Ensure that the watch will fire frequently (every 5 seconds or so)
  3. Go the the home screen of the watcher management section and click on the threshold watch
  4. Once the watch has entered "Firing" state attempt to acknowledge the alert

@jloleysens jloleysens added Feature:Watcher v8.0.0 Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more release_note:skip Skip the PR/issue when compiling release notes v7.13.0 labels Apr 15, 2021
@jloleysens jloleysens marked this pull request as ready for review April 15, 2021 16:07
@jloleysens jloleysens requested a review from a team as a code owner April 15, 2021 16:07
@elasticmachine
Copy link
Contributor

Pinging @elastic/es-ui (Team:Elasticsearch UI)

…te-legacy-es-client

* 'master' of github.com:elastic/kibana: (102 commits)
  [Exploratory view] integerate page views to exploratory view (elastic#97258)
  Fix typo in license_api_guard README name and import http server mocks from public interface (elastic#97334)
  Avoid mutating KQL query when validating it (elastic#97081)
  Add description as title on tag badge (elastic#97109)
  Remove legacy ES client usages in `home` and `xpack_legacy` (elastic#97359)
  [Fleet] Finer-grained error information from install/upgrade API (elastic#95649)
  Rule registry bundle size (elastic#97251)
  [Partial Results] Move other bucket into Search Source (elastic#96384)
  [Dashboard] Makes lens default editor for creating new panels (elastic#96181)
  skip flaky suite (elastic#97387)
  [Asset Management] Agent picker follow up (elastic#97357)
  skip flaky suite (elastic#97382)
  [Security Solutions] Fixes flake with cypress tests (elastic#97329)
  skip flaky suite (elastic#97355)
  Skip test to try and stabilize master
  minimize number of so fild asserted in tests. it creates flakines when implementation details change (elastic#97374)
  [Search Sessions] Client side search cache (elastic#92439)
  [SavedObjects] Add aggregations support (elastic#96292)
  [Reporting] Remove legacy elasticsearch client usage from the reporting plugin (elastic#97184)
  [kbnClient] fix basePath handling and export reponse type (elastic#97277)
  ...

# Conflicts:
#	x-pack/plugins/watcher/server/lib/license_pre_routing_factory/license_pre_routing_factory.ts
#	x-pack/plugins/watcher/server/plugin.ts
#	x-pack/plugins/watcher/server/routes/api/indices/register_get_route.ts
#	x-pack/plugins/watcher/server/routes/api/license/register_refresh_route.ts
#	x-pack/plugins/watcher/server/routes/api/register_list_fields_route.ts
#	x-pack/plugins/watcher/server/routes/api/register_load_history_route.ts
#	x-pack/plugins/watcher/server/routes/api/settings/register_load_route.ts
#	x-pack/plugins/watcher/server/routes/api/watch/action/register_acknowledge_route.ts
#	x-pack/plugins/watcher/server/routes/api/watch/register_activate_route.ts
#	x-pack/plugins/watcher/server/routes/api/watch/register_deactivate_route.ts
#	x-pack/plugins/watcher/server/routes/api/watch/register_delete_route.ts
#	x-pack/plugins/watcher/server/routes/api/watch/register_execute_route.ts
#	x-pack/plugins/watcher/server/routes/api/watch/register_history_route.ts
#	x-pack/plugins/watcher/server/routes/api/watch/register_load_route.ts
#	x-pack/plugins/watcher/server/routes/api/watch/register_save_route.ts
#	x-pack/plugins/watcher/server/routes/api/watch/register_visualize_route.ts
#	x-pack/plugins/watcher/server/routes/api/watches/register_delete_route.ts
#	x-pack/plugins/watcher/server/routes/api/watches/register_list_route.ts
#	x-pack/plugins/watcher/server/shared_imports.ts
#	x-pack/plugins/watcher/server/types.ts
@jloleysens
Copy link
Contributor Author

@elasticmachine merge upstream

@jloleysens
Copy link
Contributor Author

@elasticmachine merge upstream

@cjcenizal
Copy link
Contributor

@elasticmachine merge upstream

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

Tested locally, code LGTM! Had a few comments and questions, but nothing worth blocking.

I tested the following behavior:

  • Create watch
  • Edit watch
  • Fetch execution history
  • Fetch action statuses
  • Activate watch
  • Deactivate watch
  • Delete watch

I didn't get to test the acknowledge route, but will do so tomorrow.

): Promise<any> {
const newHits = get(searchResuls, 'hits.hits', []);
const scrollId = get(searchResuls, '_scroll_id');
searchResults: ScrollResponse<unknown>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice typo catch!

@@ -33,9 +29,9 @@ describe('fetch_all_from_scroll', () => {
});
});

it('should not call callWithRequest', () => {
it('should not call asCurrentUser.scroll', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like how these tests became clearer as a result of this migration!

return response.aggregations.indices.buckets.map((bucket: any) => bucket.key);
});
});
return indices.buckets ? indices.buckets.map((bucket) => bucket.key) : [];
Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to suggest being even stricter here:

return Array.isArray(indices.buckets) ? indices.buckets.map((bucket) => bucket.key) : [];

I'm imagining the response containing something unexpected, either because of a deliberate API change or because of a bug, and generating a 500 because map is undefined. But then I decided that it will be easier to debug a user complaining about a 500 and the accompanying stack trace in the logs, than it would be to debug a user complaining about silently disappearing information. So I think this is good as-is. :)

{
index: indexes,
fields: ['*'],
allow_no_indices: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the ignoreUnavailable param was omitted. Was that deliberate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope this was a mistake!

// Case: default
throw e;
// TODO: Figure out if this covers us sufficiently given that previous logic returned a body with "Watch with id = ${watchId} not found" previously
return handleEsError({ error: e, response });
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you look into how to test this, either in this handler or in the other route handlers that contain this TODO?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I just checked this out and it looks like the ES response we get looks like:

Screenshot 2021-04-29 at 15 56 29

Which is not very user friendly. So I reintroduced the renaming logic so that the response for 404s is now:

Screenshot 2021-04-29 at 15 59 45

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

{
index,
body,
allow_no_indices: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the decision to omit ignoreUnavailable was deliberate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above, will re-add

},
{ ignore: [404] }
)
.then(({ body: response }) => fetchAllFromScroll(response, dataClient));
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: why not pass body as-is instead of renaming it?

.then(({ body }) => fetchAllFromScroll(body, dataClient));

@jloleysens
Copy link
Contributor Author

@elasticmachine merge upstream

@alisonelizabeth
Copy link
Contributor

It's awesome to see yet another plugin migrated to use the new ES client 🎉 ! Nice job working through these. I was wondering if we can also delete watcher/server/lib/elasticsearch_js_plugin.ts as part of this work?

@jloleysens
Copy link
Contributor Author

we can also delete watcher/server/lib/elasticsearch_js_plugin.ts as part of this work?

I always leave this for last for some reason 😅 , seems like to should be the first order of business.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

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

@jloleysens jloleysens merged commit e297fec into elastic:master Apr 30, 2021
@jloleysens jloleysens deleted the watcher/migrate-legacy-es-client branch April 30, 2021 08:44
jloleysens added a commit to jloleysens/kibana that referenced this pull request Apr 30, 2021
* initial migration away from ILegacyScopedClusterClient to
IScopedClusterClient and from "isEsError" to "handleEsError"

* re-instate ignore: [404]

* remove use of ignore_unavailable

* get the correct payload from the response

* fix use of new licensePreRoutingFactory

* fix jest tests

* address CJs feedback and re-add ignore_unavailable, clean up remaining TODOs

* remove legacy client config

* undo renaming as part of destructuring assignment

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
jloleysens added a commit that referenced this pull request Apr 30, 2021
* initial migration away from ILegacyScopedClusterClient to
IScopedClusterClient and from "isEsError" to "handleEsError"

* re-instate ignore: [404]

* remove use of ignore_unavailable

* get the correct payload from the response

* fix use of new licensePreRoutingFactory

* fix jest tests

* address CJs feedback and re-add ignore_unavailable, clean up remaining TODOs

* remove legacy client config

* undo renaming as part of destructuring assignment

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
byronhulcher pushed a commit to byronhulcher/kibana that referenced this pull request Apr 30, 2021
* initial migration away from ILegacyScopedClusterClient to
IScopedClusterClient and from "isEsError" to "handleEsError"

* re-instate ignore: [404]

* remove use of ignore_unavailable

* get the correct payload from the response

* fix use of new licensePreRoutingFactory

* fix jest tests

* address CJs feedback and re-add ignore_unavailable, clean up remaining TODOs

* remove legacy client config

* undo renaming as part of destructuring assignment

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
madirey pushed a commit to madirey/kibana that referenced this pull request May 11, 2021
* initial migration away from ILegacyScopedClusterClient to
IScopedClusterClient and from "isEsError" to "handleEsError"

* re-instate ignore: [404]

* remove use of ignore_unavailable

* get the correct payload from the response

* fix use of new licensePreRoutingFactory

* fix jest tests

* address CJs feedback and re-add ignore_unavailable, clean up remaining TODOs

* remove legacy client config

* undo renaming as part of destructuring assignment

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Watcher release_note:skip Skip the PR/issue when compiling release notes Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.14.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants