pub const ACTIVE_WRITE_VERSION: &str = "tsoracle.schema.active_write_version";
pub const MIN_READABLE_VERSION: &str = "tsoracle.schema.min_readable_version";
pub const MAX_READABLE_VERSION: &str = "tsoracle.schema.max_readable_version";
pub const MIN_MEMBER_READ_CAPABILITY: &str = "tsoracle.schema.min_member_read_capability";
pub const PROPOSED_TOTAL: &str = "tsoracle.schema.format_version.proposed.total";
pub const COMMITTED_TOTAL: &str = "tsoracle.schema.format_version.committed.total";
pub const APPLIED_TOTAL: &str = "tsoracle.schema.format_version.applied.total";
pub const NOOP_MEMBERSHIP_SUBSET_TOTAL: &str =
"tsoracle.schema.format_version.noop_membership_subset.total";
pub const REJECTED_BY_GATE_TOTAL: &str = "tsoracle.schema.format_version.rejected_by_gate.total";
pub const NOOP_TARGET_OUT_OF_RANGE_TOTAL: &str =
"tsoracle.schema.format_version.noop_target_out_of_range.total";
#[cfg(feature = "metrics")]
pub fn record_active_write_version(version: u8) {
metrics::gauge!(ACTIVE_WRITE_VERSION).set(f64::from(version));
}
#[cfg(not(feature = "metrics"))]
pub fn record_active_write_version(_version: u8) {}
#[cfg(feature = "metrics")]
pub fn record_readable_bounds(min_readable: u8, max_readable: u8) {
metrics::gauge!(MIN_READABLE_VERSION).set(f64::from(min_readable));
metrics::gauge!(MAX_READABLE_VERSION).set(f64::from(max_readable));
}
#[cfg(not(feature = "metrics"))]
pub fn record_readable_bounds(_min_readable: u8, _max_readable: u8) {}
#[cfg(feature = "metrics")]
pub fn record_min_member_read_capability(min_member_max_readable: u8) {
metrics::gauge!(MIN_MEMBER_READ_CAPABILITY).set(f64::from(min_member_max_readable));
}
#[cfg(not(feature = "metrics"))]
pub fn record_min_member_read_capability(_min_member_max_readable: u8) {}
#[cfg(feature = "metrics")]
pub fn record_proposed() {
metrics::counter!(PROPOSED_TOTAL).increment(1);
}
#[cfg(not(feature = "metrics"))]
pub fn record_proposed() {}
#[cfg(feature = "metrics")]
pub fn record_committed() {
metrics::counter!(COMMITTED_TOTAL).increment(1);
}
#[cfg(not(feature = "metrics"))]
pub fn record_committed() {}
#[cfg(feature = "metrics")]
pub fn record_applied() {
metrics::counter!(APPLIED_TOTAL).increment(1);
}
#[cfg(not(feature = "metrics"))]
pub fn record_applied() {}
#[cfg(feature = "metrics")]
pub fn record_noop_membership_subset() {
metrics::counter!(NOOP_MEMBERSHIP_SUBSET_TOTAL).increment(1);
}
#[cfg(not(feature = "metrics"))]
pub fn record_noop_membership_subset() {}
#[cfg(feature = "metrics")]
pub fn record_rejected_by_gate() {
metrics::counter!(REJECTED_BY_GATE_TOTAL).increment(1);
}
#[cfg(not(feature = "metrics"))]
pub fn record_rejected_by_gate() {}
#[cfg(feature = "metrics")]
pub fn record_noop_target_out_of_range() {
metrics::counter!(NOOP_TARGET_OUT_OF_RANGE_TOTAL).increment(1);
}
#[cfg(not(feature = "metrics"))]
pub fn record_noop_target_out_of_range() {}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn metric_names_match_the_interface_contract() {
assert_eq!(ACTIVE_WRITE_VERSION, "tsoracle.schema.active_write_version");
assert_eq!(MIN_READABLE_VERSION, "tsoracle.schema.min_readable_version");
assert_eq!(MAX_READABLE_VERSION, "tsoracle.schema.max_readable_version");
assert_eq!(
MIN_MEMBER_READ_CAPABILITY,
"tsoracle.schema.min_member_read_capability"
);
assert_eq!(
PROPOSED_TOTAL,
"tsoracle.schema.format_version.proposed.total"
);
assert_eq!(
COMMITTED_TOTAL,
"tsoracle.schema.format_version.committed.total"
);
assert_eq!(
APPLIED_TOTAL,
"tsoracle.schema.format_version.applied.total"
);
assert_eq!(
NOOP_MEMBERSHIP_SUBSET_TOTAL,
"tsoracle.schema.format_version.noop_membership_subset.total"
);
assert_eq!(
REJECTED_BY_GATE_TOTAL,
"tsoracle.schema.format_version.rejected_by_gate.total"
);
assert_eq!(
NOOP_TARGET_OUT_OF_RANGE_TOTAL,
"tsoracle.schema.format_version.noop_target_out_of_range.total"
);
}
#[test]
fn emit_helpers_are_callable_without_metrics_feature() {
record_active_write_version(4);
record_readable_bounds(4, 4);
record_min_member_read_capability(4);
record_proposed();
record_committed();
record_applied();
record_noop_membership_subset();
record_rejected_by_gate();
record_noop_target_out_of_range();
}
}