diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2018-06-20 14:33:14 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2018-06-20 14:35:04 +0200 |
commit | d73e68deb55ea9a5b52facd2f701b9772c0717ac (patch) | |
tree | 4d23c87d5032197fabfe98ef7c15272d5c9d6155 /lib | |
parent | 1a0ee66275316109af1911f96651ca10be930e75 (diff) | |
download | gitlab-ce-d73e68deb55ea9a5b52facd2f701b9772c0717ac.tar.gz |
Limit the action suffixes in transaction metricslimit-metrics-content-type
There seem to be a lot of cases where the suffix of an action (e.g.
".html") is set to bogus data, such as "*/*" or entire URLs. This can
increase cardinality of our metrics, and isn't very useful for
monitoring and filtering. To work around this, we enforce a whitelist
containing a few suffixes we actually care about. Suffixes not supported
will be grouped under the action without a suffix. This means that a
request to "FooController#bar.jpeg" will be assigned to
"FooController#bar".
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/metrics/web_transaction.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/gitlab/metrics/web_transaction.rb b/lib/gitlab/metrics/web_transaction.rb index 3799aaebf1c..723ca576aab 100644 --- a/lib/gitlab/metrics/web_transaction.rb +++ b/lib/gitlab/metrics/web_transaction.rb @@ -3,6 +3,7 @@ module Gitlab class WebTransaction < Transaction CONTROLLER_KEY = 'action_controller.instance'.freeze ENDPOINT_KEY = 'api.endpoint'.freeze + ALLOWED_SUFFIXES = Set.new(%w[json js atom rss xml zip]) def initialize(env) super() @@ -32,9 +33,13 @@ module Gitlab # Devise exposes a method called "request_format" that does the below. # However, this method is not available to all controllers (e.g. certain # Doorkeeper controllers). As such we use the underlying code directly. - suffix = controller.request.format.try(:ref) + suffix = controller.request.format.try(:ref).to_s - if suffix && suffix != :html + # Sometimes the request format is set to silly data such as + # "application/xrds+xml" or actual URLs. To prevent such values from + # increasing the cardinality of our metrics, we limit the number of + # possible suffixes. + if suffix && ALLOWED_SUFFIXES.include?(suffix) action += ".#{suffix}" end |