rill_export/
config.rs

1use rill_protocol::config::ConfigPatch;
2use rill_protocol::io::provider::PathPattern;
3use serde::Deserialize;
4use std::collections::HashSet;
5
6// TODO: Support no env vars for `ConfigPatch`
7pub static NODE: ConfigPatch<String> = ConfigPatch::new("VAR-NOT-SPECIFIED");
8
9///
10/// Config of exporters.
11#[derive(Deserialize, Debug)]
12pub struct ExportConfig {
13    /// Optional config for Prometheus
14    pub prometheus: Option<PrometheusConfig>,
15    /// Optional config for Graphite
16    pub graphite: Option<GraphiteConfig>,
17}
18
19impl Default for ExportConfig {
20    fn default() -> Self {
21        Self {
22            prometheus: None,
23            graphite: None,
24        }
25    }
26}
27
28impl ExportConfig {
29    // TODO: Use direct connections
30    /// Full url of the node
31    pub fn node_url(&self) -> String {
32        let host = NODE.get(|| None, || "localhost:9090".into());
33        format!("ws://{}/live/client", host)
34    }
35}
36
37/// Prometheus exporter config.
38#[derive(Deserialize, Debug)]
39pub struct PrometheusConfig {
40    // TODO: Deserialize paths here directly using `FromStr`
41    /// Patterns of paths.
42    pub paths: HashSet<PathPattern>,
43}
44
45/// Graphite exporter config.
46#[derive(Deserialize, Debug)]
47pub struct GraphiteConfig {
48    // TODO: Deserialize paths here directly using `FromStr`
49    /// Patterns of paths.
50    pub paths: HashSet<PathPattern>,
51    /// Interval of uploading the data to the server.
52    pub interval: Option<u64>,
53}