Skip to main content

frontend/service_config/
prom_store.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 serde::{Deserialize, Serialize};
18
19#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
20pub struct PromStoreOptions {
21    pub enable: bool,
22    pub with_metric_engine: bool,
23    #[serde(default, with = "humantime_serde")]
24    pub pending_rows_flush_interval: Duration,
25    #[serde(default = "default_max_batch_rows")]
26    pub max_batch_rows: usize,
27    #[serde(default = "default_max_concurrent_flushes")]
28    pub max_concurrent_flushes: usize,
29    #[serde(default = "default_worker_channel_capacity")]
30    pub worker_channel_capacity: usize,
31    #[serde(default = "default_max_inflight_requests")]
32    pub max_inflight_requests: usize,
33}
34
35fn default_max_batch_rows() -> usize {
36    100_000
37}
38
39fn default_max_concurrent_flushes() -> usize {
40    256
41}
42
43fn default_worker_channel_capacity() -> usize {
44    65526
45}
46
47fn default_max_inflight_requests() -> usize {
48    3000
49}
50
51impl Default for PromStoreOptions {
52    fn default() -> Self {
53        Self {
54            enable: true,
55            with_metric_engine: true,
56            pending_rows_flush_interval: Duration::ZERO,
57            max_batch_rows: default_max_batch_rows(),
58            max_concurrent_flushes: default_max_concurrent_flushes(),
59            worker_channel_capacity: default_worker_channel_capacity(),
60            max_inflight_requests: default_max_inflight_requests(),
61        }
62    }
63}
64
65#[cfg(test)]
66mod tests {
67    use std::time::Duration;
68
69    use super::PromStoreOptions;
70    use crate::service_config::prom_store::{
71        default_max_batch_rows, default_max_concurrent_flushes, default_max_inflight_requests,
72        default_worker_channel_capacity,
73    };
74
75    #[test]
76    fn test_prom_store_options() {
77        let default = PromStoreOptions::default();
78        assert!(default.enable);
79        assert!(default.with_metric_engine);
80        assert_eq!(default.pending_rows_flush_interval, Duration::ZERO);
81        assert_eq!(default.max_batch_rows, default_max_batch_rows());
82        assert_eq!(
83            default.max_concurrent_flushes,
84            default_max_concurrent_flushes()
85        );
86        assert_eq!(
87            default.worker_channel_capacity,
88            default_worker_channel_capacity()
89        );
90        assert_eq!(
91            default.max_inflight_requests,
92            default_max_inflight_requests()
93        );
94    }
95}