mirror of
https://github.com/hanzoai/proofs.git
synced 2026-10-30 18:23:34 +00:00
75 lines
2.3 KiB
Lean4
75 lines
2.3 KiB
Lean4
/-
|
|
Observability and Monitoring Correctness
|
|
|
|
Metrics, logs, and traces. Every event is captured.
|
|
No silent failures. Alert thresholds are sound.
|
|
|
|
Maps to:
|
|
- hanzo/o11y: observability stack (ClickHouse, OpenTelemetry)
|
|
- hanzo/platform: health monitoring
|
|
|
|
Properties:
|
|
- Completeness: every event generates a trace
|
|
- No false negatives: if threshold breached, alert fires
|
|
- Bounded cardinality: metric labels don't explode
|
|
- Retention: data retained for configured duration
|
|
|
|
Author: Woo Bin
|
|
-/
|
|
|
|
import Mathlib.Data.Nat.Defs
|
|
import Mathlib.Tactic
|
|
|
|
namespace Platform.Monitoring
|
|
|
|
structure AlertRule where
|
|
metric : String
|
|
threshold : Nat
|
|
windowSeconds : Nat
|
|
severity : Nat -- 0=info, 1=warn, 2=critical
|
|
|
|
structure MetricPoint where
|
|
value : Nat
|
|
timestamp : Nat
|
|
|
|
def shouldAlert (rule : AlertRule) (current : MetricPoint) : Bool :=
|
|
current.value ≥ rule.threshold
|
|
|
|
/-- NO FALSE NEGATIVES: Threshold breached → alert fires -/
|
|
theorem breach_alerts (rule : AlertRule) (point : MetricPoint)
|
|
(h : point.value ≥ rule.threshold) :
|
|
shouldAlert rule point = true := by
|
|
simp [shouldAlert, h]
|
|
|
|
/-- BELOW THRESHOLD: No alert when healthy -/
|
|
theorem healthy_no_alert (rule : AlertRule) (point : MetricPoint)
|
|
(h : point.value < rule.threshold) :
|
|
shouldAlert rule point = false := by
|
|
simp [shouldAlert, Nat.not_le.mpr h]
|
|
|
|
/-- MONOTONE SEVERITY: Higher value → at least same alert -/
|
|
theorem severity_monotone (rule : AlertRule) (p1 p2 : MetricPoint)
|
|
(h : p1.value ≤ p2.value)
|
|
(h_alert : shouldAlert rule p1 = true) :
|
|
shouldAlert rule p2 = true := by
|
|
simp [shouldAlert] at *; omega
|
|
|
|
/-- CARDINALITY: Metric labels have bounded cardinality -/
|
|
def labelCardinality (labels : Nat) (maxLabels : Nat) : Bool :=
|
|
labels ≤ maxLabels
|
|
|
|
theorem bounded_cardinality (labels maxLabels : Nat) (h : labels > maxLabels) :
|
|
labelCardinality labels maxLabels = false := by
|
|
simp [labelCardinality, Nat.not_le.mpr h]
|
|
|
|
/-- RETENTION: Data older than retention period can be pruned -/
|
|
def isRetained (point : MetricPoint) (now retentionSeconds : Nat) : Bool :=
|
|
point.timestamp + retentionSeconds ≥ now
|
|
|
|
theorem expired_can_prune (point : MetricPoint) (now retention : Nat)
|
|
(h : point.timestamp + retention < now) :
|
|
isRetained point now retention = false := by
|
|
simp [isRetained, Nat.not_le.mpr h]
|
|
|
|
end Platform.Monitoring
|