Class: Necropsy::Diagnostics
- Inherits:
-
Object
- Object
- Necropsy::Diagnostics
- Defined in:
- lib/necropsy/diagnostics.rb
Constant Summary collapse
- FORMATS =
%i[human json].freeze
Instance Method Summary collapse
- #explain(node_id) ⇒ Object
-
#initialize(report) ⇒ Diagnostics
constructor
A new instance of Diagnostics.
- #render(payload, format: :human) ⇒ Object
- #why(node_id) ⇒ Object
Constructor Details
#initialize(report) ⇒ Diagnostics
Returns a new instance of Diagnostics.
9 10 11 12 13 |
# File 'lib/necropsy/diagnostics.rb', line 9 def initialize(report) raise Error, 'Reachability witnesses are unavailable for this report' unless report.reachability @report = report end |
Instance Method Details
#explain(node_id) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/necropsy/diagnostics.rb', line 28 def explain(node_id) node = graph.nodes[node_id] return missing_payload(node_id) unless node finding = report.findings.find { |candidate| candidate.node.id == node_id } return { 'status' => 'alive', 'node' => node.to_h } unless finding { 'status' => 'finding', 'node' => node.to_h, 'classification' => finding.classification.to_s, 'confidence' => finding.confidence.to_s, 'score' => finding.score, 'components' => finding.score_components.map(&:to_h), 'reasons' => finding.reasons } end |
#render(payload, format: :human) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/necropsy/diagnostics.rb', line 46 def render(payload, format: :human) normalized = format.to_sym raise Error, "Diagnostics support only human or json output, not #{format}" unless FORMATS.include?(normalized) return JSON.pretty_generate(payload) if normalized == :json render_human(payload) end |
#why(node_id) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/necropsy/diagnostics.rb', line 15 def why(node_id) node = graph.nodes[node_id] return missing_payload(node_id) unless node runtime_path = reachability.witness(node_id) return alive_payload(node, runtime_path, :runtime) if runtime_path test_path = reachability.witness(node_id, kind: :test) return alive_payload(node, test_path, :test) if test_path dead_payload(node) end |