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

Stack Management elasticsearch-js client migration #73973

Closed
17 tasks done
cjcenizal opened this issue Jul 31, 2020 · 1 comment · Fixed by #105863
Closed
17 tasks done

Stack Management elasticsearch-js client migration #73973

cjcenizal opened this issue Jul 31, 2020 · 1 comment · Fixed by #105863
Labels
chore Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more

Comments

@cjcenizal
Copy link
Contributor

cjcenizal commented Jul 31, 2020

Summary

Per #83910, the new elasticsearch-js client is available in Kibana and we need to migrate our apps over to it prior to 7.14.

Learn more about the new elasticsearch-js client at https://github.com/elastic/elasticsearch-js.

See the ES JS client API reference.

Punch list

Apps

Alison

Yulia

JL

CJ

How to migrate

📚 Be prepared! Review the migration guide.

Basic steps

  • Replace instances of import { LegacyAPICaller } from 'src/core/server' with import { ElasticsearchClient } from 'kibana/server'.
  • Replace instances of LegacyAPICaller (commonly named callAsCurrentUser) with ElasticsearchClient (commonly named client).
  • Replace instances of transport.request with direct calls to the APIs defined on the new client (see API docs).
  • Similarly, replace consumption of legacy client extensions (e.g. https://github.com/elastic/kibana/blob/master/x-pack/plugins/cross_cluster_replication/server/client/elasticsearch_ccr.ts) with direct calls to the APIs defined on the new client.
  • Replace references to context.core.elasticsearch.legacy.client.callAsCurrentUser with references to context.core.elasticsearch.client.asCurrentUser.

Handling errors

When handling errors, replaces usage of lib.isEsError(e) with a comparison of e.name === 'ResponseError' and replace usage of:

return response.customError({
  statusCode: e.statusCode,
  body: e,
});

with:

// See https://github.com/elastic/kibana/pull/80302 for an example of how to provide handleEsError
return handleEsError({ error, response });

Per #84801, test the app and verify that full ES errors are surfaced in the UI via SectionError, if applicable.

API integration tests

  • Migrate references of getService('legacyEs') to getService('es').
  • The es service now returns a promise that resolves to an object containing the body. So any helper functions that consume this API like const getIndex = (index) => es.indices.get({ index }); will need to be migrated to handle the resolved promise and pull out the body: ``const getIndex = (index) => es.indices.get({ index }).then(({ body }) => body);`.
  • Re-run tests (steps below) to verify the client hasn't changed the way errors are reported.
# tab 1
cd x-pack && node scripts/functional_tests_server.js

# tab 2
node scripts/functional_test_runner.js --config x-pack/test/api_integration/config.ts --grep "Some string from the test case name" 

Functional tests

We also need to migrate functional tests over from using the legacyEs service to the es service. This means replacing instances of getService('legacyEs') with getService('es'), and ensuring that the required APIs are available.

Once you're done

  • Update the punch list at the top of this issue by checking off completed items and linking to the relevant PRs
  • Update the migration tracker meta issue and check off completed items
@cjcenizal cjcenizal added chore Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more labels Jul 31, 2020
@elasticmachine
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants