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
-
.buffering_duration_for_job(job) ⇒ Object
Returns the buffering duration for a Sidekiq job in seconds, as a float, if the ‘concurrency_limit_buffered_at` field is available.
-
.enqueue_latency_for_scheduled_job(job) ⇒ Object
Returns the time it took for a scheduled job to be enqueued in seconds, as a float, if the ‘scheduled_at` and `enqueued_at` fields are available.
-
.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.
- .round_elapsed_time(start, end_time = Time.now) ⇒ Object
Instance Method Summary collapse
- #add_instrumentation_data(payload) ⇒ Object
- #init_instrumentation_data ⇒ Object
- #instrument_active_record(payload) ⇒ Object
- #instrument_cpu(payload) ⇒ Object
- #instrument_elasticsearch(payload) ⇒ Object
- #instrument_exclusive_lock(payload) ⇒ Object
- #instrument_external_http(payload) ⇒ Object
- #instrument_gitaly(payload) ⇒ Object
- #instrument_global_search_api(payload) ⇒ Object
- #instrument_ldap(payload) ⇒ Object
- #instrument_load_balancing(payload) ⇒ Object
- #instrument_middleware_path_traversal_check(payload) ⇒ Object
- #instrument_pid(payload) ⇒ Object
- #instrument_rack_attack(payload) ⇒ Object
- #instrument_rate_limiting_gates(payload) ⇒ Object
- #instrument_redis(payload) ⇒ Object
- #instrument_thread_memory_allocations(payload) ⇒ Object
- #instrument_throttle(payload) ⇒ Object
- #instrument_uploads(payload) ⇒ Object
- #instrument_worker_id(payload) ⇒ Object
- #instrument_zoekt(payload) ⇒ Object
Class Method Details
.buffering_duration_for_job(job) ⇒ Object
Returns the buffering duration for a Sidekiq job in seconds, as a float, if the ‘concurrency_limit_buffered_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
185 186 187 188 189 190 191 192 193 |
# File 'lib/gitlab/instrumentation_helper.rb', line 185 def self.buffering_duration_for_job(job) buffered_at = job['concurrency_limit_buffered_at'] return unless buffered_at buffered_at_time = convert_to_time(buffered_at) return unless buffered_at_time round_elapsed_time(buffered_at_time) end |
.enqueue_latency_for_scheduled_job(job) ⇒ Object
Returns the time it took for a scheduled job to be enqueued in seconds, as a float, if the ‘scheduled_at` and `enqueued_at` fields are 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
202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/gitlab/instrumentation_helper.rb', line 202 def self.enqueue_latency_for_scheduled_job(job) scheduled_at = job['scheduled_at'] enqueued_at = job['enqueued_at'] return unless scheduled_at && enqueued_at scheduled_at_time = convert_to_time(scheduled_at) enqueued_at_time = convert_to_time(enqueued_at) return unless scheduled_at_time && enqueued_at_time round_elapsed_time(scheduled_at_time, enqueued_at_time) end |
.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
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/gitlab/instrumentation_helper.rb', line 167 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 round_elapsed_time(enqueued_at_time) end |
.round_elapsed_time(start, end_time = Time.now) ⇒ Object
216 217 218 219 220 221 |
# File 'lib/gitlab/instrumentation_helper.rb', line 216 def self.round_elapsed_time(start, end_time = Time.now) # It's possible that if there is 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(start, end_time), 0].max.round(DURATION_PRECISION) end |
Instance Method Details
#add_instrumentation_data(payload) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/gitlab/instrumentation_helper.rb', line 13 def add_instrumentation_data(payload) instrument_gitaly(payload) instrument_redis(payload) instrument_elasticsearch(payload) instrument_zoekt(payload) instrument_throttle(payload) instrument_active_record(payload) instrument_external_http(payload) instrument_rack_attack(payload) instrument_middleware_path_traversal_check(payload) instrument_cpu(payload) instrument_thread_memory_allocations(payload) instrument_load_balancing(payload) instrument_pid(payload) instrument_worker_id(payload) instrument_uploads(payload) instrument_rate_limiting_gates(payload) instrument_global_search_api(payload) instrument_ldap(payload) instrument_exclusive_lock(payload) end |
#init_instrumentation_data ⇒ Object
9 10 11 |
# File 'lib/gitlab/instrumentation_helper.rb', line 9 def init_instrumentation_data Gitlab::RequestContext.start_thread_context end |
#instrument_active_record(payload) ⇒ Object
84 85 86 87 88 |
# File 'lib/gitlab/instrumentation_helper.rb', line 84 def instrument_active_record(payload) db_counters = ::Gitlab::Metrics::Subscribers::ActiveRecord.db_counter_payload payload.merge!(db_counters) end |
#instrument_cpu(payload) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/gitlab/instrumentation_helper.rb', line 97 def instrument_cpu(payload) cpu_s = ::Gitlab::Metrics::System.thread_cpu_duration( ::Gitlab::RequestContext.instance.start_thread_cpu_time) payload[:cpu_s] = cpu_s.round(DURATION_PRECISION) if cpu_s end |
#instrument_elasticsearch(payload) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# 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 payload[:elasticsearch_timed_out_count] = Gitlab::Instrumentation::ElasticsearchTransport.get_timed_out_count end |
#instrument_exclusive_lock(payload) ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/gitlab/instrumentation_helper.rb', line 144 def instrument_exclusive_lock(payload) requested_count = Gitlab::Instrumentation::ExclusiveLock.requested_count return if requested_count == 0 payload.merge!(Gitlab::Instrumentation::ExclusiveLock.payload) end |
#instrument_external_http(payload) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/gitlab/instrumentation_helper.rb', line 71 def instrument_external_http(payload) external_http_count = Gitlab::Metrics::Subscribers::ExternalHttp.request_count return if external_http_count == 0 payload.merge! Gitlab::Metrics::Subscribers::ExternalHttp.payload end |
#instrument_gitaly(payload) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/gitlab/instrumentation_helper.rb', line 35 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_global_search_api(payload) ⇒ Object
132 133 134 |
# File 'lib/gitlab/instrumentation_helper.rb', line 132 def instrument_global_search_api(payload) payload.merge!(::Gitlab::Instrumentation::GlobalSearchApi.payload) end |
#instrument_ldap(payload) ⇒ Object
136 137 138 139 140 141 142 |
# File 'lib/gitlab/instrumentation_helper.rb', line 136 def instrument_ldap(payload) ldap_count = Gitlab::Metrics::Subscribers::Ldap.count return if ldap_count == 0 payload.merge! Gitlab::Metrics::Subscribers::Ldap.payload end |
#instrument_load_balancing(payload) ⇒ Object
118 119 120 121 122 |
# File 'lib/gitlab/instrumentation_helper.rb', line 118 def instrument_load_balancing(payload) load_balancing_payload = ::Gitlab::Metrics::Subscribers::LoadBalancing.load_balancing_payload payload.merge!(load_balancing_payload) end |
#instrument_middleware_path_traversal_check(payload) ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/gitlab/instrumentation_helper.rb', line 152 def instrument_middleware_path_traversal_check(payload) duration = ::Gitlab::Instrumentation::Middleware::PathTraversalCheck.duration return if duration == 0 payload.merge!(::Gitlab::Instrumentation::Middleware::PathTraversalCheck.payload) end |
#instrument_pid(payload) ⇒ Object
104 105 106 |
# File 'lib/gitlab/instrumentation_helper.rb', line 104 def instrument_pid(payload) payload[:pid] = Process.pid end |
#instrument_rack_attack(payload) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/gitlab/instrumentation_helper.rb', line 90 def instrument_rack_attack(payload) rack_attack_redis_count = ::Gitlab::Metrics::Subscribers::RackAttack.payload[:rack_attack_redis_count] return if rack_attack_redis_count == 0 payload.merge!(::Gitlab::Metrics::Subscribers::RackAttack.payload) end |
#instrument_rate_limiting_gates(payload) ⇒ Object
128 129 130 |
# File 'lib/gitlab/instrumentation_helper.rb', line 128 def instrument_rate_limiting_gates(payload) payload.merge!(::Gitlab::Instrumentation::RateLimitingGates.payload) 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_thread_memory_allocations(payload) ⇒ Object
112 113 114 115 116 |
# File 'lib/gitlab/instrumentation_helper.rb', line 112 def instrument_thread_memory_allocations(payload) counters = ::Gitlab::Memory::Instrumentation.measure_thread_memory_allocations( ::Gitlab::RequestContext.instance.thread_memory_allocations) payload.merge!(counters) if counters end |
#instrument_throttle(payload) ⇒ Object
79 80 81 82 |
# File 'lib/gitlab/instrumentation_helper.rb', line 79 def instrument_throttle(payload) safelist = Gitlab::Instrumentation::Throttle.safelist payload[:throttle_safelist] = safelist if safelist.present? end |
#instrument_uploads(payload) ⇒ Object
124 125 126 |
# File 'lib/gitlab/instrumentation_helper.rb', line 124 def instrument_uploads(payload) payload.merge! ::Gitlab::Instrumentation::Uploads.payload end |
#instrument_worker_id(payload) ⇒ Object
108 109 110 |
# File 'lib/gitlab/instrumentation_helper.rb', line 108 def instrument_worker_id(payload) payload[:worker_id] = ::Prometheus::PidProvider.worker_id end |
#instrument_zoekt(payload) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/gitlab/instrumentation_helper.rb', line 60 def instrument_zoekt(payload) # Zoekt integration is only available in EE but instrumentation # only depends on the Gem which is also available in FOSS. zoekt_calls = Gitlab::Instrumentation::Zoekt.get_request_count return if zoekt_calls == 0 payload[:zoekt_calls] = zoekt_calls payload[:zoekt_duration_s] = Gitlab::Instrumentation::Zoekt.query_time end |