Class: LlmCostTracker::Doctor::LegacyAuditCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/llm_cost_tracker/doctor/legacy_audit_check.rb

Constant Summary collapse

WARNING_PERCENT =
10

Instance Method Summary collapse

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/llm_cost_tracker/doctor/legacy_audit_check.rb', line 12

def call
  return unless Probe.table_exists?("llm_cost_tracker_calls")
  return unless LlmCostTracker::Call.column_names.include?("pricing_snapshot")

  counts = LlmCostTracker::Call
           .select(
             "COUNT(*) AS total_count, " \
             "COALESCE(SUM(CASE WHEN pricing_snapshot IS NULL THEN 1 ELSE 0 END), 0) AS missing_count"
           )
           .take
  total = counts.total_count.to_i
  return if total.zero?

  missing = counts.missing_count.to_i
  return unless (missing * 100) > (total * WARNING_PERCENT)

  message = "#{missing}/#{total} tracked calls lack pricing_snapshot; " \
            "stored totals remain stable but applied rates cannot be audited"
  Check.new(:warn, "pricing snapshot audit", message)
rescue StandardError
  nil
end