agent_data_plane_config/domains/
multi_region_failover.rs

1//! Multi-Region Failover domain. Self-contained: it carries its own failover endpoint (`api_key`,
2//! `site`, `dd_url`), distinct from the primary forwarder endpoint in `shared.endpoints`.
3
4use serde::Serialize;
5
6/// Prefix of the Datadog failover-region metrics intake, completed by the failover site.
7const MRF_METRICS_ENDPOINT_PREFIX: &str = "https://app.mrf.";
8
9/// Resolved Multi-Region Failover configuration.
10#[derive(Clone, Debug, Default, PartialEq, Serialize)]
11pub struct Domain {
12    /// Whether multi-region failover is active.
13    pub enabled: bool,
14
15    /// Whether metrics are mirrored to the failover region.
16    pub failover_metrics: bool,
17
18    /// Metrics permitted to be sent to the failover region.
19    pub metric_allowlist: Vec<String>,
20
21    /// API key used to authenticate to the failover region.
22    pub api_key: Option<String>,
23
24    /// Datadog site of the failover region.
25    pub site: Option<String>,
26
27    /// Explicit intake URL for the failover region, overriding the site.
28    pub dd_url: Option<String>,
29}
30
31impl Domain {
32    /// Returns the failover-region metrics intake URL, if the region is addressable.
33    ///
34    /// [`dd_url`](Self::dd_url) takes precedence and is used as provided. When only
35    /// [`site`](Self::site) is set, the Datadog failover metrics intake is derived from it. Neither
36    /// setting has a default, so a failover region that is configured with neither has no endpoint.
37    pub fn metrics_endpoint_url(&self) -> Option<String> {
38        self.dd_url.clone().or_else(|| {
39            self.site
40                .as_deref()
41                .map(|site| format!("{MRF_METRICS_ENDPOINT_PREFIX}{site}"))
42        })
43    }
44}
45
46#[cfg(test)]
47mod tests {
48    use super::Domain;
49
50    #[test]
51    fn dd_url_takes_precedence_over_site() {
52        let domain = Domain {
53            site: Some("datadoghq.eu".to_string()),
54            dd_url: Some("https://custom-mrf.example.com".to_string()),
55            ..Default::default()
56        };
57
58        assert_eq!(
59            Some("https://custom-mrf.example.com".to_string()),
60            domain.metrics_endpoint_url()
61        );
62    }
63
64    #[test]
65    fn the_site_derives_the_failover_metrics_intake() {
66        let domain = Domain {
67            site: Some("datadoghq.eu".to_string()),
68            ..Default::default()
69        };
70
71        assert_eq!(
72            Some("https://app.mrf.datadoghq.eu".to_string()),
73            domain.metrics_endpoint_url()
74        );
75    }
76
77    #[test]
78    fn a_region_configured_with_neither_setting_has_no_endpoint() {
79        assert_eq!(None, Domain::default().metrics_endpoint_url());
80    }
81}