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

[Painless Lab] NP migration #59794

Merged
merged 8 commits into from
Mar 13, 2020

Conversation

alisonelizabeth
Copy link
Contributor

@alisonelizabeth alisonelizabeth commented Mar 10, 2020

This PR moves the painless lab plugin over to the new platform.

How to test

I'm not as familiar with this app as others might be, so please in general verify the app still behaves as it did prior to the migration.

  • Confirm painless scripts execute as expected
  • Verify "Painless Lab" appears in the Kibana plugins directory on the home page
  • Verify setting xpack.painless_lab.enabled: false disables the app
  • Verify SCSS still working as expected

Note: The license handling logic was brought over from Seb's implementation in index_management.

@alisonelizabeth alisonelizabeth added painless painless 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 labels Mar 10, 2020
@elasticmachine
Copy link
Contributor

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

) as any,
enableRouting: false,
disabled: false,
// tooltipContent: xpackInfo.get('features.painlessLab.message'),
Copy link
Contributor Author

@alisonelizabeth alisonelizabeth Mar 10, 2020

Choose a reason for hiding this comment

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

I'm not sure what this is for or how to test (I brought this over from the previous code). @jloleysens or @cjcenizal - any ideas?

Copy link
Contributor

Choose a reason for hiding this comment

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

iirc, that value would come from x-pack/legacy/plugins/painless_lab/server/lib/check_license.ts L16 as a way of informing the user that Painless Lab is not available due to a license issue.

To get parity we would need to subscribe to license$ and check the license value. We can update the UI in some other perhaps (like disabling the editors) if the ES cluster is not running min. basic license. Perhaps something to do in a follow up PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see. I'm going to delete this for now.

Currently, the app is redirecting back to /dev-tools if the license is invalid. This is current functionality that I brought over. It looks like this was originally copied over from grokdebugger, as I see it is doing the same thing.

@alisonelizabeth alisonelizabeth marked this pull request as ready for review March 10, 2020 19:01
@alisonelizabeth alisonelizabeth requested a review from a team as a code owner March 10, 2020 19:01
Copy link
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

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

Great work @alisonelizabeth ! Happy to see this tech debt addressed 🙂

Left some non-blocker comments.

) as any,
enableRouting: false,
disabled: false,
// tooltipContent: xpackInfo.get('features.painlessLab.message'),
Copy link
Contributor

Choose a reason for hiding this comment

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

iirc, that value would come from x-pack/legacy/plugins/painless_lab/server/lib/check_license.ts L16 as a way of informing the user that Painless Lab is not available due to a license issue.

To get parity we would need to subscribe to license$ and check the license value. We can update the UI in some other perhaps (like disabling the editors) if the ES cluster is not running min. basic license. Perhaps something to do in a follow up PR.

},
},
license.guardApiRoute(async (ctx, req, res) => {
const body = req.body as typeof bodySchema.type;
Copy link
Contributor

Choose a reason for hiding this comment

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

I've also run into this 😄. The higher order function (in this case license.guardApiRoute) needs to accept the three RequestHandler generic params <P, Q, B> and pass them through to its own handler and request object.

Like here:

We can also review this down the line.

export const PLUGIN = {
id: 'painlessLab',
minimumLicenseType: basicLicense,
getI18nName: (i18n: any): string =>
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't see where this is being used?

@jloleysens jloleysens self-requested a review March 11, 2020 10:13
Copy link
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

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

After running locally I noticed something I missed in my initial review. It looks like the error response is not being handled as before if invalid Painless is submitted. It now only says Bad Request.

Screenshot 2020-03-11 at 11 12 55

Before it would print out a nice error message giving some more context about what exactly went wrong.

Would you mind looking into this here?

@alisonelizabeth
Copy link
Contributor Author

@jloleysens I addressed your feedback and fixed the issue when a user submits an invalid painless script (great catch btw!). The UI is actually expecting a 200 in this scenario (related code). Mind taking another look?

Copy link
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

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

@alisonelizabeth Thanks for addressing the feedback!

Left one more non-blocker comment, I'll leave that one up to you 👍

Comment on lines 40 to 49
// Invalid painless script was submitted
// Return 200 with error object
if (e.body) {
return res.ok({
body: e.body,
});
}

if (isEsError(e)) {
return res.customError({ statusCode: e.statusCode, body: e });
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm just wondering whether we can't collapse this section into this if check:

	// Invalid painless script was submitted
        // Return 200 with error object
        if (isEsError(e)) {
          return res.ok({ body: e.body });
        }

I'm guessing if we detect an ES error here it means that something went wrong with the call to painless script execution endpoint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a valid point! Fixed.

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.

Thanks so much for doing this, Alison! I tested locally and everything looks great except for one bug I found. Let me know if you'd like help working through it.


const bodySchema = schema.object({
script: schema.object({
source: schema.string(),
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll need to update this schema to support the other parameters that will be provided if the user specifies "Parameters" or the other options provided by the other "Context" choices. For example, if you specify "Parameters" as in the screenshot below the request fails because it's invalidated by this schema:

image

schema.object({
params: schema.maybe(schema.any()),
document: schema.recordOf(schema.string(), schema.any()),
index: schema.string(),
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 made this required, since it looks like ES requires it, but I also opened #60020 as a follow-up.

@alisonelizabeth
Copy link
Contributor Author

@cjcenizal great catch! I have updated the schema, would you mind taking another look and testing again? I've confirmed adding params is working as expected now. I've tried to test changing the context, but my browser keeps freezing up (using this example). I tested on the feature branch as well and experience the same behavior, so I don't think it's related to this PR. Have you run into this before?

I also noticed a couple other issues:

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@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, looks great! Thanks @alisonelizabeth. I created #60146 to track the bug you were experiencing since I can verify it also exists on the feature branch.

@alisonelizabeth alisonelizabeth merged commit d33a82b into elastic:app/painless Mar 13, 2020
@alisonelizabeth alisonelizabeth deleted the painless/np branch March 13, 2020 20:01
@cjcenizal cjcenizal mentioned this pull request Mar 13, 2020
13 tasks
cjcenizal added a commit that referenced this pull request Mar 23, 2020
* Create Painless Playground app (#54578)

* Replace heart script with smiley face script. (#57755)

* Rename Painless Playground -> Painless Lab. (#57545)

* Fix i18n namespace.

* Improve smiley face proportions.
- Add def keyword to Painless spec.
- Temporarily fix broken highlighting.
- Add small padding to main controls.

* [Painless Lab] Minor Fixes (#58135)

* Code restructure, improve types, add plugin id, introduced hook

Moved the code execution hook to a custom hook outside of main,
also chaining off promise to avoid lower level handling of
sequencing.

* Re-instated formatting code

To improve DX the execution error response from the painless API
was massaged to a more reader friendly state, only giving non-repeating
information.

Currently it is hard to determine the line and character information from
the painless endpoint. If the user wishes to see this raw information it
will be available in the API response flyout.

* Remove leading new line in default script

* Remove registration of feature flag

* Fix types

* Restore previous auto-submit request behaviour

* Remove use of null and remove old comment

Stick with "undefined" as the designation for something not existing.

* [Painless Lab] NP migration (#59794)

* Fix sample document editor.

* [Painless Lab] Fix float -> integer coercion bug (#60201)

* Clarify data and persistence flow. Fix floating point precision bug.
* Send a string to API and ES client instead of an object.

* Rename helpers lib to format. Add tests for formatRequestPayload.

* Add query parameter to score context (#60414)

* Fix typo and i18n

* Make state init lazy

Otherwise we are needlessly reading and JSON.parse'ing on every
state update

* Support the query parameter in requests to Painless

* Fix borked i18n

* Fix i18n

* Another i18n issue

* [Painless] Minor state update model refactor (#60532)

* Fix typo and i18n

* Make state init lazy

Otherwise we are needlessly reading and JSON.parse'ing on every
state update

* Support the query parameter in requests to Painless

* WiP on state refactor

* Some cleanup after manual testing

* Fix types and i18n

* Fix i18n in context_tab

* i18n

* [Painless] Language Service (#60612)

* Added language service

* Use the correct monaco instance and add wordwise operations

* Remove plugin context initializer for now

* [Painless] Replace hard-coded links (#60603)

* Replace hard-coded links

Also remove all props from Main component

* Pass the new links object to the request flyout too

* Link directly to painless execute API's contexts

* Remove responsive stacking from tabs with icons in them.

* Resize Painless Lab bottom bar to accommodate nav drawer width (#60833)

* Validate Painless Lab index field (#60841)

* Make JSON format of parameters field more prominent. Set default parameters to provide an example to users.
* Set default document to provide an example to users.
* Simplify context's updateState interface.
* Refactor store and context file organization.
  - Remove common directory, move constants and types files to root.
  - Move initialState into context file, where it's being used.
* Add validation for index input.
* Create context directory.

* Fix bottom bar z-index.

* Position flyout help link so it's bottom-aligned with the title and farther from the close button.

Co-authored-by: Matthias Wilhelm <[email protected]>
Co-authored-by: Jean-Louis Leysens <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: Alison Goryachev <[email protected]>
@cjcenizal cjcenizal added the Feature:Painless Lab Dev tool for learning Painless label Mar 23, 2020
cjcenizal added a commit that referenced this pull request Mar 24, 2020
* Create Painless Playground app (#54578)

* Replace heart script with smiley face script. (#57755)

* Rename Painless Playground -> Painless Lab. (#57545)

* Fix i18n namespace.

* Improve smiley face proportions.
- Add def keyword to Painless spec.
- Temporarily fix broken highlighting.
- Add small padding to main controls.

* [Painless Lab] Minor Fixes (#58135)

* Code restructure, improve types, add plugin id, introduced hook

Moved the code execution hook to a custom hook outside of main,
also chaining off promise to avoid lower level handling of
sequencing.

* Re-instated formatting code

To improve DX the execution error response from the painless API
was massaged to a more reader friendly state, only giving non-repeating
information.

Currently it is hard to determine the line and character information from
the painless endpoint. If the user wishes to see this raw information it
will be available in the API response flyout.

* Remove leading new line in default script

* Remove registration of feature flag

* Fix types

* Restore previous auto-submit request behaviour

* Remove use of null and remove old comment

Stick with "undefined" as the designation for something not existing.

* [Painless Lab] NP migration (#59794)

* Fix sample document editor.

* [Painless Lab] Fix float -> integer coercion bug (#60201)

* Clarify data and persistence flow. Fix floating point precision bug.
* Send a string to API and ES client instead of an object.

* Rename helpers lib to format. Add tests for formatRequestPayload.

* Add query parameter to score context (#60414)

* Fix typo and i18n

* Make state init lazy

Otherwise we are needlessly reading and JSON.parse'ing on every
state update

* Support the query parameter in requests to Painless

* Fix borked i18n

* Fix i18n

* Another i18n issue

* [Painless] Minor state update model refactor (#60532)

* Fix typo and i18n

* Make state init lazy

Otherwise we are needlessly reading and JSON.parse'ing on every
state update

* Support the query parameter in requests to Painless

* WiP on state refactor

* Some cleanup after manual testing

* Fix types and i18n

* Fix i18n in context_tab

* i18n

* [Painless] Language Service (#60612)

* Added language service

* Use the correct monaco instance and add wordwise operations

* Remove plugin context initializer for now

* [Painless] Replace hard-coded links (#60603)

* Replace hard-coded links

Also remove all props from Main component

* Pass the new links object to the request flyout too

* Link directly to painless execute API's contexts

* Remove responsive stacking from tabs with icons in them.

* Resize Painless Lab bottom bar to accommodate nav drawer width (#60833)

* Validate Painless Lab index field (#60841)

* Make JSON format of parameters field more prominent. Set default parameters to provide an example to users.
* Set default document to provide an example to users.
* Simplify context's updateState interface.
* Refactor store and context file organization.
  - Remove common directory, move constants and types files to root.
  - Move initialState into context file, where it's being used.
* Add validation for index input.
* Create context directory.

* Fix bottom bar z-index.

* Position flyout help link so it's bottom-aligned with the title and farther from the close button.

Co-authored-by: Matthias Wilhelm <[email protected]>
Co-authored-by: Jean-Louis Leysens <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: Alison Goryachev <[email protected]>

Co-authored-by: Matthias Wilhelm <[email protected]>
Co-authored-by: Jean-Louis Leysens <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: Alison Goryachev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Painless Lab Dev tool for learning Painless painless painless 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants