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: ...@@ -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_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_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` | | `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_requests_total` | Counter | 9.4 | Rack request count | `method`, `status` |
| `http_request_duration_seconds` | Histogram | 9.4 | HTTP response time from rack middleware | `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_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_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` | | `gitlab_transaction_db_cached_count_total` | Counter | 13.1 | Counter for total number of cached SQL calls | `controller`, `action` |
......
...@@ -3,15 +3,7 @@ ...@@ -3,15 +3,7 @@
module Gitlab module Gitlab
module Metrics module Metrics
class RequestsRackMiddleware class RequestsRackMiddleware
HTTP_METHODS = { HTTP_METHODS = %w(delete get head options patch post put).to_set.freeze
"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
HEALTH_ENDPOINT = /^\/-\/(liveness|readiness|health|metrics)\/?$/.freeze HEALTH_ENDPOINT = /^\/-\/(liveness|readiness|health|metrics)\/?$/.freeze
...@@ -40,16 +32,14 @@ module Gitlab ...@@ -40,16 +32,14 @@ module Gitlab
end end
def self.initialize_http_request_duration_seconds def self.initialize_http_request_duration_seconds
HTTP_METHODS.each do |method, statuses| HTTP_METHODS.each do |method|
statuses.each do |status| http_request_duration_seconds.get({ method: method })
http_request_duration_seconds.get({ method: method, status: status.to_s })
end
end end
end end
def call(env) def call(env)
method = env['REQUEST_METHOD'].downcase method = env['REQUEST_METHOD'].downcase
method = 'INVALID' unless HTTP_METHODS.key?(method) method = 'INVALID' unless HTTP_METHODS.include?(method)
started = Time.now.to_f started = Time.now.to_f
health_endpoint = health_endpoint?(env['PATH_INFO']) health_endpoint = health_endpoint?(env['PATH_INFO'])
status = 'undefined' status = 'undefined'
...@@ -62,7 +52,7 @@ module Gitlab ...@@ -62,7 +52,7 @@ module Gitlab
feature_category = headers&.fetch(FEATURE_CATEGORY_HEADER, nil) feature_category = headers&.fetch(FEATURE_CATEGORY_HEADER, nil)
unless health_endpoint 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 end
[status, headers, body] [status, headers, body]
......
...@@ -32,7 +32,7 @@ RSpec.describe Gitlab::Metrics::RequestsRackMiddleware do ...@@ -32,7 +32,7 @@ RSpec.describe Gitlab::Metrics::RequestsRackMiddleware do
end end
it 'measures execution time' do 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) } Timecop.scale(3600) { subject.call(env) }
end end
...@@ -77,7 +77,7 @@ RSpec.describe Gitlab::Metrics::RequestsRackMiddleware do ...@@ -77,7 +77,7 @@ RSpec.describe Gitlab::Metrics::RequestsRackMiddleware do
it 'records the request duration' do it 'records the request duration' do
expect(described_class) expect(described_class)
.to receive_message_chain(:http_request_duration_seconds, :observe) .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) subject.call(env)
end end
...@@ -137,10 +137,8 @@ RSpec.describe Gitlab::Metrics::RequestsRackMiddleware do ...@@ -137,10 +137,8 @@ RSpec.describe Gitlab::Metrics::RequestsRackMiddleware do
describe '.initialize_http_request_duration_seconds' do describe '.initialize_http_request_duration_seconds' do
it "sets labels" do it "sets labels" do
expected_labels = [] expected_labels = []
described_class::HTTP_METHODS.each do |method, statuses| described_class::HTTP_METHODS.each do |method|
statuses.each do |status| expected_labels << { method: method }
expected_labels << { method: method, status: status.to_s }
end
end end
described_class.initialize_http_request_duration_seconds 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