From d4216a084b55e11c0d89457d0c8cc3f97684bc88 Mon Sep 17 00:00:00 2001 From: WenyXu Date: Thu, 24 Oct 2024 06:16:54 +0000 Subject: [PATCH 1/2] feat: introduce the `PluginOptions` --- Cargo.lock | 1 + src/cmd/src/datanode.rs | 3 ++- src/cmd/src/frontend.rs | 5 +++-- src/cmd/src/metasrv.rs | 3 ++- src/cmd/src/options.rs | 3 +++ src/cmd/src/standalone.rs | 7 ++++--- src/plugins/Cargo.toml | 1 + src/plugins/src/datanode.rs | 3 +++ src/plugins/src/frontend.rs | 3 +++ src/plugins/src/lib.rs | 2 ++ src/plugins/src/meta_srv.rs | 3 +++ src/plugins/src/options.rs | 23 +++++++++++++++++++++++ 12 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 src/plugins/src/options.rs diff --git a/Cargo.lock b/Cargo.lock index fc57d670461d..2464436b3a67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8330,6 +8330,7 @@ dependencies = [ "datanode", "frontend", "meta-srv", + "serde", "snafu 0.8.5", ] diff --git a/src/cmd/src/datanode.rs b/src/cmd/src/datanode.rs index 466514d0387d..fa9b196ce6b4 100644 --- a/src/cmd/src/datanode.rs +++ b/src/cmd/src/datanode.rs @@ -272,9 +272,10 @@ impl StartCommand { info!("Datanode start command: {:#?}", self); info!("Datanode options: {:#?}", opts); + let plugin_opts = opts.plugins; let opts = opts.component; let mut plugins = Plugins::new(); - plugins::setup_datanode_plugins(&mut plugins, &opts) + plugins::setup_datanode_plugins(&mut plugins, &opts, &plugin_opts) .await .context(StartDatanodeSnafu)?; diff --git a/src/cmd/src/frontend.rs b/src/cmd/src/frontend.rs index 2f10b722c732..d11f64b0b62b 100644 --- a/src/cmd/src/frontend.rs +++ b/src/cmd/src/frontend.rs @@ -266,9 +266,10 @@ impl StartCommand { info!("Frontend start command: {:#?}", self); info!("Frontend options: {:#?}", opts); + let plugin_opts = opts.plugins; let opts = opts.component; let mut plugins = Plugins::new(); - plugins::setup_frontend_plugins(&mut plugins, &opts) + plugins::setup_frontend_plugins(&mut plugins, &opts, &plugin_opts) .await .context(StartFrontendSnafu)?; @@ -472,7 +473,7 @@ mod tests { }; let mut plugins = Plugins::new(); - plugins::setup_frontend_plugins(&mut plugins, &fe_opts) + plugins::setup_frontend_plugins(&mut plugins, &fe_opts, &[]) .await .unwrap(); diff --git a/src/cmd/src/metasrv.rs b/src/cmd/src/metasrv.rs index 664066132e50..7022c6ee35a5 100644 --- a/src/cmd/src/metasrv.rs +++ b/src/cmd/src/metasrv.rs @@ -273,9 +273,10 @@ impl StartCommand { info!("Metasrv start command: {:#?}", self); info!("Metasrv options: {:#?}", opts); + let plugin_opts = opts.plugins; let opts = opts.component; let mut plugins = Plugins::new(); - plugins::setup_metasrv_plugins(&mut plugins, &opts) + plugins::setup_metasrv_plugins(&mut plugins, &opts, &plugin_opts) .await .context(StartMetaServerSnafu)?; diff --git a/src/cmd/src/options.rs b/src/cmd/src/options.rs index 26ac9203a225..ecff735294e1 100644 --- a/src/cmd/src/options.rs +++ b/src/cmd/src/options.rs @@ -15,6 +15,7 @@ use clap::Parser; use common_config::Configurable; use common_runtime::global::RuntimeOptions; +use plugins::PluginOptions; use serde::{Deserialize, Serialize}; #[derive(Parser, Default, Debug, Clone)] @@ -40,6 +41,8 @@ pub struct GlobalOptions { pub struct GreptimeOptions { /// The runtime options. pub runtime: RuntimeOptions, + /// The plugin options. + pub plugins: Vec, /// The options of each component (like Datanode or Standalone) of GreptimeDB. #[serde(flatten)] diff --git a/src/cmd/src/standalone.rs b/src/cmd/src/standalone.rs index 8e1185e38936..c9d07bd9269d 100644 --- a/src/cmd/src/standalone.rs +++ b/src/cmd/src/standalone.rs @@ -445,15 +445,16 @@ impl StartCommand { info!("Standalone options: {opts:#?}"); let mut plugins = Plugins::new(); + let plugin_opts = opts.plugins; let opts = opts.component; let fe_opts = opts.frontend_options(); let dn_opts = opts.datanode_options(); - plugins::setup_frontend_plugins(&mut plugins, &fe_opts) + plugins::setup_frontend_plugins(&mut plugins, &fe_opts, &plugin_opts) .await .context(StartFrontendSnafu)?; - plugins::setup_datanode_plugins(&mut plugins, &dn_opts) + plugins::setup_datanode_plugins(&mut plugins, &dn_opts, &plugin_opts) .await .context(StartDatanodeSnafu)?; @@ -762,7 +763,7 @@ mod tests { }; let mut plugins = Plugins::new(); - plugins::setup_frontend_plugins(&mut plugins, &fe_opts) + plugins::setup_frontend_plugins(&mut plugins, &fe_opts, &[]) .await .unwrap(); diff --git a/src/plugins/Cargo.toml b/src/plugins/Cargo.toml index c927fb3d33c5..977b7d9b7c7e 100644 --- a/src/plugins/Cargo.toml +++ b/src/plugins/Cargo.toml @@ -13,4 +13,5 @@ common-base.workspace = true datanode.workspace = true frontend.workspace = true meta-srv.workspace = true +serde.workspace = true snafu.workspace = true diff --git a/src/plugins/src/datanode.rs b/src/plugins/src/datanode.rs index f3cd62af559a..714e84bd53a2 100644 --- a/src/plugins/src/datanode.rs +++ b/src/plugins/src/datanode.rs @@ -16,11 +16,14 @@ use common_base::Plugins; use datanode::config::DatanodeOptions; use datanode::error::Result; +use crate::options::PluginOptions; + #[allow(unused_variables)] #[allow(unused_mut)] pub async fn setup_datanode_plugins( plugins: &mut Plugins, dn_opts: &DatanodeOptions, + plugin_options: &[PluginOptions], ) -> Result<()> { Ok(()) } diff --git a/src/plugins/src/frontend.rs b/src/plugins/src/frontend.rs index e94b080c894c..e95ca2e4ecd1 100644 --- a/src/plugins/src/frontend.rs +++ b/src/plugins/src/frontend.rs @@ -18,10 +18,13 @@ use frontend::error::{IllegalAuthConfigSnafu, Result}; use frontend::frontend::FrontendOptions; use snafu::ResultExt; +use crate::options::PluginOptions; + #[allow(unused_mut)] pub async fn setup_frontend_plugins( plugins: &mut Plugins, fe_opts: &FrontendOptions, + _plugin_options: &[PluginOptions], ) -> Result<()> { if let Some(user_provider) = fe_opts.user_provider.as_ref() { let provider = diff --git a/src/plugins/src/lib.rs b/src/plugins/src/lib.rs index f0be0bd76352..a29ed0e4a8e7 100644 --- a/src/plugins/src/lib.rs +++ b/src/plugins/src/lib.rs @@ -15,7 +15,9 @@ mod datanode; mod frontend; mod meta_srv; +mod options; pub use datanode::{setup_datanode_plugins, start_datanode_plugins}; pub use frontend::{setup_frontend_plugins, start_frontend_plugins}; pub use meta_srv::{setup_metasrv_plugins, start_metasrv_plugins}; +pub use options::PluginOptions; diff --git a/src/plugins/src/meta_srv.rs b/src/plugins/src/meta_srv.rs index 97fadfabd5c1..8129debca60a 100644 --- a/src/plugins/src/meta_srv.rs +++ b/src/plugins/src/meta_srv.rs @@ -16,10 +16,13 @@ use common_base::Plugins; use meta_srv::error::Result; use meta_srv::metasrv::MetasrvOptions; +use crate::options::PluginOptions; + #[allow(unused_variables)] pub async fn setup_metasrv_plugins( _plugins: &mut Plugins, metasrv_opts: &MetasrvOptions, + plugin_options: &[PluginOptions], ) -> Result<()> { Ok(()) } diff --git a/src/plugins/src/options.rs b/src/plugins/src/options.rs new file mode 100644 index 000000000000..7eb0b3290343 --- /dev/null +++ b/src/plugins/src/options.rs @@ -0,0 +1,23 @@ +// Copyright 2023 Greptime Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct DummyOptions; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub enum PluginOptions { + Dummy(DummyOptions), +} From 735deb4c4177976e8c2f1fdfdc4ea3b738ba90d0 Mon Sep 17 00:00:00 2001 From: WenyXu Date: Thu, 24 Oct 2024 08:07:02 +0000 Subject: [PATCH 2/2] chore: apply suggestions from CR --- src/cmd/src/datanode.rs | 2 +- src/cmd/src/frontend.rs | 4 ++-- src/cmd/src/metasrv.rs | 2 +- src/cmd/src/standalone.rs | 6 +++--- src/plugins/src/datanode.rs | 2 +- src/plugins/src/frontend.rs | 2 +- src/plugins/src/meta_srv.rs | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/cmd/src/datanode.rs b/src/cmd/src/datanode.rs index fa9b196ce6b4..187bdbd7aa3a 100644 --- a/src/cmd/src/datanode.rs +++ b/src/cmd/src/datanode.rs @@ -275,7 +275,7 @@ impl StartCommand { let plugin_opts = opts.plugins; let opts = opts.component; let mut plugins = Plugins::new(); - plugins::setup_datanode_plugins(&mut plugins, &opts, &plugin_opts) + plugins::setup_datanode_plugins(&mut plugins, &plugin_opts, &opts) .await .context(StartDatanodeSnafu)?; diff --git a/src/cmd/src/frontend.rs b/src/cmd/src/frontend.rs index d11f64b0b62b..63b64a8ec22c 100644 --- a/src/cmd/src/frontend.rs +++ b/src/cmd/src/frontend.rs @@ -269,7 +269,7 @@ impl StartCommand { let plugin_opts = opts.plugins; let opts = opts.component; let mut plugins = Plugins::new(); - plugins::setup_frontend_plugins(&mut plugins, &opts, &plugin_opts) + plugins::setup_frontend_plugins(&mut plugins, &plugin_opts, &opts) .await .context(StartFrontendSnafu)?; @@ -473,7 +473,7 @@ mod tests { }; let mut plugins = Plugins::new(); - plugins::setup_frontend_plugins(&mut plugins, &fe_opts, &[]) + plugins::setup_frontend_plugins(&mut plugins, &[], &fe_opts) .await .unwrap(); diff --git a/src/cmd/src/metasrv.rs b/src/cmd/src/metasrv.rs index 7022c6ee35a5..b1167903671a 100644 --- a/src/cmd/src/metasrv.rs +++ b/src/cmd/src/metasrv.rs @@ -276,7 +276,7 @@ impl StartCommand { let plugin_opts = opts.plugins; let opts = opts.component; let mut plugins = Plugins::new(); - plugins::setup_metasrv_plugins(&mut plugins, &opts, &plugin_opts) + plugins::setup_metasrv_plugins(&mut plugins, &plugin_opts, &opts) .await .context(StartMetaServerSnafu)?; diff --git a/src/cmd/src/standalone.rs b/src/cmd/src/standalone.rs index c9d07bd9269d..a72aea3c9af9 100644 --- a/src/cmd/src/standalone.rs +++ b/src/cmd/src/standalone.rs @@ -450,11 +450,11 @@ impl StartCommand { let fe_opts = opts.frontend_options(); let dn_opts = opts.datanode_options(); - plugins::setup_frontend_plugins(&mut plugins, &fe_opts, &plugin_opts) + plugins::setup_frontend_plugins(&mut plugins, &plugin_opts, &fe_opts) .await .context(StartFrontendSnafu)?; - plugins::setup_datanode_plugins(&mut plugins, &dn_opts, &plugin_opts) + plugins::setup_datanode_plugins(&mut plugins, &plugin_opts, &dn_opts) .await .context(StartDatanodeSnafu)?; @@ -763,7 +763,7 @@ mod tests { }; let mut plugins = Plugins::new(); - plugins::setup_frontend_plugins(&mut plugins, &fe_opts, &[]) + plugins::setup_frontend_plugins(&mut plugins, &[], &fe_opts) .await .unwrap(); diff --git a/src/plugins/src/datanode.rs b/src/plugins/src/datanode.rs index 714e84bd53a2..60640f05f1f6 100644 --- a/src/plugins/src/datanode.rs +++ b/src/plugins/src/datanode.rs @@ -22,8 +22,8 @@ use crate::options::PluginOptions; #[allow(unused_mut)] pub async fn setup_datanode_plugins( plugins: &mut Plugins, - dn_opts: &DatanodeOptions, plugin_options: &[PluginOptions], + dn_opts: &DatanodeOptions, ) -> Result<()> { Ok(()) } diff --git a/src/plugins/src/frontend.rs b/src/plugins/src/frontend.rs index e95ca2e4ecd1..240e7a1582d8 100644 --- a/src/plugins/src/frontend.rs +++ b/src/plugins/src/frontend.rs @@ -23,8 +23,8 @@ use crate::options::PluginOptions; #[allow(unused_mut)] pub async fn setup_frontend_plugins( plugins: &mut Plugins, - fe_opts: &FrontendOptions, _plugin_options: &[PluginOptions], + fe_opts: &FrontendOptions, ) -> Result<()> { if let Some(user_provider) = fe_opts.user_provider.as_ref() { let provider = diff --git a/src/plugins/src/meta_srv.rs b/src/plugins/src/meta_srv.rs index 8129debca60a..282ac241c50f 100644 --- a/src/plugins/src/meta_srv.rs +++ b/src/plugins/src/meta_srv.rs @@ -21,8 +21,8 @@ use crate::options::PluginOptions; #[allow(unused_variables)] pub async fn setup_metasrv_plugins( _plugins: &mut Plugins, - metasrv_opts: &MetasrvOptions, plugin_options: &[PluginOptions], + metasrv_opts: &MetasrvOptions, ) -> Result<()> { Ok(()) }