1use std::collections::BTreeMap;
11use std::path::PathBuf;
12
13use mz_build_info::BuildInfo;
14use mz_ore::metric;
15use mz_ore::metrics::{MetricsRegistry, UIntGauge};
16use mz_ore::now::NowFn;
17use mz_sql::catalog::EnvironmentId;
18use prometheus::IntCounter;
19
20mod backend;
21mod frontend;
22mod params;
23mod sync;
24
25pub use backend::SystemParameterBackend;
26pub use frontend::SystemParameterFrontend;
27pub use params::{ModifiedParameter, SynchronizedParameters};
28pub use sync::system_parameter_sync;
29
30#[derive(Clone, Debug)]
32pub struct SystemParameterSyncConfig {
33 env_id: EnvironmentId,
35 build_info: &'static BuildInfo,
37 metrics: Metrics,
39 key_map: BTreeMap<String, String>,
43 backend_config: SystemParameterSyncClientConfig,
45}
46
47#[derive(Clone, Debug)]
48pub enum SystemParameterSyncClientConfig {
49 File {
50 path: PathBuf,
52 },
53 LaunchDarkly {
54 sdk_key: String,
56 now_fn: NowFn,
58 },
59}
60
61impl SystemParameterSyncClientConfig {
62 fn is_launch_darkly(&self) -> bool {
63 match &self {
64 Self::LaunchDarkly { .. } => true,
65 _ => false,
66 }
67 }
68}
69
70impl SystemParameterSyncConfig {
71 pub fn new(
73 env_id: EnvironmentId,
74 build_info: &'static BuildInfo,
75 registry: &MetricsRegistry,
76 key_map: BTreeMap<String, String>,
77 backend_config: SystemParameterSyncClientConfig,
78 ) -> Self {
79 Self {
80 env_id,
81 build_info,
82 metrics: Metrics::register_into(registry),
83 key_map,
84 backend_config,
85 }
86 }
87}
88
89#[derive(Debug, Clone)]
90pub(super) struct Metrics {
91 pub last_cse_time_seconds: UIntGauge,
92 pub last_sse_time_seconds: UIntGauge,
93 pub params_changed: IntCounter,
94}
95
96impl Metrics {
97 pub(super) fn register_into(registry: &MetricsRegistry) -> Self {
98 Self {
99 last_cse_time_seconds: registry.register(metric!(
100 name: "mz_parameter_frontend_last_cse_time_seconds",
101 help: "The last known time when the LaunchDarkly client sent an event to the LaunchDarkly server (as unix timestamp).",
102 )),
103 last_sse_time_seconds: registry.register(metric!(
104 name: "mz_parameter_frontend_last_sse_time_seconds",
105 help: "The last known time when the LaunchDarkly client received an event from the LaunchDarkly server (as unix timestamp).",
106 )),
107 params_changed: registry.register(metric!(
108 name: "mz_parameter_frontend_params_changed",
109 help: "The number of parameter changes pulled from the LaunchDarkly frontend.",
110 )),
111 }
112 }
113}