-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
Conversation
d69332a
to
c011ef9
Compare
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@@ -11,10 +11,12 @@ describe('migrateTo660', () => { | |||
expect( | |||
migrateToKibana660({ | |||
id: 'space:foo', | |||
type: 'space', |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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 @@ | |||
/* |
There was a problem hiding this comment.
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 @@ | |||
/* |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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({ |
There was a problem hiding this comment.
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.
Pinging @elastic/kibana-security (Team:Security) |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
* 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>
* 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>
Summary
Removes all usages of the legacy saved objects service from the Spaces plugin:
SpacesClient
andcreate_default_space
handler