Skip to main content

metric_engine/
config.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 std::time::Duration;
16
17use common_telemetry::warn;
18use serde::{Deserialize, Serialize};
19
20/// The default flush interval of the metadata region.
21pub(crate) const DEFAULT_FLUSH_METADATA_REGION_INTERVAL: Duration = Duration::from_secs(30);
22
23/// Configuration for the metric engine.
24#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
25pub struct EngineConfig {
26    /// The flush interval of the metadata region.
27    #[serde(
28        with = "humantime_serde",
29        default = "EngineConfig::default_flush_metadata_region_interval"
30    )]
31    pub flush_metadata_region_interval: Duration,
32}
33
34impl Default for EngineConfig {
35    fn default() -> Self {
36        Self {
37            flush_metadata_region_interval: DEFAULT_FLUSH_METADATA_REGION_INTERVAL,
38        }
39    }
40}
41
42impl EngineConfig {
43    fn default_flush_metadata_region_interval() -> Duration {
44        DEFAULT_FLUSH_METADATA_REGION_INTERVAL
45    }
46
47    /// Sanitizes the configuration.
48    pub fn sanitize(&mut self) {
49        if self.flush_metadata_region_interval.is_zero() {
50            warn!(
51                "Flush metadata region interval is zero, override with default value: {:?}. Disable metadata region flush is forbidden.",
52                DEFAULT_FLUSH_METADATA_REGION_INTERVAL
53            );
54            self.flush_metadata_region_interval = DEFAULT_FLUSH_METADATA_REGION_INTERVAL;
55        }
56    }
57}