confium-coordinator 0.5.8

Distributed threshold signing coordinator: session orchestration, rate limiting, policy, metrics
Documentation
//! Prometheus alerting rules for the coordinator metrics.
//!
//! Generates a YAML file of Prometheus alerting rules covering the
//! most critical operational conditions. Import directly into
//! Prometheus via the rule_files configuration.

/// Generate the alerting rules as a YAML string.
pub fn generate_alerts_yaml() -> String {
    r#"# Confium coordinator alerting rules.
# Generated by confium-tc::coordinator::alerts.
groups:
  - name: confium-coordinator
    interval: 30s
    rules:
      - alert: ConfiumHighErrorRate
        expr: |
          rate(confium_aggregations_failed_total[5m])
          / clamp_min(rate(confium_aggregations_attempted_total[5m]), 0.001)
          > 0.1
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: "Aggregation error rate > 10%"
          description: "More than 10% of aggregation attempts are failing."

      - alert: ConfiumSessionsExpiredRate
        expr: rate(confium_sessions_expired_total[5m]) > 1
        for: 10m
        labels:
          severity: warning
        annotations:
          summary: "High session expiry rate"
          description: "More than 1 session/second expiring for 10 minutes."

      - alert: ConfiumNoActiveSigners
        expr: confium_registered_signers == 0
        for: 2m
        labels:
          severity: critical
        annotations:
          summary: "No registered signers"
          description: "Coordinator has no registered signers — cannot sign."

      - alert: ConfiumTooManyActiveSessions
        expr: confium_active_sessions > 50
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "Many active sessions"
          description: "More than 50 active sessions for 5 minutes."

      - alert: ConfiumSessionsAborted
        expr: rate(confium_sessions_aborted_total[5m]) > 0.5
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "Sessions being aborted"
          description: "More than 0.5 sessions/second being aborted."

      - alert: ConfiumCoordinatorDown
        expr: up{job="confium-coordinator"} == 0
        for: 1m
        labels:
          severity: critical
        annotations:
          summary: "Coordinator is down"
          description: "Prometheus cannot scrape the coordinator."
"#
    .to_string()
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn generates_non_empty_yaml() {
        let yaml = generate_alerts_yaml();
        assert!(!yaml.is_empty());
    }

    #[test]
    fn contains_alert_groups() {
        let yaml = generate_alerts_yaml();
        assert!(yaml.contains("groups:"));
        assert!(yaml.contains("confium-coordinator"));
    }

    #[test]
    fn has_high_error_rate_alert() {
        let yaml = generate_alerts_yaml();
        assert!(yaml.contains("ConfiumHighErrorRate"));
        assert!(yaml.contains("severity: critical"));
    }

    #[test]
    fn has_no_signers_alert() {
        let yaml = generate_alerts_yaml();
        assert!(yaml.contains("ConfiumNoActiveSigners"));
    }

    #[test]
    fn has_capacity_alert() {
        let yaml = generate_alerts_yaml();
        assert!(yaml.contains("ConfiumTooManyActiveSessions"));
    }

    #[test]
    fn has_coordinator_down_alert() {
        let yaml = generate_alerts_yaml();
        assert!(yaml.contains("ConfiumCoordinatorDown"));
    }

    #[test]
    fn all_alerts_have_summary() {
        let yaml = generate_alerts_yaml();
        let alert_count = yaml.matches("- alert:").count();
        let summary_count = yaml.matches("summary:").count();
        assert_eq!(
            alert_count, summary_count,
            "each alert should have a summary"
        );
    }

    #[test]
    fn all_alerts_have_for_clause() {
        let yaml = generate_alerts_yaml();
        let alert_count = yaml.matches("- alert:").count();
        let for_count = yaml.matches("for:").count();
        assert_eq!(
            alert_count, for_count,
            "each alert should have a 'for' clause"
        );
    }
}