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

Partially move server-side savedObjects domain implementation to packages #137448

Merged

Conversation

pgayvallet
Copy link
Contributor

@pgayvallet pgayvallet commented Jul 28, 2022

Summary

First part of third stage (yea, I know, hopefully the next one with be the last) of #135820

Now that all the server-side savedObjects public types have been moved to packages, we can start moving the internal implementation.

Unsurprisingly, this is probably the biggest Core domain in term of files, and will be the same in term of number of packages.

From my initial investigation, I'm currently planning on having the following packages (removed the ``@kbn/core-saved-objects` prefix here):

  • @kbn/core-saved-objects-utils-server
    • the public concrete static code that is exposed to external consumers
      • SavedObjectsUtils
      • SavedObjectsErrorHelper
      • some other misc stuff
  • @kbn/core-saved-objects-base-internal
    • the common bits of the implementation that are shared between the other internal packages
      • mappings
      • serialization
      • validation
      • version
      • type registry
      • legacy aliases
      • config (could have only put the config types here, but for the sake of simplicity the schemas were moved too)
  • @kbn/core-saved-objects-api-internal (depends on base)
    • the SOR and SOC implementations
  • @kbn/core-saved-objects-import-export-internal (depends on base and api)
    • the importer/exporter implementations
  • @kbn/core-saved-objects-migration-internal (depends on base and api)
    • all the SO migration code
  • @kbn/core-saved-objects-internal (depends on all the others)
    • SO service
    • registered routes
  • the associated mock packages

This PR is the first step, handling the creation of and code extraction to the following packages:

  • @kbn/core-saved-objects-utils-server
  • @kbn/core-saved-objects-base-server-internal
  • @kbn/core-saved-objects-base-server-mocks

NOTE: I did not look yet at the problem of the cyclic dependency with types of CoreUsageData. This only impacts the higher-level internal package, @kbn/core-saved-objects-internal, and I will take a look when the time comes

@pgayvallet pgayvallet added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc release_note:skip Skip the PR/issue when compiling release notes v8.5.0 labels Jul 28, 2022
@pgayvallet pgayvallet force-pushed the kbn-135820-so-implementation-stage-1 branch from f4a2c19 to 95837c8 Compare July 29, 2022 06:45
Copy link
Contributor Author

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

Self-review

Comment on lines +15 to +30
const createMockedTypeRegistry = ({
isNamespaceAgnostic,
isSingleNamespace,
isMultiNamespace,
}: {
isNamespaceAgnostic: boolean;
isSingleNamespace: boolean;
isMultiNamespace: boolean;
}): ISavedObjectTypeRegistry => {
const typeRegistry: Partial<ISavedObjectTypeRegistry> = {
isNamespaceAgnostic: jest.fn().mockReturnValue(isNamespaceAgnostic),
isSingleNamespace: jest.fn().mockReturnValue(isSingleNamespace),
isMultiNamespace: jest.fn().mockReturnValue(isMultiNamespace),
};
return typeRegistry as ISavedObjectTypeRegistry;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only test of the @kbn/core-saved-objects-base-server-internal that was using a mock from code that was moved to this package. I KISS'ed and created an inline mock helper.

The alternative would have been to create 2 additional packages (impl+mock) just for the SO type registry, and it didn't feel worth it.

Comment on lines +11 to +20
const createSerializerMock = () => {
const mock: jest.Mocked<ISavedObjectsSerializer> = {
isRawSavedObject: jest.fn(),
rawToSavedObject: jest.fn(),
savedObjectToRaw: jest.fn(),
generateRawId: jest.fn(),
generateRawLegacyUrlAliasId: jest.fn(),
};
return mock;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As we didn't have one yet, I introduced a mock for ISavedObjectsSerializer.

Comment on lines +13 to +16
ALL_NAMESPACES_STRING,
DEFAULT_NAMESPACE_STRING,
FIND_DEFAULT_PAGE,
FIND_DEFAULT_PER_PAGE,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These constants are in practice only used internally by Core, but they are also used by the SavedObjectsUtils implementation that is publicly exposed. To avoid duplicating them, I exposed them from the public util package, as it didn't felt like it would be causing any harm for them to be publicly accessible.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds reasonable to me.

SavedObjectsUtils,
mergeSavedObjectMigrationMaps,
} from './saved_objects';
export { SavedObjectsClient } from './saved_objects';
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 need to check if we still need to export SavedObjectsClient and SavedObjectTypeRegistry from the entrypoint, but this will be done in the next PR or in the follow-up cleanup.

export {
SavedObjectsClient,
SavedObjectsErrorHelpers,
SavedObjectsSerializer,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Last external usage of SavedObjectsSerializer have been removed and replaced by the newly introduced mock. It's no longer publicly exposed.

@pgayvallet pgayvallet marked this pull request as ready for review July 29, 2022 13:22
@pgayvallet pgayvallet requested a review from a team as a code owner July 29, 2022 13:22
@pgayvallet pgayvallet requested review from a team as code owners July 29, 2022 13:22
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

Copy link
Member

@pmuellr pmuellr left a comment

Choose a reason for hiding this comment

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

ResponseOps changes LGTM

@TinaHeiligers
Copy link
Contributor

@elasticmachine merge upstream

@TinaHeiligers
Copy link
Contributor

@pgayvallet I tried to help but seemed to have done the opposite 😨 . Sorry 'bout that!

Attempt to undo an incorrect merge.
@TinaHeiligers
Copy link
Contributor

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

merge conflict between base and head

Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

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

LGTM thus far without aby obvious changes needed.

"name": "@kbn/core-saved-objects-utils-server",
"private": true,
"version": "1.0.0",
"main": "./target_node/index.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to add Core as the author here and in the other packages as per recent changes. That being said, I wonde rif there's a way to share package ownership between teams, since the code in here is mostly related to the security wrappers.

@kibana-operations, is there a plan to reflect code-ownership in packages or do we rely on the CODEOWNER's file?

* Side Public License, v 1.
*/

export { mergeSavedObjectMigrationMaps } from './merge_migration_maps';
Copy link
Contributor

Choose a reason for hiding this comment

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

With recent changes to the build tooling, this and all the other src/index.ts files need to move to the package's root. See #138476 for more info.

Comment on lines +13 to +16
ALL_NAMESPACES_STRING,
DEFAULT_NAMESPACE_STRING,
FIND_DEFAULT_PAGE,
FIND_DEFAULT_PER_PAGE,
Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds reasonable to me.

PKG_DIRNAME = "core-saved-objects-utils-server"
PKG_REQUIRE_NAME = "@kbn/core-saved-objects-utils-server"

SOURCE_FILES = glob(
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 not sure if there's tooling to make changes required by #138476 after a package is created, so we may need to update the bazel configs manually here. From what I can tell, there's a pretty standard exclude list that we should be able to copy-paste.

@@ -0,0 +1,4 @@
# @kbn/core-saved-objects-base-server-internal

This package contains the base parts of the server-side savedObjects internal implementation,
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 we need to be a bit more specific as to what the package contains. "base parts" isn't very descriptive. The list as per the PR description would be fine.

# @kbn/core-saved-objects-base-server-mocks

This package contains the mocks for the base server-side savedObjects sub-domain:
- `SavedObjectTypeRegistry` mock
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for adding which mocks the package contains!

@TinaHeiligers
Copy link
Contributor

FYI, it looks like the failing CI tests are related to recent changes in non-core code. I've tested resolving conflicts with main locally and the tests passed.

Copy link
Contributor

@semd semd left a comment

Choose a reason for hiding this comment

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

SecuritySolution changes LGTM

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/core-saved-objects-base-server-internal - 29 +29
@kbn/core-saved-objects-base-server-mocks - 4 +4
@kbn/core-saved-objects-utils-server - 86 +86
core 296 216 -80
total +39

Any counts in public APIs

Total count of every any typed public API. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats any for more detailed information.

id before after diff
@kbn/core-saved-objects-utils-server - 1 +1
core 2 1 -1
total -0

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
@kbn/core-saved-objects-base-server-internal - 1 +1
core 6 5 -1
total -0
Unknown metric groups

API count

id before after diff
@kbn/core-saved-objects-base-server-internal - 35 +35
@kbn/core-saved-objects-base-server-mocks - 4 +4
@kbn/core-saved-objects-utils-server - 99 +99
total +138

ESLint disabled line counts

id before after diff
@kbn/core-saved-objects-base-server-internal - 3 +3
core 32 29 -3
total -0

Total ESLint disabled count

id before after diff
@kbn/core-saved-objects-base-server-internal - 3 +3
core 37 34 -3
total -0

History

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

@pgayvallet pgayvallet merged commit f7c0a0c into elastic:main Aug 22, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Aug 22, 2022
WafaaNasr pushed a commit to WafaaNasr/kibana that referenced this pull request Aug 22, 2022
…ckages (elastic#137448)

* create @kbn/core-saved-objects-utils-server package

* create empty @kbn/core-saved-objects-base-server-internal package

* fix more internal imports

* [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix'

* start moving stuff to base package

* Fix SS mocks

* adapt some imports

* start fixing internal imports

* fix remaining core usages

* start fixing external usages

* lint

* move type registry and mocks to packages

* adapt usages of serializer in tests

* fix test mocking

* [CI] Auto-commit changed files from 'node scripts/generate packages_build_manifest'

* fix more internal usages of SOTR/mock

* fix package

* fix external usages

* fix more mocked packages

* fix more mocked packages

* self review

* Fix mistake from main merge

Attempt to undo an incorrect merge.

* add root_input_dir

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Christiane (Tina) Heiligers <christiane.heiligers@elastic.co>
Mpdreamz pushed a commit to Mpdreamz/kibana that referenced this pull request Sep 6, 2022
…ckages (elastic#137448)

* create @kbn/core-saved-objects-utils-server package

* create empty @kbn/core-saved-objects-base-server-internal package

* fix more internal imports

* [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix'

* start moving stuff to base package

* Fix SS mocks

* adapt some imports

* start fixing internal imports

* fix remaining core usages

* start fixing external usages

* lint

* move type registry and mocks to packages

* adapt usages of serializer in tests

* fix test mocking

* [CI] Auto-commit changed files from 'node scripts/generate packages_build_manifest'

* fix more internal usages of SOTR/mock

* fix package

* fix external usages

* fix more mocked packages

* fix more mocked packages

* self review

* Fix mistake from main merge

Attempt to undo an incorrect merge.

* add root_input_dir

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Christiane (Tina) Heiligers <christiane.heiligers@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v8.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants