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

Spaces - Migrate to NP Saved Objects Service #58716

Merged
merged 35 commits into from
Apr 3, 2020

Conversation

legrego
Copy link
Member

@legrego legrego commented Feb 27, 2020

Summary

Removes all usages of the legacy saved objects service from the Spaces plugin:

  • Client wrapper registration
  • Saved Object type registration
  • "import"/"export" functionality for Copy to space feature
  • Repository creation for the SpacesClient and create_default_space handler
  • error handling

@legrego legrego changed the title Spaces - use NP saved objects service for type and wrapper registration Spaces - Migrate to NP Saved Objects Service Mar 4, 2020
@legrego
Copy link
Member Author

legrego commented Mar 4, 2020

@elasticmachine merge upstream

@legrego
Copy link
Member Author

legrego commented Mar 5, 2020

@elasticmachine merge upstream

@legrego
Copy link
Member Author

legrego commented Mar 5, 2020

@elasticmachine merge upstream

@legrego
Copy link
Member Author

legrego commented Mar 5, 2020

@elasticmachine merge upstream

@legrego
Copy link
Member Author

legrego commented Mar 5, 2020

@elasticmachine merge upstream

@@ -11,10 +11,12 @@ describe('migrateTo660', () => {
expect(
migrateToKibana660({
id: 'space:foo',
type: 'space',
Copy link
Member Author

Choose a reason for hiding this comment

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

note type property added solely to comply with the type definition

/**
* Returns the maximum number of objects allowed for import or export operations.
*/
getImportExportObjectLimit: () => number;
Copy link
Member Author

Choose a reason for hiding this comment

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

note exposing as part of the start contract for easier consumption by the Spaces plugin. I already need core start services, so it made more sense for me to grab this from here too.

Copy link
Contributor

Choose a reason for hiding this comment

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

I exposed it in the setup contract because that's a value that could be needed from the plugin's setup phase.
We usually don't want to expose APIs in both setup and start methods (even if we do have exceptions to that rule)

Now that's it's done however, I think it is alright, unless someone says otherwise. @rudolf ?

Copy link
Member Author

Choose a reason for hiding this comment

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

We usually don't want to expose APIs in both setup and start methods (even if we do have exceptions to that rule)

Ah, I knew we had several examples in core where we did this, but didn't realize it was an exceptional case, and not a pattern to be repeated. Thanks for the heads-up!

Copy link
Contributor

Choose a reason for hiding this comment

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

In general, we want there to be one way and one way only to do things with Core API's to minimise confusion. This makes sense for API methods that are already bound to a specific lifecycle, but I think we can possibly be less strict with read-only config values.

However in this case I don't think it should impact the code quality a lot, so I'll leave another comment for a suggested way to refactor it.

}
return doc;
}
import { SavedObjectsClientProviderOptions } from 'src/core/server';
Copy link
Member Author

Choose a reason for hiding this comment

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

Bad rename detection by git. This was previously defined in x-pack/plugins/spaces/server/lib/copy_to_spaces/copy_to_spaces.ts, but I extracted it to its own file after for easier sharing between x-pack/plugins/spaces/server/lib/copy_to_spaces/copy_to_spaces.ts and x-pack/plugins/spaces/server/lib/copy_to_spaces/resolve_copy_conflicts.ts

@@ -0,0 +1,43 @@
/*
Copy link
Member Author

Choose a reason for hiding this comment

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

note these functions were split out from x-pack/plugins/spaces/server/routes/api/__fixtures__/create_legacy_api.ts and adjusted accordingly

@@ -0,0 +1,84 @@
/*
Copy link
Member Author

Choose a reason for hiding this comment

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

note this was split out from x-pack/plugins/spaces/server/routes/api/__fixtures__/create_legacy_api.ts and adjusted accordingly

const savedObjectsRepositoryMock = createMockSavedObjectsRepository(spacesSavedObjects);

(exportSavedObjectsToStream as jest.Mock).mockImplementation(
createExportSavedObjectsToStreamMock()
Copy link
Member Author

Choose a reason for hiding this comment

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

note these create*Mock functions are only used here, but I kept their definitions under __fixtures__ in an attempt to make this test suite halfway readable. I can inline them if you think it makes more sense to do so.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the way you have it now is good.


import { deepFreeze } from '../../../../../src/core/utils';

export const SpacesSavedObjectMappings = deepFreeze({
Copy link
Member Author

Choose a reason for hiding this comment

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

We defined this as a json file in the LP, but since NP has actual type definitions, I thought it made sense to convert this to TypeScript. I don't have a super strong opinion about this however.

@legrego legrego added Feature:NP Migration Feature:Security/Spaces Platform Security - Spaces feature release_note:skip Skip the PR/issue when compiling release notes Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v7.7.0 v8.0.0 labels Mar 6, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-security (Team:Security)

@legrego
Copy link
Member Author

legrego commented Mar 24, 2020

@elasticmachine merge upstream

@legrego
Copy link
Member Author

legrego commented Apr 1, 2020

@elasticmachine merge upstream

@legrego
Copy link
Member Author

legrego commented Apr 1, 2020

@elasticmachine merge upstream

@legrego
Copy link
Member Author

legrego commented Apr 2, 2020

@elasticmachine merge upstream

@legrego legrego added v7.8.0 and removed v7.7.0 labels Apr 2, 2020
@legrego legrego requested a review from a team as a code owner April 2, 2020 15:18
@legrego
Copy link
Member Author

legrego commented Apr 2, 2020

@elasticmachine merge upstream

@legrego
Copy link
Member Author

legrego commented Apr 3, 2020

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@legrego legrego merged commit 37c8262 into elastic:master Apr 3, 2020
@legrego legrego deleted the spaces/np-sos branch April 3, 2020 13:50
legrego added a commit to legrego/kibana that referenced this pull request Apr 3, 2020
* use NP saved objects service for type and wrapper registration

* simplifying

* additional testing

* revert snapshot changes

* removing dependency on legacy saved objects service

* consolidate mocks

* fixing imports

* addrress PR feedback

* remove unused docs

* adjust tests for updated corestart contract

* address test flakiness

* address flakiness, part 2

* address test flakiness

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
legrego added a commit that referenced this pull request Apr 3, 2020
* use NP saved objects service for type and wrapper registration

* simplifying

* additional testing

* revert snapshot changes

* removing dependency on legacy saved objects service

* consolidate mocks

* fixing imports

* addrress PR feedback

* remove unused docs

* adjust tests for updated corestart contract

* address test flakiness

* address flakiness, part 2

* address test flakiness

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:NP Migration Feature:Security/Spaces Platform Security - Spaces feature release_note:skip Skip the PR/issue when compiling release notes Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v7.8.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants