Commit 909b501f authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'bvl-remove-status-from-histogram' into 'master'

Remove status from http_request_duration_seconds

See merge request gitlab-org/gitlab!45419
parents fc3dcdc6 78b0d7aa
......@@ -91,8 +91,8 @@ The following metrics are available:
| `gitlab_transaction_rails_queue_duration_total` | Counter | 9.4 | Measures latency between GitLab Workhorse forwarding a request to Rails | `controller`, `action` |
| `gitlab_transaction_view_duration_total` | Counter | 9.4 | Duration for views | `controller`, `action`, `view` |
| `gitlab_view_rendering_duration_seconds` | Histogram | 10.2 | Duration for views (histogram) | `controller`, `action`, `view` |
| `http_requests_total` | Counter | 9.4 | Rack request count | `method` |
| `http_request_duration_seconds` | Histogram | 9.4 | HTTP response time from rack middleware | `method`, `status` |
| `http_requests_total` | Counter | 9.4 | Rack request count | `method`, `status` |
| `http_request_duration_seconds` | Histogram | 9.4 | HTTP response time from rack middleware | `method` |
| `gitlab_transaction_db_count_total` | Counter | 13.1 | Counter for total number of SQL calls | `controller`, `action` |
| `gitlab_transaction_db_write_count_total` | Counter | 13.1 | Counter for total number of write SQL calls | `controller`, `action` |
| `gitlab_transaction_db_cached_count_total` | Counter | 13.1 | Counter for total number of cached SQL calls | `controller`, `action` |
......
......@@ -3,15 +3,7 @@
module Gitlab
module Metrics
class RequestsRackMiddleware
HTTP_METHODS = {
"delete" => %w(200 202 204 303 400 401 403 404 500 503),
"get" => %w(200 204 301 302 303 304 307 400 401 403 404 410 422 429 500 503),
"head" => %w(200 204 301 302 303 401 403 404 410 500),
"options" => %w(200 404),
"patch" => %w(200 202 204 400 403 404 409 416 500),
"post" => %w(200 201 202 204 301 302 303 304 400 401 403 404 406 409 410 412 422 429 500 503),
"put" => %w(200 202 204 400 401 403 404 405 406 409 410 422 500)
}.freeze
HTTP_METHODS = %w(delete get head options patch post put).to_set.freeze
HEALTH_ENDPOINT = /^\/-\/(liveness|readiness|health|metrics)\/?$/.freeze
......@@ -40,16 +32,14 @@ module Gitlab
end
def self.initialize_http_request_duration_seconds
HTTP_METHODS.each do |method, statuses|
statuses.each do |status|
http_request_duration_seconds.get({ method: method, status: status.to_s })
end
HTTP_METHODS.each do |method|
http_request_duration_seconds.get({ method: method })
end
end
def call(env)
method = env['REQUEST_METHOD'].downcase
method = 'INVALID' unless HTTP_METHODS.key?(method)
method = 'INVALID' unless HTTP_METHODS.include?(method)
started = Time.now.to_f
health_endpoint = health_endpoint?(env['PATH_INFO'])
status = 'undefined'
......@@ -62,7 +52,7 @@ module Gitlab
feature_category = headers&.fetch(FEATURE_CATEGORY_HEADER, nil)
unless health_endpoint
RequestsRackMiddleware.http_request_duration_seconds.observe({ method: method, status: status.to_s }, elapsed)
RequestsRackMiddleware.http_request_duration_seconds.observe({ method: method }, elapsed)
end
[status, headers, body]
......
......@@ -32,7 +32,7 @@ RSpec.describe Gitlab::Metrics::RequestsRackMiddleware do
end
it 'measures execution time' do
expect(described_class).to receive_message_chain(:http_request_duration_seconds, :observe).with({ status: '200', method: 'get' }, a_positive_execution_time)
expect(described_class).to receive_message_chain(:http_request_duration_seconds, :observe).with({ method: 'get' }, a_positive_execution_time)
Timecop.scale(3600) { subject.call(env) }
end
......@@ -77,7 +77,7 @@ RSpec.describe Gitlab::Metrics::RequestsRackMiddleware do
it 'records the request duration' do
expect(described_class)
.to receive_message_chain(:http_request_duration_seconds, :observe)
.with({ method: 'get', status: '200' }, a_positive_execution_time)
.with({ method: 'get' }, a_positive_execution_time)
subject.call(env)
end
......@@ -137,10 +137,8 @@ RSpec.describe Gitlab::Metrics::RequestsRackMiddleware do
describe '.initialize_http_request_duration_seconds' do
it "sets labels" do
expected_labels = []
described_class::HTTP_METHODS.each do |method, statuses|
statuses.each do |status|
expected_labels << { method: method, status: status.to_s }
end
described_class::HTTP_METHODS.each do |method|
expected_labels << { method: method }
end
described_class.initialize_http_request_duration_seconds
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment