1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
910use std::collections::BTreeMap;
1112use mz_build_info::BuildInfo;
13use mz_ore::metric;
14use mz_ore::metrics::{MetricsRegistry, UIntGauge};
15use mz_ore::now::NowFn;
16use mz_sql::catalog::EnvironmentId;
17use prometheus::IntCounter;
1819mod backend;
20mod frontend;
21mod params;
22mod sync;
2324pub use backend::SystemParameterBackend;
25pub use frontend::SystemParameterFrontend;
26pub use params::{ModifiedParameter, SynchronizedParameters};
27pub use sync::system_parameter_sync;
2829/// A factory for [SystemParameterFrontend] instances.
30#[derive(Clone, Debug)]
31pub struct SystemParameterSyncConfig {
32/// The environment ID that should identify connected clients.
33env_id: EnvironmentId,
34/// Build info for the environment running this.
35build_info: &'static BuildInfo,
36/// Parameter sync metrics.
37metrics: Metrics,
38/// Function to return the current time.
39now_fn: NowFn,
40/// The SDK key.
41ld_sdk_key: String,
42/// A map from parameter names to LaunchDarkly feature keys
43 /// to use when populating the [SynchronizedParameters]
44 /// instance in [SystemParameterFrontend::pull].
45ld_key_map: BTreeMap<String, String>,
46}
4748impl SystemParameterSyncConfig {
49/// Construct a new [SystemParameterFrontend] instance.
50pub fn new(
51 env_id: EnvironmentId,
52 build_info: &'static BuildInfo,
53 registry: &MetricsRegistry,
54 now_fn: NowFn,
55 ld_sdk_key: String,
56 ld_key_map: BTreeMap<String, String>,
57 ) -> Self {
58Self {
59 env_id,
60 build_info,
61 metrics: Metrics::register_into(registry),
62 now_fn,
63 ld_sdk_key,
64 ld_key_map,
65 }
66 }
67}
6869#[derive(Debug, Clone)]
70pub(super) struct Metrics {
71pub last_cse_time_seconds: UIntGauge,
72pub last_sse_time_seconds: UIntGauge,
73pub params_changed: IntCounter,
74}
7576impl Metrics {
77pub(super) fn register_into(registry: &MetricsRegistry) -> Self {
78Self {
79 last_cse_time_seconds: registry.register(metric!(
80 name: "mz_parameter_frontend_last_cse_time_seconds",
81 help: "The last known time when the LaunchDarkly client sent an event to the LaunchDarkly server (as unix timestamp).",
82 )),
83 last_sse_time_seconds: registry.register(metric!(
84 name: "mz_parameter_frontend_last_sse_time_seconds",
85 help: "The last known time when the LaunchDarkly client received an event from the LaunchDarkly server (as unix timestamp).",
86 )),
87 params_changed: registry.register(metric!(
88 name: "mz_parameter_frontend_params_changed",
89 help: "The number of parameter changes pulled from the LaunchDarkly frontend.",
90 )),
91 }
92 }
93}