-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathconfig.rs
85 lines (77 loc) · 2.48 KB
/
config.rs
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
use std::{path::PathBuf, time::Duration};
use crate::drivers::{
docker::DockerDriverOptions, kubernetes::KubernetesDriverOptions,
process_compose::PCDriverOptions,
};
use serde::{Deserialize, Serialize};
use figment::{
providers::{Env, Format, Serialized, Yaml},
Figment,
};
use tracing::info;
use url::Url;
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(tag = "type")]
pub enum WorkerDriverConfig {
Noop,
DockerDriver(DockerDriverOptions),
KubernetesDriver(KubernetesDriverOptions),
ProcessComposeDriver(PCDriverOptions),
}
#[derive(Debug, Deserialize, Serialize)]
pub struct OsrdyneConfig {
pub amqp_uri: String,
pub max_msg_size: i64,
pub management_uri: String,
pub pool_id: String,
pub worker_driver: WorkerDriverConfig,
pub worker_loop_interval: Duration,
pub default_message_ttl: Option<usize>,
pub max_length: Option<usize>,
pub max_length_bytes: Option<usize>,
pub api_address: String,
pub extra_lifetime: Option<Duration>,
pub opentelemetry: Option<OpentelemetryConfig>,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct OpentelemetryConfig {
pub endpoint: Url,
}
impl Default for OpentelemetryConfig {
fn default() -> Self {
Self {
endpoint: "http://jaeger:4317".parse().unwrap(),
}
}
}
impl Default for OsrdyneConfig {
fn default() -> Self {
Self {
amqp_uri: "amqp://osrd:password@osrd-rabbitmq:5672/%2f".into(),
max_msg_size: 1024 * 1024 * 128 * 5,
management_uri: "http://osrd:password@osrd-rabbitmq:15672".into(),
pool_id: "core".to_string(),
worker_driver: WorkerDriverConfig::Noop,
worker_loop_interval: Duration::from_millis(500),
default_message_ttl: None,
max_length: None,
max_length_bytes: None,
api_address: "0.0.0.0:4242".into(), // TODO: decide on the port
extra_lifetime: None,
opentelemetry: None,
}
}
}
pub fn parse_config(file: Option<PathBuf>) -> Result<OsrdyneConfig, figment::Error> {
let provider = if let Some(file) = file {
info!(file = %file.display(), "load configuration file");
Yaml::file_exact(file)
} else {
Yaml::file("osrdyne.yml")
};
Figment::from(Serialized::defaults(OsrdyneConfig::default()))
.merge(provider)
// We use `__` as a separator for nested keys
.merge(Env::prefixed("OSRDYNE__").split("__"))
.extract()
}