[Transform] Replace legacy elasticsearch client#84932
[Transform] Replace legacy elasticsearch client#84932darnautov merged 15 commits intoelastic:masterfrom
Conversation
|
Pinging @elastic/ml-ui (:ml) |
…_audit_messages.ts
| cluster, | ||
| } = await ctx.transform!.dataClient.callAsCurrentUser('transport.request', { | ||
| body: { has_all_requested: hasAllPrivileges, cluster }, | ||
| } = await ctx.core.elasticsearch.client.asCurrentUser.transport.request({ |
There was a problem hiding this comment.
I think this should use hasPrivileges from the security namespace.
ctx.core.elasticsearch.client.asCurrentUser.security.hasPrivileges
| const { indices } = await ctx.transform!.dataClient.callAsCurrentUser('transport.request', { | ||
| const { | ||
| body: { indices }, | ||
| } = await ctx.core.elasticsearch.client.asCurrentUser.transport.request({ |
| { path: addBasePath('transforms'), validate: false }, | ||
| license.guardApiRoute(async (ctx, req, res) => { | ||
| const options = {}; | ||
| license.guardApiRoute<TransformGetTransform, undefined, undefined>(async (ctx, req, res) => { |
There was a problem hiding this comment.
ctx.core.elasticsearch.client.asCurrentUser.transform could be extracted as transformClient and passed to the handler function inside guardApiRoute.
This is the pattern we use in ML and saves having to write ctx.core.elasticsearch.client.asCurrentUser.transform. each time.
There was a problem hiding this comment.
I tried it first, but it didn't work. ctx.core.elasticsearch.client.asCurrentUser.transform relies on the context and uses transport under the hood.
There was a problem hiding this comment.
From my tests this works correctly. guardApiRoute can extract ctx.core.elasticsearch.client.asCurrentUser.transform and pass it to the handler callback, and it works correctly when being called in the routes.
There was a problem hiding this comment.
but this suggested change just a refactor for simplifying the code, and is not important for the functionality.
| async function startTransforms( | ||
| transformsInfo: StartTransformsRequestSchema, | ||
| callAsCurrentUser: LegacyAPICaller | ||
| esClient: ElasticsearchClient |
There was a problem hiding this comment.
if you adopt the change suggested above, only transformClient could be passed in to these functions.
| const { | ||
| body, | ||
| } = await ctx.core.elasticsearch.client.asCurrentUser.transform.getTransformStats({ | ||
| transform_id: transformId, |
There was a problem hiding this comment.
the previous version wouldn't send the transform ID if it was undefined, this now always sends one.
is this change intentional?
There was a problem hiding this comment.
yes, this route has this validation schema
, hence this check is redundantThere was a problem hiding this comment.
also covered by API integration tests and checked manually
peteharverson
left a comment
There was a problem hiding this comment.
Tested and the only issue I found was around error handling, where some of the error details previously shown are getting lost.
| if (line !== undefined && col !== undefined) { | ||
| message += | ||
| ', ' + | ||
| i18n.translate('xpack.transform.models.transformService.withColAndLineMessage', { |
There was a problem hiding this comment.
we don't format error messages on the server side.
This will be appended onto an error which will be in english.
| /** | ||
| * Returns an error message based on the root cause | ||
| */ | ||
| function extractErrorMessage({ type, reason, line, col }: EsError): string { |
There was a problem hiding this comment.
I'm not sure this is guaranteed to match all errors raised from elasticsearch.
Also, the root_cause may not have the most relevant information for the error.
In ML we pass the whole es error through to the client and display it when the user clicks the more info button.
There was a problem hiding this comment.
We also have a extractErrorMessage function in the public code of transforms which we bring over from the ML plugin, maybe we can do the same on the server side (assuming there's also a server side function for the ML plugin)?
There was a problem hiding this comment.
It's definitely worth improving error reporting, but in this PR I focused on preserving the initial error message shape.
I'll create an issue to provide more detailed errors in the transform UI.
peteharverson
left a comment
There was a problem hiding this comment.
Tested latest edits and LGTM
💚 Build SucceededMetrics [docs]Distributable file count
History
To update your PR or re-run it, just comment with: |
* [Transform] replace legacy elasticsearch client * [Transform] delete custom legacy client definition, update transforms_audit_messages.ts * [Transform] fix start and stop transform endpoints * [Transform] fix privileges and stats endpoints * [Transform] fix forbidden * [Transform] revert continue statement, add a comment * [Transform] update privileges.ts using security namespace * [Transform] fix error wrappers * [Transform] add functional test for preview error validation * [Transform] extract error message from the root cause * [Transform] remove error translation
…k-field-to-hot-phase * 'master' of github.com:elastic/kibana: (429 commits) simplify popover open state logic (elastic#85379) [Logs UI][Metrics UI] Move actions to the kibana header (elastic#84648) [Search Source] Do not pick scripted fields if * provided (elastic#85133) [Search] Session SO polling (elastic#84225) [Transform] Replace legacy elasticsearch client (elastic#84932) [Uptime]Refactor header and action menu (elastic#83779) Fix agg select external link (elastic#85380) [ILM] Show forcemerge in hot when rollover is searchable snapshot is enabled (elastic#85292) clear using keyboard (elastic#85042) [GS] add tag and dashboard suggestion results (elastic#85144) [ML] API integration tests - skip GetAnomaliesTableData Add ECS field for event.code. (elastic#85109) [Functional][TSVB] Wait for markdown textarea to be cleaned (elastic#85128) skip flaky suite (elastic#62060) skip flaky suite (elastic#85098) Bump highlight.js to v9.18.5 (elastic#84296) Add `server.publicBaseUrl` config (elastic#85075) [Alerting & Actions ] More debug logging (elastic#85149) [Security Solution][Case] Manual attach alert to a case (elastic#82996) Loosen UUID regex to accept uuidv1 or uuidv4 (elastic#85338) ... # Conflicts: # x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.helpers.tsx # x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/hot_phase/hot_phase.tsx # x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/shared_fields/index.ts # x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/warm_phase/warm_phase.tsx # x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/edit_policy.tsx # x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/i18n_texts.ts # x-pack/plugins/index_lifecycle_management/server/routes/api/policies/register_create_route.ts
* [Transform] replace legacy elasticsearch client * [Transform] delete custom legacy client definition, update transforms_audit_messages.ts * [Transform] fix start and stop transform endpoints * [Transform] fix privileges and stats endpoints * [Transform] fix forbidden * [Transform] revert continue statement, add a comment * [Transform] update privileges.ts using security namespace * [Transform] fix error wrappers * [Transform] add functional test for preview error validation * [Transform] extract error message from the root cause * [Transform] remove error translation
Summary
Replaces legacy elasticsearch client for server-side routes in transform plugin.