use systemprompt_config::ConfigFingerprint;
use systemprompt_loader::{ServicesProvenance, ServicesRootBootstrap};
pub(super) const CONFIG_INFO: &str = "systemprompt_config_info";
pub(crate) fn current() -> Option<ConfigFingerprint> {
ConfigFingerprint::current(services_sha())
}
fn services_sha() -> Option<String> {
match ServicesRootBootstrap::get().map(|root| &root.provenance) {
Some(
ServicesProvenance::Fetched { composed_hash, .. }
| ServicesProvenance::LastGood { composed_hash, .. },
) => Some(composed_hash.clone()),
_ => None,
}
}
pub(super) fn describe() {
metrics::describe_gauge!(
CONFIG_INFO,
"1 for the configuration this replica runs (profile, secret names, services tree)"
);
}
pub(super) fn publish(last: &mut Option<ConfigFingerprint>) {
let Some(fingerprint) = current() else {
return;
};
if last.as_ref() == Some(&fingerprint) {
return;
}
if let Some(previous) = last.take() {
set(&previous, 0.0);
}
set(&fingerprint, 1.0);
*last = Some(fingerprint);
}
fn set(fingerprint: &ConfigFingerprint, value: f64) {
metrics::gauge!(
CONFIG_INFO,
"profile_sha" => fingerprint.profile_sha.clone(),
"secret_keys_sha" => fingerprint.secret_keys_sha.clone(),
"services_sha" => fingerprint.services_sha.clone().unwrap_or_default(),
"secrets_generation" => fingerprint.secrets_generation.to_string(),
)
.set(value);
}