Class: Eco::API::UseCases::GraphQL::Samples::Pages::Template::Deploy::DriftReport

Inherits:
Object
  • Object
show all
Defined in:
lib/eco/api/usecases/graphql/samples/pages/template/deploy/drift_report.rb

Overview

Post-deploy verification: did the applied delta == the intended delta?

After a deploy, re-read the target template and run a self-version diff (gem Diff::VersionDiff) between the PRE-deploy snapshot and the POST-deploy snapshot. That "applied delta" is then compared, op/kind/attribute-wise, against the "intended delta" (the changelog of the diff that produced the deploy batch).

We compare on a normalised signature per change (op + kind + attribute + before/after) rather than on Mongo ids, because a cross-object deploy re-homes ids on the target — the SHAPE of the change is what must match. Any change present in one side but not the other is reported honestly as drift; nothing is hand-waved as "close enough".

report = DriftReport.new( intended: source_diff, # the VersionDiff the deploy batch came from applied: Diff::VersionDiff.new(pre, post) # pre/post self-diff of the target ) report.match? # => true when applied delta == intended delta (shape-wise) report.missing # => intended changes NOT observed on the target (under-applied) report.unexpected # => changes observed on the target that were NOT intended (over/side-effect) report.report # => human summary for a ticket / log

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(intended:, applied:) ⇒ DriftReport

Returns a new instance of DriftReport.

Parameters:

  • intended (#changes)

    the source diff the deploy batch was synthesised from.

  • applied (#changes)

    the pre/post self-version diff of the deployed target.



28
29
30
31
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/drift_report.rb', line 28

def initialize(intended:, applied:)
  @intended = intended
  @applied  = applied
end

Instance Attribute Details

#appliedObject (readonly)

Returns the value of attribute applied.



24
25
26
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/drift_report.rb', line 24

def applied
  @applied
end

#intendedObject (readonly)

Returns the value of attribute intended.



24
25
26
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/drift_report.rb', line 24

def intended
  @intended
end

Instance Method Details

#match?Boolean

True when the applied delta exactly matches the intended delta (no drift either way).

Returns:

  • (Boolean)


44
45
46
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/drift_report.rb', line 44

def match?
  missing.empty? && unexpected.empty?
end

#missingObject

Signatures present in the intended delta but missing from the applied delta.



34
35
36
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/drift_report.rb', line 34

def missing
  @missing ||= (intended_signatures.keys - applied_signatures.keys).map { |sig| intended_signatures[sig] }
end

#reportObject



58
59
60
61
62
63
64
65
66
67
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/drift_report.rb', line 58

def report
  return 'DEPLOY VERIFY OK — applied delta matches intended delta.' if match?

  lines = ['DEPLOY DRIFT detected:']
  lines << "  Missing (intended but not applied): #{missing.size}"
  missing.each { |c| lines << "    - #{describe(c)}" }
  lines << "  Unexpected (applied but not intended): #{unexpected.size}"
  unexpected.each { |c| lines << "    + #{describe(c)}" }
  lines.join("\n")
end

#to_hObject



48
49
50
51
52
53
54
55
56
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/drift_report.rb', line 48

def to_h
  {
    match:      match?,
    intended:   intended_signatures.size,
    applied:    applied_signatures.size,
    missing:    missing.map { |c| describe(c) },
    unexpected: unexpected.map { |c| describe(c) }
  }
end

#unexpectedObject

Signatures present in the applied delta but not intended (side effects / over-apply).



39
40
41
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/drift_report.rb', line 39

def unexpected
  @unexpected ||= (applied_signatures.keys - intended_signatures.keys).map { |sig| applied_signatures[sig] }
end