Skip to content

Commit 61ea841

Browse files
Design for New Saved Object Service Interface for Custom Repository (#3954)
* Adds design document for new saved object service interface for custom repository Signed-off-by: Bandini Bhopi <bandinib@amazon.com>
1 parent 83d7b5b commit 61ea841

6 files changed

+229
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
172172
- [Doc] Update DEVELOPER_GUIDE.md with added manual bootstrap timeout solution and max virtual memory error solution with docker ([#3764](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3764))
173173
- [Doc] Add COMMUNICATIONS.md with info about Slack, forum, office hours ([#3837](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3837))
174174
- [Doc] Add docker files and instructions for debugging Selenium functional tests ([#3747](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3747))
175+
- [Saved Object Service] Adds design doc for new Saved Object Service Interface for Custom Repository [#3954](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3954)
175176

176177
### 🛠 Maintenance
177178

Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@startuml
2+
title: Current Saved Object Service Flow
3+
actor User
4+
participant "Saved Object Client" as Client
5+
participant "Saved Object Repository" as Repo
6+
participant "Opensearch" as OS
7+
8+
User -> Client: Create Saved Object
9+
Client -> Repo: Create Saved Object
10+
Repo -> OS: Index Saved Object
11+
OS --> Repo: Saved Object Saved
12+
Client -> User: Saved Object Created
13+
User -> Client: Get Saved Object
14+
Client -> Repo: Get Saved Object
15+
Repo -> OS: Get Saved Object
16+
OS --> Repo: Return Saved Object
17+
Repo -> Client: Return Saved Object
18+
Client -> User: Saved Object Data
19+
@enduml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
@startuml
2+
3+
title: Proposed Saved Object Service Flow
4+
5+
actor User
6+
7+
participant "OpenSearch-Dashboards" as OSD
8+
9+
box "Saved Object Service" #LightBlue
10+
participant "Saved Object Client" as Client
11+
participant "Repository Factory Provider" as Factory
12+
end box
13+
14+
box "Dashboards Storage Plugin" #LightYellow
15+
participant "Repository\n(e.g. PostgresRepository,\nDynamoDBRepository)" as Repo
16+
participant "Metadata Storage\n(e.g. Postgres, \nDynamoDB etc)" as Meta
17+
end box
18+
19+
autonumber
20+
group OSD Bootstrap
21+
Repo -> Factory: Register custom repository
22+
Factory -> Client: Returns repository
23+
Client -> OSD: Returns Saved Object Client
24+
end group
25+
User -> Client: Create Saved Object
26+
Client -> Repo: Create Saved Object
27+
Repo -> Meta: Create/Update Record
28+
Meta --> Repo: Saved Object Saved
29+
Client -> User: Saved Object Created
30+
User -> Client: Get Saved Object
31+
Client -> Repo: Get Saved Object
32+
Repo -> Meta: Fetch Saved Object from storage
33+
Meta --> Repo: Return Saved Object
34+
Repo -> Client: Return Saved Object
35+
Client -> User: Saved Object Data
36+
37+
skinparam BoxPadding 15
38+
@enduml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# Proposed Saved Object Service Interface for Custom Repository
2+
3+
## Introduction
4+
5+
The new saved object service interface for custom repository is a project that aims to improve scalability of the existing saved object service by introducing a new interface. The goal of this project is to provide a more efficient and flexible interface that will make it easier for developers to configure metadata of Dashboards in any different storage than OpenSearch, such as mysql, postgres, DDB, serverless (S3+ Athena).
6+
7+
Currently, Dashboards stores its metadata configuration inside OpenSearch index (called .kibana). This approach is by design of Dashboards and biased towards product decision by upstream which works seamlessly and out of the box for customers but it introduces challenges while operating at scale and providing high availability for Dashboards. While choosing OpenSearch as a storage for Dashboards metadata, availability of Dashboards depends on OpenSearch cluster’s availability and other cluster parameters such as cluster health, state, versions which could make Dashboards unavailable.
8+
9+
To mitigate above problem and unblock future extensibility of Dashboards, we are building Dashboards Meta storage adaptor to decouple Dashboards metadata storage from OpenSearch. This project will focus on introducing new interface in Saved Object Service using which developer can build their custom repository and save Dashboards metadata in storage of their choice.
10+
11+
The stakeholders of this new interface include the developers of the Dashboards and community contributors who wants to use other metadata store.
12+
13+
## Architecture Overview
14+
15+
The Saved Object Service is a critical component of Dashboards that provides a way to store and manage application data. It is built using a modular architecture that provides a high degree of flexibility and extensibility. The new interface will be designed to replace [ISavedObjectRepository](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/src/core/server/saved_objects/service/lib/repository.ts#L134) implementation so that developers can build plugins that leverage the power of existing saved object service and use their own database to store and retrieve metadata of OpenSearch Dashboards.
16+
17+
### Current Architecture
18+
19+
The repository interface named [ISavedObjectRepository](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/src/core/server/saved_objects/service/lib/repository.ts#L134) in OpenSearch-Dashboards is a module that provides an interface for managing saved objects. The [SavedObjectRepository](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/src/core/server/saved_objects/service/lib/repository.ts#L139) is the implementation of [ISavedObjectRepository](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/src/core/server/saved_objects/service/lib/repository.ts#L134), which uses OpenSearch index as it’s data store. It is responsible for storing, retrieving, and deleting saved objects for Dashboards, such as visualizations, dashboards, and searches.
20+
21+
The Saved Object Repository is built on top of the OpenSearch client and provides a simplified interface for working with OpenSearch. It uses the Saved Object Serializer to convert saved objects between their internal and external representations. The repository is then being consumed by Saved object client to create scoped saved object client.
22+
23+
![img](./img/current_saved_object_service_workflow.png)
24+
25+
### Proposed Architecture
26+
27+
- **Approach 1 (Preferred)**: The proposed architecture will add one more layer of abstraction in Saved Object Service. `The Repository Factory Provider` in OpenSearch Dashboards will be responsible for creating and managing instances of the Repository (e.g. SavedObjectRepository, PostgresRepository, DynamoDBRepository etc.), which is used to interact with the metadata storage that stores the saved objects. Currently we have an repository interface named [ISavedObjectRepository](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/src/core/server/saved_objects/service/lib/repository.ts#L134), and the [SavedObjectRepository](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/src/core/server/saved_objects/service/lib/repository.ts#L139) is the implementation, which use an OpenSearch index as its data store. This approach would make the implementation of [ISavedObjectRepository](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/src/core/server/saved_objects/service/lib/repository.ts#L134) replaceable by plugin.
28+
29+
![img](./img/proposed_saved_object_service_workflow.png)
30+
31+
* Pros:
32+
* Only change needed in Dashboard is to introduce one more abstraction layer in Saved Object Service.
33+
* Adds opportunity for community developers to contribute for other meta store.
34+
35+
* Cons
36+
* Code reusability is low.
37+
<br/>
38+
39+
**POC**:
40+
1) Core Dashboards Change: https://github.com/bandinib-amzn/OpenSearch-Dashboards/commit/b9cfc14
41+
2) Postgres Repository Plugin: https://github.com/bandinib-amzn/metadata_plugin/commit/dac35f0
42+
43+
`SavedObjectsServiceSetup` provides interface to create custom Saved Object Repository.
44+
```
45+
/**
46+
* Set the default {@link SavedObjectRepositoryFactoryProvider | factory provider} for creating Saved Objects repository.
47+
* Only one repository can be set, subsequent calls to this method will fail.
48+
*/
49+
registerRepositoryFactoryProvider: (
50+
respositoryFactoryProvider: SavedObjectRepositoryFactoryProvider
51+
) => void;
52+
```
53+
54+
Here are the main steps involved in using the Saved Objects Repository Factory in Dashboards:
55+
1. Define the dependencies: The Saved Object Repository Factory Provider requires the function which creates instance of [ISavedObjectRepository](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/src/core/server/saved_objects/service/lib/repository.ts#L134).
56+
```
57+
export const repositoryFactoryProvider: SavedObjectRepositoryFactoryProvider = (
58+
options: SavedObjectsRepositoryOptions
59+
) => {
60+
.
61+
.
62+
.
63+
return new PostgresRepository({
64+
typeRegistry,
65+
serializer,
66+
migrator,
67+
allowedTypes,
68+
});
69+
}
70+
```
71+
2. Register the provider: Register the repository factory provider with right dependencies.
72+
```
73+
core.savedObjects.registerRepositoryFactoryProvider(repositoryFactoryProvider);
74+
```
75+
3. Implement the Saved Object Operations for chosen storage type: Implement the CRUD and other operations for contracts defined in [ISavedObjectRepository](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/src/core/server/saved_objects/service/lib/repository.ts#L134)
76+
```
77+
async create<T = unknown>(
78+
type: string,
79+
attributes: T,
80+
options: SavedObjectsCreateOptions = {}
81+
): Promise<SavedObject<T>> {
82+
...
83+
}
84+
85+
async get<T = unknown>(
86+
type: string,
87+
id: string,
88+
options: SavedObjectsBaseOptions = {}
89+
): Promise<SavedObject<T>> {
90+
...
91+
}
92+
93+
async update<T = unknown>(
94+
type: string,
95+
id: string,
96+
attributes: Partial<T>,
97+
options: SavedObjectsUpdateOptions = {}
98+
): Promise<SavedObjectsUpdateResponse<T>> {
99+
...
100+
}
101+
102+
async deleteFromNamespaces(
103+
type: string,
104+
id: string,
105+
namespaces: string[],
106+
options: SavedObjectsDeleteFromNamespacesOptions = {}
107+
): Promise<SavedObjectsDeleteFromNamespacesResponse> {
108+
...
109+
}
110+
.
111+
.
112+
.
113+
```
114+
115+
- **Approach 2**: Build external plugin and using saved object client wrapper or client factory provider injection mechanism we can build custom object for Postgres or other DB.
116+
117+
* Pros:
118+
* No changes in core Dashboards. That means we can keep Dashboards as it is with very minimal changes.
119+
120+
121+
* Cons
122+
* Code reusability is low.
123+
* Some components of Saved object service such as Serializer, Type registry, interface to create internal and scoped repository are only available during Saved Object Service Start. As per the current architecture, first Saved Object Service Setup → Plugin Setup → Saved Object Service Start → Plugin Start. Some core plugin (e.g. opensearch_dashboards_usage_collection) calls find operation before plugin start and it fails because some components are still not available before plugin start.
124+
<br/>
125+
126+
**POC**: https://github.com/bandinib-amzn/metadata_plugin/compare/f040daf...89213eb
127+
128+
129+
- **Approach 3**: In this approach, we just extend the `SavedObjectsRepository` class and override CRUD and other saved object operation in core Dashboards.
130+
131+
* Pros:
132+
* As we are extending the repository in core saved object service itself, we can reuse the validation and utility functions for other database options.
133+
134+
135+
* Cons
136+
* Changes in core Dashboards : We will be making considerable changes in critical component of Dashboards.
137+
* With this approach, user will have to use the data storage option that we choose.
138+
<br/>
139+
140+
**POC**: https://github.com/bandinib-amzn/OpenSearch-Dashboards/compare/main...22d7f30
141+
142+
## Implementation Details
143+
144+
145+
| Repository | Component | Change |
146+
| ----------- | ----------- | ----------- |
147+
| OpenSearch-Dashboards | Saved Object Service | Add Saved object repository factory provider |
148+
| OpenSearch-Dashboards | Config | Configuration for metadata storage |
149+
| MetaStorage-Plugin [Name TBD] | Plugin / Extension | We will build new plugin for Postgres. This is use case for new interface in Saved Object Repository. |
150+
151+
### Configuration for metadata storage:
152+
```
153+
metaStorage.enabled: true
154+
metaStorage.config: {
155+
type: 'xxxx',
156+
hostName: 'xxxx',
157+
userName: 'xxxx',
158+
password: 'xxxx',
159+
port: xxxx,
160+
}
161+
```
162+
163+
## Testing and Quality Assurance
164+
165+
### Testing Approach
166+
167+
The following testing approach will be used to ensure the quality of the system:
168+
169+
1. **Unit testing**: Metadata store plugin will be thoroughly unit tested to ensure it meets its requirements and performs as expected. Also we will add new test cases in OpenSearch-Dashboards to test new repository factory provider.
170+
2. **Integration testing**: Components will be integrated and tested together to ensure they work together seamlessly and without conflicts.
171+

0 commit comments

Comments
 (0)