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

[Runtime fields] Add support in index template #84184

Merged
merged 41 commits into from Dec 3, 2020

Conversation

sebelga
Copy link
Contributor

@sebelga sebelga commented Nov 24, 2020

This PR integrates the runtime field editor (from the runtimeFields x-pack plugin) into the mappings editor (index_management x-pack plugin). As the mappings editor is integrated into composable index template, legacy index template, and component template wizard, the runtime section of the mappings is automatically supported in those three resources.

Note: I removed the release note from #79940 and added it here.

Screenshot 2020-11-26 at 13 58 52

Screenshot 2020-11-26 at 14 16 33

Screenshot 2020-11-26 at 14 07 39

Notes for code reviewers

How to test

  • Navigate to the index management app
  • Click on the index template tab and then "Create template" button
  • Enter a name and an index pattern in the "Logistics" step
  • Navigate to the mappings step. There should be a "Runtime fields" tab
  • Click on the "Runtime fields" tab. There should be an empty prompt with a button to create a runtime field
    Note: There should be a "Learn more" link. I asked for the link to the docs team and pointed it correctly. It does not work yet as the docs are not deployed yet. cc @DocTeam
  • Click the "Create a runtime field" button. The editor should open
  • Give a name to the field (e.g. "myField") and a type. For the script emit a test value: emit("test")
  • Click "Save". The field should appear in the list.
  • You should be able to edit and delete the field.

Shadowing mapped field

  • Navigate to the "Mapped fields" tab and create a field (e.g. with name "mappedField")
  • Navigate to the "Runtime fields" tab and click "Add field".
  • Give the same name to the field as the mapped field. A callout should appear indicating that it will shadow the mapped field
  • Proceed anyway. Add any script and click "Save"
  • The field should appear in the list.
  • Navigate to the "Mapped fields". The mapped field should have a "shadowed" badge on it with a tooltip

Prevent duplicated runtime field

  • Navigate to the "Runtime fields" tab and click "Add field" button
  • Give the same name as one of the existing runtime fields (e.g. "myField" from the first example)
  • There should be a validation error indicating that a field with the same name already exists

Handling ES error

As part of this PR I fixed #77165 which was required to help the user better understand possible errors in the runtime script when saving the template. For that, I created an es_error_parser.ts reusable handler in our "es_ui_shared/server" folder.

Tests

I added all the necessary component integration tests for the support of the runtime tab in the mappings. I also updated the API integration tests to verify that the es_error_parser correctly wraps the returned error from our endpoint.

Copy review

  • Empty prompt

Screenshot 2020-12-02 at 14 15 23

  • Field shadowed

If a runtime field has the same name as a mapped field, a "shadowed" badge appears with a tooltip.

Screenshot 2020-11-26 at 13 59 41

In the runtime field editor, a callout indicates that this field is shadowing a mapped field.

Screenshot 2020-11-26 at 14 00 41

  • Tag line

When there are 1 or more fields, there is a tagline on top with a "Learn more" link.

Screenshot 2020-11-26 at 14 12 19

Release note

Index templates and component templates can now be configured with runtime fields in their mappings.

Fixes #77165

@sebelga
Copy link
Contributor Author

sebelga commented Nov 30, 2020

Thanks for the review @jloleysens ! I will wait on a review from the @esdocs team before merging 👍

@cjcenizal cjcenizal added Feature:Index Management Index and index templates UI Feature:Mappings Editor Index mappings editor UI labels Nov 30, 2020
@sebelga
Copy link
Contributor Author

sebelga commented Dec 2, 2020

@elasticmachine merge upstream

Copy link
Contributor

@lockewritesdocs lockewritesdocs left a comment

Choose a reason for hiding this comment

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

Overall, looks really good! I left some suggested changes for wording, and also think we can provide more targeted URLs in a few spots. I left a comment about error handling when a script isn't provided and tagged Luca for his input.

{
validator: emptyField(
i18n.translate('xpack.runtimeFields.form.validations.scriptIsRequiredErrorMessage', {
defaultMessage: 'Script must emit() a value.',
Copy link
Contributor

Choose a reason for hiding this comment

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

@sebelga, a script is no longer required to create a runtime field since @romseygeek merged 64981. I believe the script is still the preferred way, so perhaps we want users to create a script. But throwing in an error that forces users to create a script - when they don't have to - seems incorrect.

cc: @javanna to get his input on how we want to handle this situation.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch 👍 I will add an (optional) to the label and let the user save the field without a script.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2020-12-03 at 10 29 14

Copy link
Member

Choose a reason for hiding this comment

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

sorry for being late, maybe users will wonder what the runtime field will do when a script is not defined, it may be worth to include that in the UI

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch Luca. I created a PR to add text that explains this behavior: #85204

<EuiSpacer size="l" />

{/* Script */}
<UseField<string> path="script">
<UseField<string> path="script.source">
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a comment about links.painlessSyntax on line 229, which just goes to the main page for the Painless guide. I don't think that information is particularly useful in this context. Instead, we could link to the section for Mapping a runtime field, which provides users information about writing a Painless script in the context of a runtime field.

I believe the resulting URL would be: https://www.elastic.co/guide/en/elasticsearch/reference/master/runtime.html#runtime-mapping-fields

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is great idea! I will change the link 👍

@sebelga
Copy link
Contributor Author

sebelga commented Dec 3, 2020

Thanks for the review @lockewritesdocs ! I've committed your change suggestions and made the suggested change. Thanks for pointing out that the script is now optional! 👍

Can you have another look? Cheers!

Copy link
Contributor

@lockewritesdocs lockewritesdocs left a comment

Choose a reason for hiding this comment

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

👏 Looks great @sebelga! I built locally and tested. Thanks for integrating these changes.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
indexManagement 512 514 +2

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
indexManagement 1.5MB 1.5MB +12.0KB

Distributable file count

id before after diff
default 43460 43461 +1
oss 22744 22745 +1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
esUiShared 278.1KB 278.2KB +99.0B
indexManagement 114.2KB 114.4KB +161.0B
runtimeFields 24.2KB 29.8KB +5.6KB
total +5.8KB

History

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Index Management Index and index templates UI Feature:Mappings Editor Index mappings editor UI Project:RuntimeFields release_note:enhancement Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.11.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Revisit how we return ES error in the <SectionError />
7 participants