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

[Transform] Replace legacy elasticsearch client #84932

Merged
merged 15 commits into from
Dec 9, 2020

Conversation

darnautov
Copy link
Contributor

@darnautov darnautov commented Dec 3, 2020

Summary

Replaces legacy elasticsearch client for server-side routes in transform plugin.

@darnautov darnautov added :ml v8.0.0 release_note:skip Skip the PR/issue when compiling release notes Feature:Transforms ML transforms v7.11.0 labels Dec 3, 2020
@darnautov darnautov self-assigned this Dec 3, 2020
@darnautov darnautov requested a review from a team as a code owner December 3, 2020 18:17
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

cluster,
} = await ctx.transform!.dataClient.callAsCurrentUser('transport.request', {
body: { has_all_requested: hasAllPrivileges, cluster },
} = await ctx.core.elasticsearch.client.asCurrentUser.transport.request({
Copy link
Member

Choose a reason for hiding this comment

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

I think this should use hasPrivileges from the security namespace.
ctx.core.elasticsearch.client.asCurrentUser.security.hasPrivileges

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 4e44a09

const { indices } = await ctx.transform!.dataClient.callAsCurrentUser('transport.request', {
const {
body: { indices },
} = await ctx.core.elasticsearch.client.asCurrentUser.transport.request({
Copy link
Member

Choose a reason for hiding this comment

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

same as above comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 4e44a09

@@ -83,14 +78,13 @@ export function registerTransformsRoutes(routeDependencies: RouteDependencies) {
*/
router.get(
{ path: addBasePath('transforms'), validate: false },
license.guardApiRoute(async (ctx, req, res) => {
const options = {};
license.guardApiRoute<TransformGetTransform, undefined, undefined>(async (ctx, req, res) => {
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

but this suggested change just a refactor for simplifying the code, and is not important for the functionality.

@@ -569,14 +558,16 @@ const startTransformsHandler: RequestHandler<

async function startTransforms(
transformsInfo: StartTransformsRequestSchema,
callAsCurrentUser: LegacyAPICaller
esClient: ElasticsearchClient
Copy link
Member

Choose a reason for hiding this comment

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

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,
Copy link
Member

@jgowdyelastic jgowdyelastic Dec 8, 2020

Choose a reason for hiding this comment

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

the previous version wouldn't send the transform ID if it was undefined, this now always sends one.
is this change intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, this route has this validation schema

export const transformIdParamSchema = schema.object({
, hence this check is redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also covered by API integration tests and checked manually

Copy link
Member

@jgowdyelastic jgowdyelastic left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

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

Tested and the only issue I found was around error handling, where some of the error details previously shown are getting lost.

x-pack/plugins/transform/server/routes/api/error_utils.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@walterra walterra left a comment

Choose a reason for hiding this comment

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

Great update, LGTM 👍

if (line !== undefined && col !== undefined) {
message +=
', ' +
i18n.translate('xpack.transform.models.transformService.withColAndLineMessage', {
Copy link
Member

Choose a reason for hiding this comment

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

we don't format error messages on the server side.
This will be appended onto an error which will be in english.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed error translation in 307252b

/**
* Returns an error message based on the root cause
*/
function extractErrorMessage({ type, reason, line, col }: EsError): string {
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

@walterra walterra Dec 9, 2020

Choose a reason for hiding this comment

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

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)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

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

Tested latest edits and LGTM

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Distributable file count

id before after diff
default 46960 47719 +759

History

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

@darnautov darnautov merged commit 58fc711 into elastic:master Dec 9, 2020
@darnautov darnautov deleted the transform-new-es-client branch December 9, 2020 11:55
darnautov added a commit to darnautov/kibana that referenced this pull request Dec 9, 2020
* [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
jloleysens added a commit to jloleysens/kibana that referenced this pull request Dec 9, 2020
…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
darnautov added a commit that referenced this pull request Dec 9, 2020
* [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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Transforms ML transforms :ml release_note:skip Skip the PR/issue when compiling release notes v7.11.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants