Class: Familia::Horreum::AuditReport
- Inherits:
-
Data
- Object
- Data
- Familia::Horreum::AuditReport
- Defined in:
- lib/familia/horreum/management/audit_report.rb
Overview
AuditReport wraps the results of a full health_check across all consistency dimensions: instances timeline, unique indexes, multi indexes, and participation collections.
Created by ManagementMethods#health_check, consumed by repair methods.
Instance Attribute Summary collapse
-
#audited_at ⇒ Object
readonly
Returns the value of attribute audited_at.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#instances ⇒ Object
readonly
Returns the value of attribute instances.
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
-
#multi_indexes ⇒ Object
readonly
Returns the value of attribute multi_indexes.
-
#participations ⇒ Object
readonly
Returns the value of attribute participations.
-
#unique_indexes ⇒ Object
readonly
Returns the value of attribute unique_indexes.
Instance Method Summary collapse
-
#complete? ⇒ Boolean
Returns true when every audit dimension was actually checked.
-
#healthy? ⇒ Boolean
Returns true when every audit dimension is clean.
-
#to_h ⇒ Object
Summary counts for quick inspection.
-
#to_s ⇒ Object
Human-readable summary.
Instance Attribute Details
#audited_at ⇒ Object (readonly)
Returns the value of attribute audited_at
13 14 15 |
# File 'lib/familia/horreum/management/audit_report.rb', line 13 def audited_at @audited_at end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration
13 14 15 |
# File 'lib/familia/horreum/management/audit_report.rb', line 13 def duration @duration end |
#instances ⇒ Object (readonly)
Returns the value of attribute instances
13 14 15 |
# File 'lib/familia/horreum/management/audit_report.rb', line 13 def instances @instances end |
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class
13 14 15 |
# File 'lib/familia/horreum/management/audit_report.rb', line 13 def model_class @model_class end |
#multi_indexes ⇒ Object (readonly)
Returns the value of attribute multi_indexes
13 14 15 |
# File 'lib/familia/horreum/management/audit_report.rb', line 13 def multi_indexes @multi_indexes end |
#participations ⇒ Object (readonly)
Returns the value of attribute participations
13 14 15 |
# File 'lib/familia/horreum/management/audit_report.rb', line 13 def participations @participations end |
#unique_indexes ⇒ Object (readonly)
Returns the value of attribute unique_indexes
13 14 15 |
# File 'lib/familia/horreum/management/audit_report.rb', line 13 def unique_indexes @unique_indexes end |
Instance Method Details
#complete? ⇒ Boolean
Returns true when every audit dimension was actually checked.
A report can be healthy but incomplete when stub dimensions (like multi-indexes) return :not_implemented. This lets callers distinguish "everything checked and clean" from "some dimensions were skipped".
43 44 45 |
# File 'lib/familia/horreum/management/audit_report.rb', line 43 def complete? multi_indexes.none? { |idx| idx[:status] == :not_implemented } end |
#healthy? ⇒ Boolean
Returns true when every audit dimension is clean.
Multi-indexes with status :not_implemented are skipped — they cannot be assessed, so they neither pass nor fail the health check.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/familia/horreum/management/audit_report.rb', line 26 def healthy? instances[:phantoms].empty? && instances[:missing].empty? && unique_indexes.all? { |idx| idx[:stale].empty? && idx[:missing].empty? } && multi_indexes.all? { |idx| next true if idx[:status] == :not_implemented idx[:stale_members].empty? && idx[:orphaned_keys].empty? } && participations.all? { |p| p[:stale_members].empty? } end |
#to_h ⇒ Object
Summary counts for quick inspection.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/familia/horreum/management/audit_report.rb', line 48 def to_h { model_class: model_class, audited_at: audited_at, healthy: healthy?, complete: complete?, duration: duration, instances: { count_timeline: instances[:count_timeline], count_scan: instances[:count_scan], phantoms: instances[:phantoms].size, missing: instances[:missing].size, }, unique_indexes: unique_indexes.map { |idx| { index_name: idx[:index_name], stale: idx[:stale].size, missing: idx[:missing].size } }, multi_indexes: multi_indexes.map { |idx| entry = { index_name: idx[:index_name], stale_members: idx[:stale_members].size, orphaned_keys: idx[:orphaned_keys].size } entry[:status] = idx[:status] if idx[:status] entry }, participations: participations.map { |p| { collection_name: p[:collection_name], stale_members: p[:stale_members].size } }, } end |
#to_s ⇒ Object
Human-readable summary.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/familia/horreum/management/audit_report.rb', line 76 def to_s lines = [] lines << "AuditReport for #{model_class} (#{healthy? ? 'HEALTHY' : 'UNHEALTHY'})" lines << " audited_at: #{Time.at(audited_at).utc} (#{duration.round(3)}s)" lines << " instances: timeline=#{instances[:count_timeline]} scan=#{instances[:count_scan]}" \ " phantoms=#{instances[:phantoms].size} missing=#{instances[:missing].size}" unique_indexes.each do |idx| lines << " unique_index :#{idx[:index_name]}: stale=#{idx[:stale].size} missing=#{idx[:missing].size}" end multi_indexes.each do |idx| if idx[:status] == :not_implemented lines << " multi_index :#{idx[:index_name]}: not_implemented" else lines << " multi_index :#{idx[:index_name]}: stale_members=#{idx[:stale_members].size}" \ " orphaned_keys=#{idx[:orphaned_keys].size}" end end participations.each do |p| lines << " participation :#{p[:collection_name]}: stale_members=#{p[:stale_members].size}" end lines.join("\n") end |