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

[SOM] Preserve saved object references when saving the object #66584

Merged

Conversation

pgayvallet
Copy link
Contributor

Summary

Fix #66542

Fix a bug causing the edition of a saved objects from the management section to removes all its references, resulting in a corrupted object.

@pgayvallet pgayvallet added release_note:fix Feature:Saved Objects Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc labels May 14, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

@pgayvallet pgayvallet added the Feature:Kibana Management Feature label for Data Views, Advanced Setting, Saved Object management pages label May 14, 2020
@pgayvallet pgayvallet changed the title create field for references and add comments [SOM] Preserve saved object references when saving the object May 14, 2020
Comment on lines +38 to +39
// Special handling for references which isn't within "attributes"
fields = [...fields, ...createFields('references', object.references)];
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 was missed when migrating from legacy.

Ideally, we would create fields with full path instead of assuming all fields are in attributes to avoid that kind of hack (that would break for example if a given editable SO type had a references attributes), but this is outside of the scope of this mere fix.

Comment on lines +43 to +47
return browser.execute(
(editor: string, value: string) => {
return (window as any).ace.edit(editor).setValue(value);
},
editorId,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using the ace API from the browser side instead of performing 'real' user interactions is far from ideal, however as ace autocompletes user input (for example, user type [, ace automatically adds the closing ]), it was just over complicated to use focus + sendKeys, so this will have to be good enough.

Same things with getAceEditorFieldValue: parsing the text content from the ace editor structure is a pain.

@@ -99,5 +121,48 @@ export default function({ getPageObjects, getService }: FtrProviderContext) {
const objects = await PageObjects.settings.getSavedObjectsInTable();
expect(objects.includes('A Dashboard')).to.be(false);
});

it('preserves the object references when saving', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

testing that references are properly displayed and preserved during save, then testing that updating the references actually works.

@pgayvallet pgayvallet marked this pull request as ready for review May 14, 2020 20:17
@pgayvallet pgayvallet requested a review from a team as a code owner May 14, 2020 20:17
Copy link
Contributor

@joshdover joshdover 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 and it worked! Few nits / questions on test, but otherwise LGTM

Comment on lines 150 to 152
expect(JSON.parse(await getAceEditorFieldValue('references'))).to.eql(
JSON.parse(referencesValue)
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we just parsing to ensure that key order doesn't effect the test outcome? Might be good to comment as such.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct assumption. We were getting the key in arbitrary order here.

Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately this check doesn't prevent again this regression. The references text was rendered already as an empty array before this patch, clicking saving and checking the results will not discover if we are facing this issue again.
IMHO I think it's better to check, if possible, the presence of the references array directly on the saved object from ES, or somewhere else on the UI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if possible, the presence of the references array directly on the saved object from ES, or somewhere else on the UI

  • from ES: Unfortunately this is not possible from an e2e test.
  • somewhere else on the UI: AFAIK we are not displaying references anywhere expect in the SOM edition page.

As we control the source data for the test however, I can assert that the displayed relations matches the references from the dataset.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dataset/assertion modified in d453272

Comment on lines 129 to 133
await PageObjects.settings.navigateTo();
await PageObjects.settings.clickKibanaSavedObjects();

let objects = await PageObjects.settings.getSavedObjectsInTable();
expect(objects.includes('A Pie')).to.be(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

These steps don't seem necessary for this test?

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 was mostly to insert webdriver implicit timing to wait for the listing page.

I will replace this with just await PageObjects.settings.getSavedObjectsInTable()

Comment on lines 158 to 159
objects = await PageObjects.settings.getSavedObjectsInTable();
expect(objects.includes('A Pie')).to.be(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to do this again?

Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

I've left a comment on the functional test, we should probably revisit it to avoid this regression again in the future

Comment on lines 150 to 152
expect(JSON.parse(await getAceEditorFieldValue('references'))).to.eql(
JSON.parse(referencesValue)
);
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately this check doesn't prevent again this regression. The references text was rendered already as an empty array before this patch, clicking saving and checking the results will not discover if we are facing this issue again.
IMHO I think it's better to check, if possible, the presence of the references array directly on the saved object from ES, or somewhere else on the UI

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@pgayvallet pgayvallet merged commit 61936a1 into elastic:master May 16, 2020
pgayvallet added a commit to pgayvallet/kibana that referenced this pull request May 16, 2020
…c#66584)

* create field for references and add comments

* add FTR test

* remove comments

* address comments

* use real reference in dataset and assert against it.
pgayvallet added a commit to pgayvallet/kibana that referenced this pull request May 16, 2020
…c#66584)

* create field for references and add comments

* add FTR test

* remove comments

* address comments

* use real reference in dataset and assert against it.
pgayvallet added a commit to pgayvallet/kibana that referenced this pull request May 16, 2020
…c#66584)

* create field for references and add comments

* add FTR test

* remove comments

* address comments

* use real reference in dataset and assert against it.
# Conflicts:
#	src/plugins/saved_objects_management/public/lib/create_field_list.test.ts
#	src/plugins/saved_objects_management/public/lib/create_field_list.ts
#	src/plugins/saved_objects_management/public/management_section/object_view/components/field.tsx
#	src/plugins/saved_objects_management/public/management_section/object_view/components/form.tsx
pgayvallet added a commit that referenced this pull request May 17, 2020
#66843)

* create field for references and add comments

* add FTR test

* remove comments

* address comments

* use real reference in dataset and assert against it.
pgayvallet added a commit that referenced this pull request May 17, 2020
#66844)

* create field for references and add comments

* add FTR test

* remove comments

* address comments

* use real reference in dataset and assert against it.
pgayvallet added a commit that referenced this pull request May 17, 2020
#66845)

* create field for references and add comments

* add FTR test

* remove comments

* address comments

* use real reference in dataset and assert against it.
# Conflicts:
#	src/plugins/saved_objects_management/public/lib/create_field_list.test.ts
#	src/plugins/saved_objects_management/public/lib/create_field_list.ts
#	src/plugins/saved_objects_management/public/management_section/object_view/components/field.tsx
#	src/plugins/saved_objects_management/public/management_section/object_view/components/form.tsx
jloleysens added a commit that referenced this pull request May 18, 2020
…ine-editor

* 'master' of github.com:elastic/kibana: (157 commits)
  [ML] fix url assertion (#66850)
  Skip failing lens test(s). #66779
  [SOM] Preserve saved object references when saving the object (#66584)
  Use ES API from start contract (#66157)
  Reorganize Management apps into Ingest, Data, Alerts and Insights, Security, Kibana, and Stack groups (#65796)
  [Uptime] Fix flaky navigation to certs page in tests (#66806)
  [Maps] Do not check count for blended layers when layer is not visible (#66460)
  [SIEM] Fixes glob patterns from directory changes recently for GraphQL
  chore(NA): bump static-fs to 1.0.2 (#66775)
  [Maps] Handle cross cluster index _settings resp (#66797)
  [SIEM][Lists] Adds 90% of the REST API and client API for exception lists and exception items
  allow any type for customResponseHeaders config (#66689)
  [APM] Disable map layout animation (#66763)
  [ML] Add linking to dataframe from job management tab (#65778)
  [Maps] Get number of categories from palette (#66454)
  move oss features registration to KP (#66524)
  [kbn/plugin-helpers] typescript-ify (#66513)
  Add kibana-operations as codeowners for .ci/es-snapshots and vars/ (#66746)
  FTR: move basic services under common folder (#66563)
  Migrate Beats Management UI to KP (#65791)
  ...

# Conflicts:
#	x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form.tsx
#	x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form_fields.tsx
gmmorris added a commit to gmmorris/kibana that referenced this pull request May 18, 2020
* master:
  [ML] fix url assertion (elastic#66850)
  Skip failing lens test(s). elastic#66779
  [SOM] Preserve saved object references when saving the object (elastic#66584)
  Use ES API from start contract (elastic#66157)
  Reorganize Management apps into Ingest, Data, Alerts and Insights, Security, Kibana, and Stack groups (elastic#65796)
  [Uptime] Fix flaky navigation to certs page in tests (elastic#66806)
  [Maps] Do not check count for blended layers when layer is not visible (elastic#66460)
  [SIEM] Fixes glob patterns from directory changes recently for GraphQL
  chore(NA): bump static-fs to 1.0.2 (elastic#66775)
  [Maps] Handle cross cluster index _settings resp (elastic#66797)
  [SIEM][Lists] Adds 90% of the REST API and client API for exception lists and exception items
  allow any type for customResponseHeaders config (elastic#66689)
  [APM] Disable map layout animation (elastic#66763)
  [ML] Add linking to dataframe from job management tab (elastic#65778)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Kibana Management Feature label for Data Views, Advanced Setting, Saved Object management pages Feature:Saved Objects release_note:fix Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.7.1 v7.8.0 v7.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Editing a saved object from Management UI can corrupt the saved object
5 participants