Skip to content

Stack Management elasticsearch-js client migration #73973

Closed

Description

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Team:Kibana ManagementDev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and morechore

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions