Skip to main content

frontend/service_config/
otlp.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 serde::{Deserialize, Serialize};
16
17const DEFAULT_TRACE_INGEST_CHUNK_SIZE: usize = 128;
18
19#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
20#[serde(default)]
21pub struct OtlpOptions {
22    pub enable: bool,
23    /// Maximum spans per trace ingest chunk. Set to 0 to disable splitting.
24    pub trace_ingest_chunk_size: usize,
25}
26
27impl Default for OtlpOptions {
28    fn default() -> Self {
29        Self {
30            enable: true,
31            trace_ingest_chunk_size: DEFAULT_TRACE_INGEST_CHUNK_SIZE,
32        }
33    }
34}
35
36#[cfg(test)]
37mod tests {
38    use super::*;
39
40    #[test]
41    fn test_otlp_options() {
42        let default = OtlpOptions::default();
43        assert!(default.enable);
44        assert_eq!(
45            default.trace_ingest_chunk_size,
46            DEFAULT_TRACE_INGEST_CHUNK_SIZE
47        );
48
49        let options: OtlpOptions = toml::from_str("enable = false").unwrap();
50        assert!(!options.enable);
51        assert_eq!(
52            options.trace_ingest_chunk_size,
53            DEFAULT_TRACE_INGEST_CHUNK_SIZE
54        );
55
56        let options: OtlpOptions = toml::from_str("trace_ingest_chunk_size = 0").unwrap();
57        assert!(options.enable);
58        assert_eq!(options.trace_ingest_chunk_size, 0);
59    }
60}