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

[Content Management] Server side client #175968

Merged
merged 26 commits into from
Feb 5, 2024

Conversation

sebelga
Copy link
Contributor

@sebelga sebelga commented Jan 31, 2024

In this PR I'v added a server side client for Content management.
The client operates on a single content type and has the same methods as the content storage:

  • get
  • bulkGet
  • create
  • update
  • delete
  • search

I've also exposed an multi type search client with a single method to search accros different content types.
Currently it only support searching content types stored using the Saved object client.

  • msearch

API

When registering a content type

// 1. When registering the content type on the server, a content client for this specific content is returned
const { contentClient } = contentManagement.register({
  id: CONTENT_ID,
  storage: new MapsStorage(), // Instantiate our storage class
  version: {
    latest: LATEST_VERSION,
  },
});

// 2. On an incoming HTTP request we instantiate the client for this request
const client = contentClient.getForRequest({
  request, // the Kibana HTTP request
  requestHandlerContext, // the Kibana Request context
  version, // OPTIONAL: the browser client content version
});

// 3. We can now use any of the client method (e.g. fetch a map with ID '123')
const myMap = await client.get('123');

From the plugin setup contract

// setup lifecycle
const { contentClient } = plugins.contentManagement;

// Instantiate the factory for an incoming request
const client = contentClient.getForRequest({
  request,
  requestHandlerContext,
});

// Get a client for "dashboards" content type on version "2"
// Note: version is optional and will default to the latest version of the content if not provided
// It is recommended to provide the version of the browser making the request to be able to up/down transform the
// content if need be.
const dashboardClient = client.for("dashboards", 2);

// Fetch a dashboard
const myDashboard = await dashboardClient.get("123");

// -------------- Multi content type search --------------------

// Instantiate the factory for an incoming request
const client = contentClient.getForRequest({
  request,
  requestHandlerContext,
});

const { hits } = await client.msearch({
  contentTypes: [
    { contentTypeId: "dashboards" }, // optionally a "version" can be provided (defaults to "latest")
    { contentTypeId: "lens" },
  ],
  query: { text:  "my title" }
});

Notes on implementation

I've replaced the code in all the RPC procedures to consume the clients. This means that appart from the unit tests that I've added, the server side client is used on all the functional tests for the content registered in CM.

Fixes #154836
Fixes #170877

@sebelga
Copy link
Contributor Author

sebelga commented Jan 31, 2024

/ci

@sebelga sebelga force-pushed the content-management/server-client branch from c3e07b2 to 73a0d61 Compare February 1, 2024 11:10
@sebelga
Copy link
Contributor Author

sebelga commented Feb 1, 2024

/ci

@sebelga sebelga self-assigned this Feb 1, 2024
@sebelga sebelga added Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience) Feature:Content Management User generated content (saved objects) management labels Feb 1, 2024
@sebelga sebelga marked this pull request as ready for review February 1, 2024 12:30
@sebelga sebelga requested a review from a team as a code owner February 1, 2024 12:30
@elasticmachine
Copy link
Contributor

Pinging @elastic/appex-sharedux (Team:SharedUX)

@sebelga sebelga added the release_note:skip Skip the PR/issue when compiling release notes label Feb 1, 2024
@sebelga
Copy link
Contributor Author

sebelga commented Feb 1, 2024

Pinging @mattkime @thomasneirynck @davismcphee as you all requested this feature to be released at some point.
Feedback welcome on the provided API or any part of the code 😊

@sebelga
Copy link
Contributor Author

sebelga commented Feb 1, 2024

/ci

@sebelga
Copy link
Contributor Author

sebelga commented Feb 1, 2024

@elasticmachine run elasticsearch-ci/docs

@sebelga
Copy link
Contributor Author

sebelga commented Feb 1, 2024

/ci

Copy link
Member

@tsullivan tsullivan left a comment

Choose a reason for hiding this comment

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

LGTM, very straightforward CRUD additions

storageContext: StorageContext;
}

const secretToken = Symbol('secretToken');
Copy link
Member

Choose a reason for hiding this comment

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

Note to self: this never gets stored. I had to check because that could pose an issue if we ever handle a token that was created in a separate Kibana instance

@sebelga
Copy link
Contributor Author

sebelga commented Feb 5, 2024

Thanks for the review @tsullivan !

@sebelga sebelga enabled auto-merge (squash) February 5, 2024 10:24
@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
contentManagement 126 125 -1

History

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

cc @sebelga

@sebelga sebelga merged commit 97ebed0 into elastic:main Feb 5, 2024
17 checks passed
@kibanamachine kibanamachine added v8.13.0 backport:skip This commit does not require backporting labels Feb 5, 2024
@thomasneirynck
Copy link
Contributor

thx @sebelga this will be useful when looking at #174497

@sebelga sebelga deleted the content-management/server-client branch February 6, 2024 10:21
fkanout pushed a commit to fkanout/kibana that referenced this pull request Feb 7, 2024
CoenWarmer pushed a commit to CoenWarmer/kibana that referenced this pull request Feb 15, 2024
CoenWarmer pushed a commit to CoenWarmer/kibana that referenced this pull request Feb 15, 2024
fkanout pushed a commit to fkanout/kibana that referenced this pull request Mar 4, 2024
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 Feature:Content Management User generated content (saved objects) management release_note:skip Skip the PR/issue when compiling release notes Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience) v8.13.0
Projects
None yet
6 participants