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

Create common and api types packages for the savedObjects domain #136722

Merged

Conversation

pgayvallet
Copy link
Contributor

@pgayvallet pgayvallet commented Jul 20, 2022

Summary

Part 1 of #135820
Required for #134122

Extract all the types associated to the browser and server-side SavedObjectClient / SavedObjectClientContract and SavedObjectRepository and move them to packages.

Create the following packages:

  • @kbn/core-saved-objects-common
  • @kbn/core-saved-objects-api-server
  • @kbn/core-saved-objects-api-browser

Note: this PR does not move all the SO types to packages, only the subset associated with the browser/server-side clients. The other types will be done in a follow-up (part 2), then the implementation will (part 3).

Remarks:

- @kbn/core-saved-objects-api-browser depends on @kbn/core-saved-objects-api-server

A lot of client-side types were inferred from their server-side counterpart, and move importantly, some were inferred from the server-side client type itself, which would have meant that if we wanted to move these 'common' types to a common package, the whole server-side types would have needed to be in it.

After a lot of thinking and discussions with various people, the conclusion was that the best approach was probably to KISS and just have the browser-side type api types package depends on the server-side one, 'as it's currently done'.

Note that this doesn't go against the package architecture rules in any way, as the Operations teams is not planning on banning cross environment type only imports.

- There will be more than one type package for the SO types

@kbn/core-saved-objects-api-server and @kbn/core-saved-objects-api-browser only contain the types associated with the SO clients/repository. The other public types will be extracted to distinct @kbn/core-saved-objects-browser and @kbn/core-saved-objects-api-server packages during the next stage of the issue.

This separation felt just logical for multiple reasons:

  • The SO domain just has a LOT of types, splitting them into type sub packages felt just a good thing to do
  • Doing the splitting on the client API / non client API public type felt like the most logical separation (and it still feels correct after having completed the current PR)
  • It give a better isolation of concern / dependency regarding the browser-side types that depends on the server-side types (the service/contract types will not depend on each other, only the client types did)

Notable changes:

1. (browser+server) cleanup of the client/repository API types.

The SavedObjectClientContract and ISavedObjectRepository (we're so consistent in naming our interfaces...) were implicitly inferred from their respective concrete implementations (which is something that is not possibleto have for the package arch). This is no longer the case, as explicit interfaces were introduced in this PR.

The API types were also properly reorganised (it was so a mess previously), with one file per API, in the @kbn/core-saved-objects-api-server and @kbn/core-saved-objects-api-browser packages.

2. (browser) expose SimpleSavedObject as an interface

The SimpleSavedObject concrete implementation was used in some of the client-side SO client signatures, and exported from our client-side entrypoint (as a concrete class, not as a type). It's now properly exposed as an interface.

The implementation is still exported (as SimpleSavedObjectImpl) atm, as a few test files outside of Core were using the implementation for testing purposes. We could eventually introduce a mock later on to address this point.

3. (server) removal of SavedObjectClientContract.errors

The SavedObjectErrorHelper utility has been historically exposed via SavedObjectClientContract.errors. Cleaning up the types was a good opportunity to remove it from the server-side client type. Adapted the code of the few actors that were accessing it to import and use SavedObjectErrorHelper directly instead (this class will be moved to a utility package at some point)

4. (browser) removal of some 'server-side only' export from src/core/public

Some server-side SO API types were exported from Core's client-side entrypoint just because some external consumers were importing it to shape some responses from server APIs that did not belong to Core (so these types were technically not used on the client-side by core public APIs).

These exports were removed, and the imports external to Core were adapted to import the client-side type counterparts, or to import from the server-side api package instead (which is and will be technically allowed by the package system).

@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.4.0 labels Jul 20, 2022
@pgayvallet pgayvallet changed the title Create common types package for the savedObjects domain Create common and api types package for the savedObjects domain Jul 21, 2022
@matschaffer matschaffer self-requested a review July 25, 2022 03:42
@matschaffer
Copy link
Contributor

@elasticmachine merge upstream

Copy link
Contributor

@matschaffer matschaffer left a comment

Choose a reason for hiding this comment

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

Infra plugin changes (@elastic/infra-monitoring-ui) look fine to me.

@@ -50,7 +50,7 @@ interface EncryptedSavedObjectsClientOptions {
export class EncryptedSavedObjectsClientWrapper implements SavedObjectsClientContract {
constructor(
private readonly options: EncryptedSavedObjectsClientOptions,
public readonly errors = options.baseClient.errors
public readonly errors = SavedObjectsErrorHelpers
Copy link
Member

Choose a reason for hiding this comment

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

But just to avoid potentially breaking stuff, I kept it (as the original SO client also still have the property even if not defined on the interface)

👍 We'll probably get rid of this in the scope of #134395 anyway

@@ -8,7 +8,7 @@
import { EuiHorizontalRule, EuiText } from '@elastic/eui';
import React, { useMemo } from 'react';

import type { SavedObjectReferenceWithContext } from '@kbn/core/public';
import type { SavedObjectReferenceWithContext } from '@kbn/core-saved-objects-api-server';
Copy link
Member

Choose a reason for hiding this comment

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

question: I see the issue description mentions that it's expected that @kbn/core-saved-objects-api-browser depends on @kbn/core-saved-objects-api-server, does it also apply to the type dependencies from the browser parts of other plugins to @kbn/core-saved-objects-api-server or is it just intermediate step and we'll eventually have SavedObjectReferenceWithContext and SavedObjectsCollectMultiNamespaceReferencesResponse exposed from either @kbn/core-saved-objects-api-browser or @kbn/core-saved-objects-common?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question, to which we don't have a definitive answer atm. For now, the idea is that 'server' types (understand types coming from the server-side client/repository signatures) that are not directly used by publicly exposed Core public-side SO APIs are considered as 'server-side only' from Core standpoint, and therefor will not be exposed from public/common core packages.

Note that, as explained in the issue's description, it's still fine to import such types coming from -server packages from the client side from browser-side plugins that uses it.

Mid/long term, we'll probably want to introduce an additional layer of types for the param/response types of the SO HTTP APIs (which we currently don't have atm). Those types will be exposed from a common package, given they handle the client/server contract via these HTTP APIs.

Copy link
Member

Choose a reason for hiding this comment

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

Mid/long term, we'll probably want to introduce an additional layer of types for the param/response types of the SO HTTP APIs (which we currently don't have atm). Those types will be exposed from a common package, given they handle the client/server contract via these HTTP APIs.

Got it, it makes sense. Thank you for clarifying.

@pgayvallet pgayvallet force-pushed the kbn-135820-so-common-types-to-package branch from 745b220 to 8451d9b Compare July 25, 2022 07:23
@pgayvallet pgayvallet requested a review from a team as a code owner July 25, 2022 07:52
Copy link
Contributor

@patrykkopycinski patrykkopycinski left a comment

Choose a reason for hiding this comment

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

Asset management LGTM

Copy link
Contributor

@dasansol92 dasansol92 left a comment

Choose a reason for hiding this comment

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

OLM changes LGTM!

Copy link
Contributor

@gbamparop gbamparop left a comment

Choose a reason for hiding this comment

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

APM change LGTM!

@pgayvallet pgayvallet removed the request for review from joeypoon July 25, 2022 14:21
Copy link
Contributor

@dhurley14 dhurley14 left a comment

Choose a reason for hiding this comment

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

security solution platform changes LGTM!

Copy link
Contributor

@ThomThomson ThomThomson left a comment

Choose a reason for hiding this comment

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

Import changes LGTM!

Copy link
Member

@sorenlouv sorenlouv left a comment

Choose a reason for hiding this comment

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

apm changes lgtm

@pgayvallet pgayvallet enabled auto-merge (squash) July 26, 2022 07:09
@kibana-ci
Copy link
Collaborator

kibana-ci commented Jul 26, 2022

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Fleet Cypress Tests / View agents Bulk actions "after all" hook for "should allow to bulk upgrade agents"

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-api-browser - 66 +66
@kbn/core-saved-objects-api-server - 125 +125
@kbn/core-saved-objects-common - 41 +41
core 648 413 -235
data 2424 2420 -4
dataViews 203 201 -2
total -9

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-api-browser - 1 +1
@kbn/core-saved-objects-api-server - 1 +1
core 5 2 -3
total -1

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
core 16 8 -8

Page load bundle

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

id before after diff
core 342.2KB 342.2KB +20.0B
Unknown metric groups

API count

id before after diff
@kbn/core-saved-objects-api-browser - 94 +94
@kbn/core-saved-objects-api-server - 288 +288
@kbn/core-saved-objects-common - 82 +82
core 2474 2498 +24
total +488

ESLint disabled line counts

id before after diff
securitySolution 418 419 +1

Total ESLint disabled count

id before after diff
securitySolution 495 496 +1

Unreferenced deprecated APIs

id before after diff
@kbn/core-saved-objects-common - 1 +1

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
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:APM All issues that need APM UI Team support Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Team:Fleet Team label for Observability Data Collection Fleet team v8.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.