Module: Gitlab::InstrumentationHelper

Extended by:
InstrumentationHelper
Included in:
GrapeLogging::Loggers::PerfLogger, InstrumentationHelper
Defined in:
lib/gitlab/instrumentation_helper.rb

Constant Summary collapse

DURATION_PRECISION =

microseconds

6

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.queue_duration_for_job(job) ⇒ Object

Returns the queuing duration for a Sidekiq job in seconds, as a float, if the `enqueued_at` field or `created_at` field is available.

  • If the job doesn't contain sufficient information, returns nil

  • If the job has a start time in the future, returns 0

  • If the job contains an invalid start time value, returns nil

Parameters:

  • job (Hash)

    a Sidekiq job, represented as a hash


66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/gitlab/instrumentation_helper.rb', line 66

def self.queue_duration_for_job(job)
  # Old gitlab-shell messages don't provide enqueued_at/created_at attributes
  enqueued_at = job['enqueued_at'] || job['created_at']
  return unless enqueued_at

  enqueued_at_time = convert_to_time(enqueued_at)
  return unless enqueued_at_time

  # Its possible that if theres clock-skew between two nodes
  # this value may be less than zero. In that event, we record the value
  # as zero.
  [elapsed_by_absolute_time(enqueued_at_time), 0].max.round(DURATION_PRECISION)
end

Instance Method Details

#add_instrumentation_data(payload) ⇒ Object


19
20
21
22
23
24
# File 'lib/gitlab/instrumentation_helper.rb', line 19

def add_instrumentation_data(payload)
  instrument_gitaly(payload)
  instrument_rugged(payload)
  instrument_redis(payload)
  instrument_elasticsearch(payload)
end

#instrument_elasticsearch(payload) ⇒ Object


48
49
50
51
52
53
54
55
56
57
# File 'lib/gitlab/instrumentation_helper.rb', line 48

def instrument_elasticsearch(payload)
  # Elasticsearch integration is only available in EE but instrumentation
  # only depends on the Gem which is also available in FOSS.
  elasticsearch_calls = Gitlab::Instrumentation::ElasticsearchTransport.get_request_count

  return if elasticsearch_calls == 0

  payload[:elasticsearch_calls] = elasticsearch_calls
  payload[:elasticsearch_duration_s] = Gitlab::Instrumentation::ElasticsearchTransport.query_time
end

#instrument_gitaly(payload) ⇒ Object


26
27
28
29
30
31
32
33
# File 'lib/gitlab/instrumentation_helper.rb', line 26

def instrument_gitaly(payload)
  gitaly_calls = Gitlab::GitalyClient.get_request_count

  return if gitaly_calls == 0

  payload[:gitaly_calls] = gitaly_calls
  payload[:gitaly_duration_s] = Gitlab::GitalyClient.query_time
end

#instrument_redis(payload) ⇒ Object


44
45
46
# File 'lib/gitlab/instrumentation_helper.rb', line 44

def instrument_redis(payload)
  payload.merge! ::Gitlab::Instrumentation::Redis.payload
end

#instrument_rugged(payload) ⇒ Object


35
36
37
38
39
40
41
42
# File 'lib/gitlab/instrumentation_helper.rb', line 35

def instrument_rugged(payload)
  rugged_calls = Gitlab::RuggedInstrumentation.query_count

  return if rugged_calls == 0

  payload[:rugged_calls] = rugged_calls
  payload[:rugged_duration_s] = Gitlab::RuggedInstrumentation.query_time
end

#keysObject


9
10
11
12
13
14
15
16
17
# File 'lib/gitlab/instrumentation_helper.rb', line 9

def keys
  @keys ||= [:gitaly_calls,
             :gitaly_duration_s,
             :rugged_calls,
             :rugged_duration_s,
             :elasticsearch_calls,
             :elasticsearch_duration_s,
             *::Gitlab::Instrumentation::Redis.known_payload_keys]
end