diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2020-10-15 18:00:06 +0300 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2020-10-16 13:03:08 +0300 |
commit | 4d8b5c2d0fbeb71236418acee10956622e13b755 (patch) | |
tree | 326bb87255eb56f33ba987756fb72b063ee481bf | |
parent | ae60852b9206c750140e03d95695945ade173aa2 (diff) |
Fix rubocop offenses
-rw-r--r-- | ruby/.rubocop_todo.yml | 1 | ||||
-rw-r--r-- | ruby/lib/gitaly_server/logging_interceptor.rb | 42 |
2 files changed, 23 insertions, 20 deletions
diff --git a/ruby/.rubocop_todo.yml b/ruby/.rubocop_todo.yml index 87453d9e6..b7b33a7d2 100644 --- a/ruby/.rubocop_todo.yml +++ b/ruby/.rubocop_todo.yml @@ -74,6 +74,7 @@ Lint/SuppressedException: # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods. Lint/UnusedMethodArgument: Exclude: + - 'lib/gitaly_server/logging_interceptor.rb' - 'lib/gitaly_server/sentry_interceptor.rb' - 'lib/gitlab/git/conflict/parser.rb' diff --git a/ruby/lib/gitaly_server/logging_interceptor.rb b/ruby/lib/gitaly_server/logging_interceptor.rb index 92ed8c4ff..ad5e644b5 100644 --- a/ruby/lib/gitaly_server/logging_interceptor.rb +++ b/ruby/lib/gitaly_server/logging_interceptor.rb @@ -1,12 +1,12 @@ # frozen_string_literal: truer -equire 'grpc' +require 'grpc' require 'active_support/core_ext/string/inflections' require 'json' module GitalyServer class LoggingInterceptor < GRPC::ServerInterceptor - CodeStrings = { + CODE_STRINGS = { GRPC::Core::StatusCodes::OK => 'OK', GRPC::Core::StatusCodes::CANCELLED => 'Canceled', GRPC::Core::StatusCodes::UNKNOWN => 'Unknown', @@ -36,8 +36,8 @@ module GitalyServer code = GRPC::Core::StatusCodes::OK yield - rescue => e - code = e.code if e.is_a?(GRPC::BadStatus) + rescue GRPC::BadStatus => e + code = e.code raise ensure log_request(method, call, code, start) @@ -48,8 +48,8 @@ module GitalyServer code = GRPC::Core::StatusCodes::OK yield - rescue => e - code = e.code if e.is_a?(GRPC::BadStatus) + rescue GRPC::BadStatus => e + code = e.code raise ensure log_request(method, call, code, start) @@ -60,8 +60,8 @@ module GitalyServer code = GRPC::Core::StatusCodes::OK yield - rescue => e - code = e.code if e.is_a?(GRPC::BadStatus) + rescue GRPC::BadStatus => e + code = e.code raise ensure log_request(method, call, code, start) @@ -69,8 +69,8 @@ module GitalyServer def bidi_streamer(requests: nil, call: nil, method: nil) yield - rescue => e - code = e.code if e.is_a?(GRPC::BadStatus) + rescue GRPC::BadStatus => e + code = e.code raise ensure log_request(method, call, code, start) @@ -79,16 +79,18 @@ module GitalyServer private def log_request(method, call, code, start) - log({ - type: 'gitaly-ruby', - duration: (Time.now - start).to_f, - code: CodeStrings[code] || code, - method: method.name.to_s.camelize, - service: method.owner.service_name, - pid: Process.pid, - correlation_id: call.metadata['x-gitlab-correlation-id'], - time: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%LZ') - }) + log( + { + type: 'gitaly-ruby', + duration: (Time.now - start).to_f, + code: CODE_STRINGS[code] || code, + method: method.name.to_s.camelize, + service: method.owner.service_name, + pid: Process.pid, + correlation_id: call.metadata['x-gitlab-correlation-id'], + time: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%LZ') + } + ) end def log(msg) |