diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-09-06 04:02:08 +0300 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-11-02 20:11:43 +0300 |
commit | 6db3151fa164d65d6176896301166c9883df1fe4 (patch) | |
tree | a39d5015455eba63c8613e87db102eb2ac901392 /lib/gitlab/metrics/subscribers | |
parent | c97dc61a9e3e203bc7a3315dd6828eda320b4323 (diff) |
Introduce missing Action concept
Diffstat (limited to 'lib/gitlab/metrics/subscribers')
-rw-r--r-- | lib/gitlab/metrics/subscribers/active_record.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/metrics/subscribers/rails_cache.rb | 44 |
2 files changed, 37 insertions, 11 deletions
diff --git a/lib/gitlab/metrics/subscribers/active_record.rb b/lib/gitlab/metrics/subscribers/active_record.rb index 15892c88e86..411f49456a6 100644 --- a/lib/gitlab/metrics/subscribers/active_record.rb +++ b/lib/gitlab/metrics/subscribers/active_record.rb @@ -8,14 +8,14 @@ module Gitlab def self.metric_sql_duration_seconds @metric_sql_duration_seconds ||= Gitlab::Metrics.histogram( :gitlab_sql_duration_seconds, - 'SQL duration seconds', + 'SQL time', {}, [0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.500, 2.0, 10.0] ) end def sql(event) - self.class.metric_sql_duration_secodnds.observe({}, event.duration/1000.0) + self.class.metric_sql_duration_secodnds.observe({}, event.duration / 1000.0) return unless current_transaction current_transaction.increment(:sql_duration, event.duration, false) diff --git a/lib/gitlab/metrics/subscribers/rails_cache.rb b/lib/gitlab/metrics/subscribers/rails_cache.rb index aaed2184f44..8eadb40a739 100644 --- a/lib/gitlab/metrics/subscribers/rails_cache.rb +++ b/lib/gitlab/metrics/subscribers/rails_cache.rb @@ -6,54 +6,80 @@ module Gitlab class RailsCache < ActiveSupport::Subscriber attach_to :active_support + def self.metric_cache_duration_seconds + @metric_cache_duration_seconds ||= Gitlab::Metrics.histogram( + :gitlab_cache_duration_seconds, + 'Cache access time', + { action: nil, operation: nil }, + [0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.500, 2.0, 10.0] + ) + end + + def self.metric_cache_read_hit_total + @metric_cache_read_hit_total ||= Gitlab::Metrics.counter(:gitlab_cache_read_hit_total, 'Cache read hit', { action: nil }) + end + + def self.metric_cache_read_miss_total + @metric_cache_read_miss_total ||= Gitlab::Metrics.counter(:gitlab_cache_read_miss_total, 'Cache read miss', { action: nil }) + end + def cache_read(event) - increment(:cache_read, event.duration) + observe(:read, event.duration) return unless current_transaction return if event.payload[:super_operation] == :fetch if event.payload[:hit] + self.class.metric_cache_read_hit_total.increment({ action: action }) current_transaction.increment(:cache_read_hit_count, 1) else + self.class.metric_cache_read_miss_total.increment({ action: action }) current_transaction.increment(:cache_read_miss_count, 1) end end def cache_write(event) - increment(:cache_write, event.duration) + observe(:write, event.duration) end def cache_delete(event) - increment(:cache_delete, event.duration) + observe(:delete, event.duration) end def cache_exist?(event) - increment(:cache_exists, event.duration) + observe(:exists, event.duration) end def cache_fetch_hit(event) return unless current_transaction + self.class.metric_cache_read_hit_total.increment({ action: action }) current_transaction.increment(:cache_read_hit_count, 1) end def cache_generate(event) return unless current_transaction + self.class.metric_cache_read_miss_total.increment({ action: action }) current_transaction.increment(:cache_read_miss_count, 1) end - def increment(key, duration) + def observe(key, duration) return unless current_transaction - current_transaction.increment(:cache_duration, duration) - current_transaction.increment(:cache_count, 1) - current_transaction.increment("#{key}_duration".to_sym, duration) - current_transaction.increment("#{key}_count".to_sym, 1) + metric_cache_duration_seconds.observe({ operation: key, action: action }, duration / 1000.1) + current_transaction.increment(:cache_duration, duration, false) + current_transaction.increment(:cache_count, 1, false) + current_transaction.increment("#{key}_duration".to_sym, duration, false) + current_transaction.increment("#{key}_count".to_sym, 1, false) end private + def action + current_transaction&.action + end + def current_transaction Transaction.current end |