spring_opendal/config.rs
1use schemars::JsonSchema;
2use serde::Deserialize;
3use spring::config::Configurable;
4use std::collections::HashMap;
5use std::fmt::{Display, Formatter};
6
7spring::submit_config_schema!("opendal", OpenDALConfig);
8
9#[derive(Debug, Configurable, Clone, JsonSchema, Deserialize)]
10#[config_prefix = "opendal"]
11pub struct OpenDALConfig {
12 /// [Services](opendal::Scheme) that OpenDAL supports
13 ///
14 /// According trait [opendal::Scheme::from_str] to set the config,
15 /// visit [opendal](https://docs.rs/opendal/latest/opendal/services/index.html) to learn more
16 ///
17 /// **Required**: Need enable feature like `services-{$scheme}`
18 pub scheme: String,
19
20 /// Different options for different [scheme](https://docs.rs/opendal/latest/opendal/services/index.html),
21 ///
22 /// **Optional**
23 pub options: Option<HashMap<String, String>>,
24
25 /// OpenDAL provides a variety of [layers](https://docs.rs/opendal/latest/opendal/layers/index.html)
26 ///
27 /// **Optional**: Need enable feature
28 pub layers: Option<Vec<Layers>>,
29}
30
31#[derive(Debug, Clone, JsonSchema, Deserialize)]
32pub enum Layers {
33 /// [OpenDAL ChaosLayer](https://docs.rs/opendal/latest/opendal/layers/struct.ChaosLayer.html)
34 ///
35 /// Enable feature: `layers-chaos`
36 Chaos { error_ratio: f64 },
37 /// [OpenDAL MetricsLayer](https://docs.rs/opendal/latest/opendal/layers/struct.MetricsLayer.html)
38 ///
39 /// Enable feature: `layers-metrics`
40 Metrics,
41 /// [OpenDAL MimeGuessLayer](https://docs.rs/opendal/latest/opendal/layers/struct.MimeGuessLayer.html)
42 ///
43 /// Enable feature: `layers-mime-guess`
44 MimeGuess,
45 /// [OpenDAL PrometheusLayer](https://docs.rs/opendal/latest/opendal/layers/struct.PrometheusLayer.html)
46 ///
47 /// Enable feature: `layers-prometheus`
48 Prometheus {
49 duration_seconds_buckets: Option<Vec<f64>>,
50 bytes_buckets: Option<Vec<f64>>,
51 },
52 /// [OpenDAL PrometheusClientLayer](https://docs.rs/opendal/latest/opendal/layers/struct.PrometheusClientLayer.html)
53 ///
54 /// Enable feature: `layers-prometheus-client`
55 PrometheusClient,
56 /// [OpenDAL FastraceLayer](https://docs.rs/opendal/latest/opendal/layers/struct.FastraceLayer.html)
57 ///
58 /// Enable feature: `layers-fastrace`
59 Fastrace,
60 /// [OpenDAL TracingLayer](https://docs.rs/opendal/latest/opendal/layers/struct.TracingLayer.html)
61 ///
62 /// Enable feature: `layers-tracing`
63 Tracing,
64 /// [OpenDAL OtelTraceLayer](https://docs.rs/opendal/latest/opendal/layers/struct.OtelTraceLayer.html)
65 ///
66 /// Enable feature: `layers-otel-trace`
67 OtelTrace,
68 /// [OpenDAL ThrottleLayer](https://docs.rs/opendal/latest/opendal/layers/struct.ThrottleLayer.html)
69 ///
70 /// Enable feature: `layers-throttle`
71 Throttle { bandwidth: u32, burst: u32 },
72 /// [OpenDAL AwaitTreeLayer](https://docs.rs/opendal/latest/opendal/layers/struct.AwaitTreeLayer.html)
73 ///
74 /// Enable feature: `layers-await-tree`
75 AwaitTree,
76 /// [OpenDAL AsyncBacktraceLayer](https://docs.rs/opendal/latest/opendal/layers/struct.AsyncBacktraceLayer.html)
77 ///
78 /// Enable feature: `layers-async-backtrace`
79 AsyncBacktrace,
80 /// [OpenDAL DtraceLayer](https://docs.rs/opendal/latest/opendal/layers/struct.DtraceLayer.html)
81 ///
82 /// On Linux and enable feature: `layers-dtrace`
83 Dtrace,
84}
85
86impl Display for Layers {
87 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
88 let lf = match self {
89 Layers::Chaos { .. } => "chaos",
90 Layers::Metrics => "metrics",
91 Layers::MimeGuess => "mimeGuess",
92 Layers::Prometheus { .. } => "prometheus",
93 Layers::PrometheusClient => "prometheus-client",
94 Layers::Fastrace => "fastrace",
95 Layers::Tracing => "tracing",
96 Layers::OtelTrace => "otel-trace",
97 Layers::Throttle { .. } => "throttle",
98 Layers::AwaitTree => "awaitTree",
99 Layers::AsyncBacktrace => "async-backtrace",
100 Layers::Dtrace => "dtrace",
101 };
102 write!(f, "{lf}")
103 }
104}