forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for dynamic application configurations (opensearch-projec…
…t#5855) * Add application configuration service Signed-off-by: Tianle Huang <[email protected]> * update API path name Signed-off-by: Tianle Huang <[email protected]> * implement two APIs/interfaces Signed-off-by: Tianle Huang <[email protected]> * expose get function for other plugins to use Signed-off-by: Tianle Huang <[email protected]> * update interfaces Signed-off-by: Tianle Huang <[email protected]> * implement the APIs and interfaces Signed-off-by: Tianle Huang <[email protected]> * add license and jsdoc Signed-off-by: Tianle Huang <[email protected]> * update docs Signed-off-by: Tianle Huang <[email protected]> * add more docs Signed-off-by: Tianle Huang <[email protected]> * update variable name Signed-off-by: Tianle Huang <[email protected]> * remove unnecessary dependency Signed-off-by: Tianle Huang <[email protected]> * format readme Signed-off-by: Tianle Huang <[email protected]> * use osd version Signed-off-by: Tianle Huang <[email protected]> * remove debugging info Signed-off-by: Tianle Huang <[email protected]> * update logging Signed-off-by: Tianle Huang <[email protected]> * remove lint js Signed-off-by: Tianle Huang <[email protected]> * remove logs Signed-off-by: Tianle Huang <[email protected]> * update name style Signed-off-by: Tianle Huang <[email protected]> * update Signed-off-by: Tianle Huang <[email protected]> * update function visibility and error function Signed-off-by: Tianle Huang <[email protected]> * fix unit test failures Signed-off-by: Tianle Huang <[email protected]> * add unit test Signed-off-by: Tianle Huang <[email protected]> * remove lint file Signed-off-by: Tianle Huang <[email protected]> * add more tests Signed-off-by: Tianle Huang <[email protected]> * add unit tests for routes Signed-off-by: Tianle Huang <[email protected]> * add remaining unit tests Signed-off-by: Tianle Huang <[email protected]> * add enabled to this plugin Signed-off-by: Tianle Huang <[email protected]> * update readme to mention experimental Signed-off-by: Tianle Huang <[email protected]> * update change log Signed-off-by: Tianle Huang <[email protected]> * dummy commit to trigger workflow rerun Signed-off-by: Tianle Huang <[email protected]> * remove experimental Signed-off-by: Tianle Huang <[email protected]> * add key to yml file Signed-off-by: Tianle Huang <[email protected]> * remove i18n Signed-off-by: Tianle Huang <[email protected]> * remove lint rc Signed-off-by: Tianle Huang <[email protected]> * update comment style Signed-off-by: Tianle Huang <[email protected]> * add input validation Signed-off-by: Tianle Huang <[email protected]> * update unit tests Signed-off-by: Tianle Huang <[email protected]> * prevent multiple registration Signed-off-by: Tianle Huang <[email protected]> * add return types Signed-off-by: Tianle Huang <[email protected]> * update readme wording Signed-off-by: Tianle Huang <[email protected]> * add unit test to the plugin class about double register Signed-off-by: Tianle Huang <[email protected]> * move related ymls Signed-off-by: Tianle Huang <[email protected]> * move validation to a function Signed-off-by: Tianle Huang <[email protected]> * use trimmed versions Signed-off-by: Tianle Huang <[email protected]> * reword changelog entry Signed-off-by: Tianle Huang <[email protected]> * readability Signed-off-by: Tianle Huang <[email protected]> * add back yml change Signed-off-by: Tianle Huang <[email protected]> --------- Signed-off-by: Tianle Huang <[email protected]>
- Loading branch information
Showing
21 changed files
with
1,464 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` | ||
|
||
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>; | ||
``` | ||
|
||
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 | ||
|
||
See the [OpenSearch Dashboards contributing | ||
guide](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/CONTRIBUTING.md) for instructions | ||
setting up your development environment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
Oops, something went wrong.