Class: Gitlab::Metrics::Subscribers::ExternalHttp

Inherits:
ActiveSupport::Subscriber
  • Object
show all
Defined in:
lib/gitlab/metrics/subscribers/external_http.rb

Overview

Class for tracking the total time spent in external HTTP See more at gitlab.com/gitlab-org/labkit-ruby/-/blob/v0.14.0/lib/gitlab-labkit.rb#L18

Constant Summary collapse

DEFAULT_STATUS_CODE =
'undefined'
DETAIL_STORE =
:external_http_detail_store
COUNTER =
:external_http_count
DURATION =
:external_http_duration_s

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.detail_storeObject


17
18
19
# File 'lib/gitlab/metrics/subscribers/external_http.rb', line 17

def self.detail_store
  ::Gitlab::SafeRequestStore[DETAIL_STORE] ||= []
end

.durationObject


21
22
23
# File 'lib/gitlab/metrics/subscribers/external_http.rb', line 21

def self.duration
  Gitlab::SafeRequestStore[DURATION].to_f
end

.payloadObject


29
30
31
32
33
34
# File 'lib/gitlab/metrics/subscribers/external_http.rb', line 29

def self.payload
  {
    COUNTER => request_count,
    DURATION => duration
  }
end

.request_countObject


25
26
27
# File 'lib/gitlab/metrics/subscribers/external_http.rb', line 25

def self.request_count
  Gitlab::SafeRequestStore[COUNTER].to_i
end

Instance Method Details

#request(event) ⇒ Object


36
37
38
39
40
41
# File 'lib/gitlab/metrics/subscribers/external_http.rb', line 36

def request(event)
  payload = event.payload
  add_to_detail_store(event.time, payload)
  add_to_request_store(payload)
  expose_metrics(payload)
end