standalone/
options.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use common_base::readable_size::ReadableSize;
16use common_config::{Configurable, KvBackendConfig};
17use common_options::memory::MemoryOptions;
18use common_telemetry::logging::{LoggingOptions, SlowQueryOptions, TracingOptions};
19use common_wal::config::DatanodeWalConfig;
20use datanode::config::{DatanodeOptions, ProcedureConfig, RegionEngineConfig, StorageConfig};
21use file_engine::config::EngineConfig as FileEngineConfig;
22use flow::FlowConfig;
23use frontend::frontend::FrontendOptions;
24use frontend::service_config::{
25    InfluxdbOptions, JaegerOptions, MysqlOptions, OpentsdbOptions, PostgresOptions,
26    PromStoreOptions,
27};
28use mito2::config::MitoConfig;
29use query::options::QueryOptions;
30use serde::{Deserialize, Serialize};
31use servers::grpc::GrpcOptions;
32use servers::http::HttpOptions;
33
34#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
35#[serde(default)]
36pub struct StandaloneOptions {
37    pub enable_telemetry: bool,
38    pub default_timezone: Option<String>,
39    pub default_column_prefix: Option<String>,
40    pub http: HttpOptions,
41    pub grpc: GrpcOptions,
42    pub mysql: MysqlOptions,
43    pub postgres: PostgresOptions,
44    pub opentsdb: OpentsdbOptions,
45    pub influxdb: InfluxdbOptions,
46    pub jaeger: JaegerOptions,
47    pub prom_store: PromStoreOptions,
48    pub wal: DatanodeWalConfig,
49    pub storage: StorageConfig,
50    pub metadata_store: KvBackendConfig,
51    pub procedure: ProcedureConfig,
52    pub flow: FlowConfig,
53    pub logging: LoggingOptions,
54    pub user_provider: Option<String>,
55    /// Options for different store engines.
56    pub region_engine: Vec<RegionEngineConfig>,
57    pub tracing: TracingOptions,
58    pub init_regions_in_background: bool,
59    pub init_regions_parallelism: usize,
60    pub max_in_flight_write_bytes: Option<ReadableSize>,
61    pub slow_query: SlowQueryOptions,
62    pub query: QueryOptions,
63    pub memory: MemoryOptions,
64}
65
66impl Default for StandaloneOptions {
67    fn default() -> Self {
68        Self {
69            enable_telemetry: true,
70            default_timezone: None,
71            default_column_prefix: None,
72            http: HttpOptions::default(),
73            grpc: GrpcOptions::default(),
74            mysql: MysqlOptions::default(),
75            postgres: PostgresOptions::default(),
76            opentsdb: OpentsdbOptions::default(),
77            influxdb: InfluxdbOptions::default(),
78            jaeger: JaegerOptions::default(),
79            prom_store: PromStoreOptions::default(),
80            wal: DatanodeWalConfig::default(),
81            storage: StorageConfig::default(),
82            metadata_store: KvBackendConfig::default(),
83            procedure: ProcedureConfig::default(),
84            flow: FlowConfig::default(),
85            logging: LoggingOptions::default(),
86            user_provider: None,
87            region_engine: vec![
88                RegionEngineConfig::Mito(MitoConfig::default()),
89                RegionEngineConfig::File(FileEngineConfig::default()),
90            ],
91            tracing: TracingOptions::default(),
92            init_regions_in_background: false,
93            init_regions_parallelism: 16,
94            max_in_flight_write_bytes: None,
95            slow_query: SlowQueryOptions::default(),
96            query: QueryOptions::default(),
97            memory: MemoryOptions::default(),
98        }
99    }
100}
101
102impl Configurable for StandaloneOptions {
103    fn env_list_keys() -> Option<&'static [&'static str]> {
104        Some(&["wal.broker_endpoints"])
105    }
106}
107
108/// The [`StandaloneOptions`] is only defined in `standalone` crate,
109/// we don't want to make `frontend` depends on it, so impl [`Into`]
110/// rather than [`From`].
111#[allow(clippy::from_over_into)]
112impl Into<FrontendOptions> for StandaloneOptions {
113    fn into(self) -> FrontendOptions {
114        self.frontend_options()
115    }
116}
117
118impl StandaloneOptions {
119    pub fn frontend_options(&self) -> FrontendOptions {
120        let cloned_opts = self.clone();
121        FrontendOptions {
122            default_timezone: cloned_opts.default_timezone,
123            http: cloned_opts.http,
124            grpc: cloned_opts.grpc,
125            mysql: cloned_opts.mysql,
126            postgres: cloned_opts.postgres,
127            opentsdb: cloned_opts.opentsdb,
128            influxdb: cloned_opts.influxdb,
129            jaeger: cloned_opts.jaeger,
130            prom_store: cloned_opts.prom_store,
131            meta_client: None,
132            logging: cloned_opts.logging,
133            user_provider: cloned_opts.user_provider,
134            max_in_flight_write_bytes: cloned_opts.max_in_flight_write_bytes,
135            slow_query: cloned_opts.slow_query,
136            ..Default::default()
137        }
138    }
139
140    pub fn datanode_options(&self) -> DatanodeOptions {
141        let cloned_opts = self.clone();
142        DatanodeOptions {
143            node_id: Some(0),
144            enable_telemetry: cloned_opts.enable_telemetry,
145            wal: cloned_opts.wal,
146            storage: cloned_opts.storage,
147            region_engine: cloned_opts.region_engine,
148            grpc: cloned_opts.grpc,
149            init_regions_in_background: cloned_opts.init_regions_in_background,
150            init_regions_parallelism: cloned_opts.init_regions_parallelism,
151            query: cloned_opts.query,
152            ..Default::default()
153        }
154    }
155
156    /// Sanitize the `StandaloneOptions` to ensure the config is valid.
157    pub fn sanitize(&mut self) {
158        if self.storage.is_object_storage() {
159            self.storage
160                .store
161                .cache_config_mut()
162                .unwrap()
163                .sanitize(&self.storage.data_home);
164        }
165    }
166}