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