Class: VAProfile::Stats
- Inherits:
-
Object
- Object
- VAProfile::Stats
- Defined in:
- lib/va_profile/stats.rb
Constant Summary collapse
- STATSD_KEY_PREFIX =
'api.va_profile'
- FINAL_SUCCESS =
%w[COMPLETED_SUCCESS COMPLETED_NO_CHANGES_DETECTED].freeze
- FINAL_FAILURE =
%w[REJECTED COMPLETED_FAILURE].freeze
Class Method Summary collapse
- .bucket_for(status) ⇒ Object private
- .failure?(status) ⇒ Boolean private
- .final_status?(status) ⇒ Boolean private
-
.increment(*args) ⇒ Object
Triggers the associated StatsD.increment method for the VAProfile buckets that are initialized in the config/initializers/statsd.rb file.
-
.increment_exception(key) ⇒ Object
Increments the associated StatsD bucket with the passed in exception error key.
-
.increment_transaction_results(response, bucket1 = 'posts_and_puts') ⇒ Nil
If the passed response contains a transaction status that is in one of the final success or failure states, it increments the associated StatsD bucket.
- .status_in(response) ⇒ Object private
- .success?(status) ⇒ Boolean private
Class Method Details
.bucket_for(status) ⇒ Object (private)
68 69 70 71 72 73 74 |
# File 'lib/va_profile/stats.rb', line 68 def bucket_for(status) if success?(status) 'success' elsif failure?(status) 'failure' end end |
.failure?(status) ⇒ Boolean (private)
64 65 66 |
# File 'lib/va_profile/stats.rb', line 64 def failure?(status) FINAL_FAILURE.include? status end |
.final_status?(status) ⇒ Boolean (private)
56 57 58 |
# File 'lib/va_profile/stats.rb', line 56 def final_status?(status) status.present? && success?(status) || failure?(status) end |
.increment(*args) ⇒ Object
Triggers the associated StatsD.increment method for the VAProfile buckets that are initialized in the config/initializers/statsd.rb file.
19 20 21 22 23 |
# File 'lib/va_profile/stats.rb', line 19 def increment(*args) buckets = args.map(&:downcase).join('.') StatsD.increment("#{STATSD_KEY_PREFIX}.#{buckets}") end |
.increment_exception(key) ⇒ Object
Increments the associated StatsD bucket with the passed in exception error key.
46 47 48 |
# File 'lib/va_profile/stats.rb', line 46 def increment_exception(key) StatsD.increment("#{STATSD_KEY_PREFIX}.exceptions", tags: ["exception:#{key.downcase}"]) end |
.increment_transaction_results(response, bucket1 = 'posts_and_puts') ⇒ Nil
If the passed response contains a transaction status that is in one of the final success or failure states, it increments the associated StatsD bucket.
33 34 35 36 37 38 39 |
# File 'lib/va_profile/stats.rb', line 33 def increment_transaction_results(response, bucket1 = 'posts_and_puts') status = status_in(response) return unless final_status?(status) increment(bucket1, bucket_for(status)) end |
.status_in(response) ⇒ Object (private)
52 53 54 |
# File 'lib/va_profile/stats.rb', line 52 def status_in(response) response&.body&.dig('tx_status')&.upcase end |
.success?(status) ⇒ Boolean (private)
60 61 62 |
# File 'lib/va_profile/stats.rb', line 60 def success?(status) FINAL_SUCCESS.include? status end |