Commit 9d784a42 authored by Ryan Cobb's avatar Ryan Cobb

Reduce cardinality of http_request_duration initialization

parent ca4a2642
...@@ -3,8 +3,17 @@ ...@@ -3,8 +3,17 @@
module Gitlab module Gitlab
module Metrics module Metrics
class RequestsRackMiddleware class RequestsRackMiddleware
HTTP_METHODS = %w(delete get head options patch post put trace).freeze HTTP_METHODS = {
STATUSES = %w(200 301 304 400 401 403 404 500).freeze "delete" => %w(200 202 204 303 400 401 403 404 410 422 500 503),
"get" => %w(200 204 301 302 303 304 307 400 401 403 404 410 412 422 429 500 503),
"head" => %w(200 204 301 302 303 304 400 401 403 404 410 429 500 503),
"options" => %w(200 404),
"patch" => %w(200 202 204 400 403 404 409 416 422 500),
"post" => %w(200 201 202 204 301 302 303 304 400 401 403 404 406 409 410 412 413 415 422 429 500 503),
"propfind" => %w(404),
"put" => %w(200 202 204 400 401 403 404 405 406 409 410 415 422 500),
"report" => %w(404)
}.freeze
def initialize(app) def initialize(app)
@app = app @app = app
...@@ -24,8 +33,8 @@ module Gitlab ...@@ -24,8 +33,8 @@ module Gitlab
end end
def self.initialize_http_request_duration_seconds def self.initialize_http_request_duration_seconds
HTTP_METHODS.each do |method| HTTP_METHODS.each do |method, statuses|
STATUSES.each do |status| statuses.each do |status|
http_request_duration_seconds.get({ method: method, status: status }) http_request_duration_seconds.get({ method: method, status: status })
end end
end end
......
...@@ -67,8 +67,8 @@ describe Gitlab::Metrics::RequestsRackMiddleware do ...@@ -67,8 +67,8 @@ 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| described_class::HTTP_METHODS.each do |method, statuses|
described_class::STATUSES.each do |status| statuses.each do |status|
expected_labels << { method: method, status: status } expected_labels << { method: method, status: status }
end end
end end
......
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