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.
-
#cross_references ⇒ Object
readonly
Returns the value of attribute cross_references.
-
#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.
-
#related_fields ⇒ Object
readonly
Returns the value of attribute related_fields.
-
#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 |
#cross_references ⇒ Object (readonly)
Returns the value of attribute cross_references
13 14 15 |
# File 'lib/familia/horreum/management/audit_report.rb', line 13 def cross_references @cross_references 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 |
#related_fields ⇒ Object (readonly)
Returns the value of attribute related_fields
13 14 15 |
# File 'lib/familia/horreum/management/audit_report.rb', line 13 def @related_fields 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, or when related_fields / cross_references were skipped (nil). This lets callers distinguish "everything checked and clean" from "some dimensions were skipped".
58 59 60 61 62 |
# File 'lib/familia/horreum/management/audit_report.rb', line 58 def complete? multi_indexes.none? { |idx| idx[:status] == :not_implemented } && !.nil? && !cross_references.nil? 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. A multi-index entry in +foreign_owned_keys+ counts against health only without an +owner_key+: a key whose owner the audit did not check. A key with an owner is that record's data, which neither the rebuild nor a repair changes. A nil related_fields or cross_references means the dimension was not checked and does not affect health.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/familia/horreum/management/audit_report.rb', line 37 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? && idx[:missing].empty? && unchecked_foreign_keys(idx).empty? } && participations.all? { |p| p[:stale_members].empty? } && && cross_references_healthy? end |
#to_h ⇒ Object
Summary counts for quick inspection.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/familia/horreum/management/audit_report.rb', line 65 def to_h hash = { 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, missing: idx[:missing].size } entry[:foreign_owned_keys] = idx[:foreign_owned_keys].size if idx.key?(:foreign_owned_keys) entry[:status] = idx[:status] if idx[:status] entry }, participations: participations.map { |p| { collection_name: p[:collection_name], stale_members: p[:stale_members].size } }, } hash[:related_fields] = hash[:cross_references] = cross_references_to_h hash end |
#to_s ⇒ Object
Human-readable summary.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/familia/horreum/management/audit_report.rb', line 98 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 line = " multi_index :#{idx[:index_name]}: stale_members=#{idx[:stale_members].size}" \ " orphaned_keys=#{idx[:orphaned_keys].size} missing=#{idx[:missing].size}" line += " foreign_owned_keys=#{idx[:foreign_owned_keys].size}" if idx.key?(:foreign_owned_keys) lines << line end end participations.each do |p| lines << " participation :#{p[:collection_name]}: stale_members=#{p[:stale_members].size}" end lines.concat() lines.concat(cross_references_lines) lines.join("\n") end |