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

Add support for dynamic application configurations #5855

Merged
merged 47 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
5fdba1d
Add application configuration service
tianleh Feb 9, 2024
91b2d56
update API path name
tianleh Feb 15, 2024
7c9b6ac
implement two APIs/interfaces
tianleh Feb 15, 2024
e98600f
expose get function for other plugins to use
tianleh Feb 15, 2024
37e740b
update interfaces
tianleh Feb 16, 2024
237dd22
implement the APIs and interfaces
tianleh Feb 17, 2024
dffb866
add license and jsdoc
tianleh Feb 17, 2024
d352d18
update docs
tianleh Feb 20, 2024
bf73427
add more docs
tianleh Feb 20, 2024
673d82d
update variable name
tianleh Feb 20, 2024
b92d724
remove unnecessary dependency
tianleh Feb 20, 2024
3be8782
format readme
tianleh Feb 20, 2024
5c94f9f
use osd version
tianleh Feb 20, 2024
4bc6fa5
remove debugging info
tianleh Feb 21, 2024
60448f4
update logging
tianleh Feb 21, 2024
845b1dc
remove lint js
tianleh Feb 22, 2024
7d27aa5
remove logs
tianleh Feb 22, 2024
9460c11
update name style
tianleh Feb 23, 2024
fefc172
update
tianleh Feb 23, 2024
d422a0d
update function visibility and error function
tianleh Feb 23, 2024
01550dd
fix unit test failures
tianleh Feb 23, 2024
1df50d2
add unit test
tianleh Feb 24, 2024
d88b7d1
remove lint file
tianleh Feb 24, 2024
eea3b1d
add more tests
tianleh Feb 24, 2024
8196280
add unit tests for routes
tianleh Feb 24, 2024
a610415
add remaining unit tests
tianleh Feb 24, 2024
4dd1f72
add enabled to this plugin
tianleh Feb 24, 2024
17c84b9
update readme to mention experimental
tianleh Feb 24, 2024
d1dd2b5
update change log
tianleh Feb 24, 2024
43e3e7f
dummy commit to trigger workflow rerun
tianleh Feb 24, 2024
cd54144
remove experimental
tianleh Feb 26, 2024
3117dbb
add key to yml file
tianleh Feb 27, 2024
ffe1a92
remove i18n
tianleh Feb 27, 2024
f6c4647
remove lint rc
tianleh Feb 28, 2024
813d897
update comment style
tianleh Feb 28, 2024
a338863
add input validation
tianleh Feb 28, 2024
98b2bfd
update unit tests
tianleh Feb 29, 2024
a59fe4f
prevent multiple registration
tianleh Feb 29, 2024
1198047
add return types
tianleh Feb 29, 2024
d2668d7
update readme wording
tianleh Feb 29, 2024
90e5a08
add unit test to the plugin class about double register
tianleh Feb 29, 2024
f4e1a31
move related ymls
tianleh Feb 29, 2024
6db36df
move validation to a function
tianleh Feb 29, 2024
6b07cd8
use trimmed versions
tianleh Mar 1, 2024
1ff31f6
reword changelog entry
tianleh Mar 1, 2024
73fd1c4
readability
tianleh Mar 1, 2024
4d80ad6
add back yml change
tianleh Mar 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Multiple Datasource] Refactor client and legacy client to use authentication registry ([#5881](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5881))
- [Multiple Datasource] Improved error handling for the search API when a null value is passed for the dataSourceId ([#5882](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5882))
- [Multiple Datasource] Hide/Show authentication method in multi data source plugin based on configuration ([#5916](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5916))
- [[Dynamic Configurations] Add support for dynamic application configurations ([#5855](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5855))

### 🐛 Bug Fixes

Expand Down
7 changes: 7 additions & 0 deletions config/opensearch_dashboards.yml
tianleh marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
# dashboards. OpenSearch Dashboards creates a new index if the index doesn't already exist.
#opensearchDashboards.index: ".opensearch_dashboards"

# OpenSearch Dashboards uses an index in OpenSearch to store dynamic configurations.
# This shall be a different index from opensearchDashboards.index.
# opensearchDashboards.configIndex: ".opensearch_dashboards_config"

# Set the value of this setting to true to enable plugin application config. By default it is disabled.
# application_config.enabled: false

# The default application to load.
#opensearchDashboards.defaultAppId: "home"

Expand Down
1 change: 1 addition & 0 deletions src/core/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export function pluginInitializerContextConfigMock<T>(config: T) {
const globalConfig: SharedGlobalConfig = {
opensearchDashboards: {
index: '.opensearch_dashboards_tests',
configIndex: '.opensearch_dashboards_config_tests',
autocompleteTerminateAfter: duration(100000),
autocompleteTimeout: duration(1000),
},
Expand Down
1 change: 1 addition & 0 deletions src/core/server/opensearch_dashboards_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const config = {
schema: schema.object({
enabled: schema.boolean({ defaultValue: true }),
index: schema.string({ defaultValue: '.kibana' }),
configIndex: schema.string({ defaultValue: '.opensearch_dashboards_config' }),
autocompleteTerminateAfter: schema.duration({ defaultValue: 100000 }),
autocompleteTimeout: schema.duration({ defaultValue: 1000 }),
branding: schema.object({
Expand Down
1 change: 1 addition & 0 deletions src/core/server/plugins/plugin_context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ describe('createPluginInitializerContext', () => {
expect(configObject).toStrictEqual({
opensearchDashboards: {
index: '.kibana',
configIndex: '.opensearch_dashboards_config',
autocompleteTerminateAfter: duration(100000),
autocompleteTimeout: duration(1000),
},
Expand Down
7 changes: 6 additions & 1 deletion src/core/server/plugins/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,12 @@ export interface Plugin<

export const SharedGlobalConfigKeys = {
// We can add more if really needed
opensearchDashboards: ['index', 'autocompleteTerminateAfter', 'autocompleteTimeout'] as const,
opensearchDashboards: [
'index',
'configIndex',
'autocompleteTerminateAfter',
'autocompleteTimeout',
] as const,
opensearch: ['shardTimeout', 'requestTimeout', 'pingTimeout'] as const,
path: ['data'] as const,
savedObjects: ['maxImportPayloadBytes'] as const,
Expand Down
1 change: 1 addition & 0 deletions src/legacy/server/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export default () =>
opensearchDashboards: Joi.object({
enabled: Joi.boolean().default(true),
index: Joi.string().default('.kibana'),
configIndex: Joi.string().default('.opensearch_dashboards_config'),
autocompleteTerminateAfter: Joi.number().integer().min(1).default(100000),
// TODO Also allow units here like in opensearch config once this is moved to the new platform
autocompleteTimeout: Joi.number().integer().min(1).default(1000),
Expand Down
112 changes: 112 additions & 0 deletions src/plugins/application_config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# ApplicationConfig Plugin

An OpenSearch Dashboards plugin for application configuration and a default implementation based on OpenSearch as storage.

---

## Introduction

This plugin introduces the support of dynamic application configurations as opposed to the existing static configuration in OSD YAML file `opensearch_dashboards.yml`. It stores the configuration in an index whose default name is `.opensearch_dashboards_config` and could be customized through the key `opensearchDashboards.configIndex` in OSD YAML file. Initially the new index does not exist. Only OSD users who need dynamic configurations will create it.

It also provides an interface `ConfigurationClient` for future extensions of external configuration clients. A default implementation based on OpenSearch as database is used.

This plugin is disabled by default.

## Configuration

OSD users who want to set up application configurations will first need to enable this plugin by the following line in OSD YML.

```
application_config.enabled: true
tianleh marked this conversation as resolved.
Show resolved Hide resolved

```

Then they can perform configuration operations through CURL the OSD APIs.

(Note that the commands following could be first obtained from a copy as curl option from the network tab of a browser development tool and then replaced with the API names)

Below is the CURL command to view all configurations.

```
curl '{osd endpoint}/api/appconfig' -X GET
```

Below is the CURL command to view the configuration of an entity.

```
curl '{osd endpoint}/api/appconfig/{entity}' -X GET

```

Below is the CURL command to update the configuration of an entity.

```
curl '{osd endpoint}/api/appconfig/{entity}' -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'osd-xsrf: osd-fetch' -H 'Sec-Fetch-Dest: empty' --data-raw '{"newValue":"{new value}"}'
```

Below is the CURL command to delete the configuration of an entity.

```
curl '{osd endpoint}/api/appconfig/{entity}' -X DELETE -H 'osd-xsrf: osd-fetch' -H 'Sec-Fetch-Dest: empty'

```


## External Configuration Clients

While a default OpenSearch based client is implemented, OSD users can use external configuration clients through an OSD plugin (outside OSD).

Let's call this plugin `MyConfigurationClientPlugin`.

First, this plugin will need to implement a class `MyConfigurationClient` based on interface `ConfigurationClient` defined in the `types.ts` under directory `src/plugins/application_config/server/types.ts`. Below are the functions inside the interface.

```
getConfig(): Promise<Map<string, string>>;

getEntityConfig(entity: string): Promise<string>;

updateEntityConfig(entity: string, newValue: string): Promise<string>;

deleteEntityConfig(entity: string): Promise<string>;
tianleh marked this conversation as resolved.
Show resolved Hide resolved
```

Second, this plugin needs to declare `applicationConfig` as its dependency by adding it to `requiredPlugins` in its own `opensearch_dashboards.json`.

Third, the plugin will define a new type called `AppPluginSetupDependencies` as follows in its own `types.ts`.

```
export interface AppPluginSetupDependencies {
applicationConfig: ApplicationConfigPluginSetup;
}

```

Then the plugin will import the new type `AppPluginSetupDependencies` and add to its own setup input. Below is the skeleton of the class `MyConfigurationClientPlugin`.

```
// MyConfigurationClientPlugin
public setup(core: CoreSetup, { applicationConfig }: AppPluginSetupDependencies) {

...
// The function createClient provides an instance of ConfigurationClient which
// could have a underlying DynamoDB or Postgres implementation.
const myConfigurationClient: ConfigurationClient = this.createClient();

applicationConfig.registerConfigurationClient(myConfigurationClient);
...
return {};
}

```

## Onboarding Configurations

Since the APIs and interfaces can take an entity, a new use case to this plugin could just pass their entity into the parameters. There is no need to implement new APIs or interfaces. To programmatically call the functions in `ConfigurationClient` from a plugin (the caller plugin), below is the code example.

Similar to [section](#external-configuration-clients), a new type `AppPluginSetupDependencies` which encapsulates `ApplicationConfigPluginSetup` is needed. Then it can be imported into the `setup` function of the caller plugin. Then the caller plugin will have access to the `getConfigurationClient` and `registerConfigurationClient` exposed by `ApplicationConfigPluginSetup`.

## Development
tianleh marked this conversation as resolved.
Show resolved Hide resolved

See the [OpenSearch Dashboards contributing
guide](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/CONTRIBUTING.md) for instructions
setting up your development environment.
7 changes: 7 additions & 0 deletions src/plugins/application_config/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export const PLUGIN_ID = 'applicationConfig';
export const PLUGIN_NAME = 'application_config';
12 changes: 12 additions & 0 deletions src/plugins/application_config/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { schema, TypeOf } from '@osd/config-schema';

export const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: false }),
});

export type ApplicationConfigSchema = TypeOf<typeof configSchema>;
9 changes: 9 additions & 0 deletions src/plugins/application_config/opensearch_dashboards.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "applicationConfig",
"version": "opensearchDashboards",
"opensearchDashboardsVersion": "opensearchDashboards",
"server": true,
"ui": false,
"requiredPlugins": [],
"optionalPlugins": []
}
23 changes: 23 additions & 0 deletions src/plugins/application_config/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { PluginConfigDescriptor, PluginInitializerContext } from '../../../core/server';
import { ApplicationConfigSchema, configSchema } from '../config';
import { ApplicationConfigPlugin } from './plugin';

/*
This exports static code and TypeScript types,
as well as, OpenSearch Dashboards Platform `plugin()` initializer.
*/

export const config: PluginConfigDescriptor<ApplicationConfigSchema> = {
schema: configSchema,
};

export function plugin(initializerContext: PluginInitializerContext) {
return new ApplicationConfigPlugin(initializerContext);
}

export { ApplicationConfigPluginSetup, ApplicationConfigPluginStart } from './types';
Loading
Loading