Commit c0e11351 authored by Takuya Noguchi's avatar Takuya Noguchi
Browse files

Update rubocop from 0.42.0 to 0.93.1


Signed-off-by: default avatarTakuya Noguchi <takninnovationresearch@gmail.com>
parent 0073b8e5
inherit_from: .rubocop_todo.yml
AllCops:
TargetRubyVersion: 2.3
TargetRubyVersion: 2.7
DisplayCopNames: true
# Just use double quotes please
......@@ -20,15 +22,15 @@ Style/RaiseArgs:
Style/FrozenStringLiteralComment:
Enabled: false
# Commonly used screens these days easily fit more than 80 characters.
Layout/LineLength:
Max: 120
Metrics/MethodLength:
Max: 15
Metrics/AbcSize:
Enabled: false
# Commonly used screens these days easily fit more than 80 characters.
Metrics/LineLength:
Max: 120
Metrics/ClassLength:
Max: 150
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2021-01-11 12:24:03 UTC using RuboCop version 0.93.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 1
# Configuration parameters: Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'gitlab-exporter.gemspec'
# Offense count: 3
Lint/AmbiguousBlockAssociation:
Exclude:
- 'spec/git_spec.rb'
- 'spec/util_spec.rb'
# Offense count: 2
# Configuration parameters: MaximumRangeSize.
Lint/MissingCopEnableDirective:
Exclude:
- 'spec/database/ci_builds_spec.rb'
- 'spec/git_process_proper_spec.rb'
# Offense count: 1
# Cop supports --auto-correct.
Lint/NonDeterministicRequireOrder:
Exclude:
- 'spec/spec_helper.rb'
# Offense count: 16
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 349
# Offense count: 1
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 8
# Offense count: 1
# Configuration parameters: IgnoredMethods.
Metrics/PerceivedComplexity:
Max: 9
# Offense count: 1
# Configuration parameters: EnforcedStyle, AllowModifiersOnSymbols.
# SupportedStyles: inline, group
Style/AccessModifierDeclarations:
Exclude:
- 'lib/gitlab_exporter/util.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods.
# AllowedMethods: present?, blank?, presence, try, try!
Style/SafeNavigation:
Exclude:
- 'lib/gitlab_exporter/database/base.rb'
......@@ -13,22 +13,24 @@ PATH
GEM
remote: https://rubygems.org/
specs:
ast (2.4.0)
ast (2.4.1)
connection_pool (2.2.2)
diff-lcs (1.3)
mustermann (1.0.3)
parser (2.5.1.0)
ast (~> 2.4.0)
parallel (1.20.1)
parser (3.0.0.0)
ast (~> 2.4.1)
pg (1.2.2)
powerpack (0.1.1)
quantile (0.2.1)
rack (2.0.7)
rack-protection (2.0.7)
rack
rainbow (2.1.0)
rainbow (3.0.0)
redis (4.1.3)
redis-namespace (1.6.0)
redis (>= 3.0.4)
regexp_parser (2.0.3)
rexml (3.2.4)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
......@@ -42,13 +44,18 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.1)
rubocop (0.42.0)
parser (>= 2.3.1.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
rubocop (0.93.1)
parallel (~> 1.10)
parser (>= 2.7.1.5)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8)
rexml
rubocop-ast (>= 0.6.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.8.1)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (1.4.0)
parser (>= 2.7.1.5)
ruby-progressbar (1.11.0)
sidekiq (5.2.7)
connection_pool (~> 2.2, >= 2.2.2)
rack (>= 1.5.0)
......@@ -60,7 +67,7 @@ GEM
rack-protection (= 2.0.7)
tilt (~> 2.0)
tilt (2.0.9)
unicode-display_width (1.6.0)
unicode-display_width (1.7.0)
PLATFORMS
ruby
......
#!/usr/bin/env ruby
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
require "optparse"
require "gitlab_exporter"
......
lib = File.expand_path("../lib", __FILE__)
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "gitlab_exporter/version"
......@@ -20,13 +20,13 @@ Gem::Specification.new do |s|
s.homepage = "http://gitlab.com"
s.license = "MIT"
s.add_runtime_dependency "connection_pool", "~> 2.2.1"
s.add_runtime_dependency "pg", "~> 1.1"
s.add_runtime_dependency "sinatra", "~> 2.0.4"
s.add_runtime_dependency "quantile", "~> 0.2.0"
s.add_runtime_dependency "sidekiq", "~> 5.2.1"
s.add_runtime_dependency "redis", "~> 4.1.2"
s.add_runtime_dependency "redis-namespace", "~> 1.6.0"
s.add_runtime_dependency "connection_pool", "~> 2.2.1"
s.add_runtime_dependency "sidekiq", "~> 5.2.1"
s.add_runtime_dependency "sinatra", "~> 2.0.4"
s.add_development_dependency "rspec", "~> 3.7.0"
s.add_development_dependency "rspec-expectations", "~> 3.7.0"
......
......@@ -19,8 +19,7 @@ module GitLab
# Empty runner that will raise an InvalidCLICommand when executed to provide the usage
# in the exception message
class NullRunner
def initialize(args)
end
def initialize(args); end
def run
fail InvalidCLICommand.new("Usage: #{EXECUTABLE_NAME} <command> [options] [arguments...]\n\n"\
......
......@@ -31,14 +31,12 @@ module GitLab
def with_connection_pool
connection_pool.with do |conn|
begin
yield conn
rescue PG::UnableToSend => e
@logger.warn "Error sending to the database: #{e}" if @logger
conn.reset
raise e
end
end
rescue PG::Error => e
@logger.error "Error connecting to the database: #{e}" if @logger
raise e
......
......@@ -35,7 +35,7 @@ module GitLab
# Prober class to gather bloat metrics
class BloatProber
METRIC_KEYS = %w(bloat_ratio bloat_size extra_size real_size).freeze
METRIC_KEYS = %w[bloat_ratio bloat_size extra_size real_size].freeze
attr_reader :metrics, :collector, :bloat_types
......@@ -46,7 +46,7 @@ module GitLab
@metrics = metrics
@collector = collector
@collector.logger = logger
@bloat_types = opts[:bloat_types] || %i(btree table)
@bloat_types = opts[:bloat_types] || %i[btree table]
end
def probe_db
......
......@@ -391,6 +391,7 @@ module GitLab
def include_bool_if_row_defined(row, field)
return {} unless row[field.to_s]
{ field => row[field.to_s] == "t" ? "yes" : "no" }
end
......@@ -470,7 +471,7 @@ module GitLab
def add_ci_created_pending_builds(metric_name, value, labels)
add_metric_with_namespace_label(metric_name,
[:namespace, :shared_runners, :has_minutes],
%i[namespace shared_runners has_minutes],
value,
labels)
end
......@@ -505,8 +506,8 @@ module GitLab
def add_ci_running_builds(value, labels)
add_metric_with_namespace_label(
"ci_running_builds",
[:runner, :namespace, :runner_type, :scheduled,
:triggered, :mirror, :mirror_trigger_builds, :has_minutes],
%i[runner namespace runner_type scheduled
triggered mirror mirror_trigger_builds has_minutes],
value,
labels
)
......
......@@ -5,7 +5,7 @@ module GitLab
#
# It takes a connection string (e.g. "dbname=test port=5432")
class TupleStatsCollector < Base
COLUMNS = %w(relname seq_tup_read idx_tup_fetch n_tup_ins n_tup_upd n_tup_del n_tup_hot_upd n_dead_tup seq_scan)
COLUMNS = %w[relname seq_tup_read idx_tup_fetch n_tup_ins n_tup_upd n_tup_del n_tup_hot_upd n_dead_tup seq_scan]
.join(",")
QUERY = <<-SQL.freeze
SELECT #{COLUMNS}
......@@ -35,9 +35,11 @@ module GitLab
result.each do |table_name, tuple_stats|
tuple_stats.each do |column_name, value|
next if value.is_a?(Numeric)
@metrics.add("gitlab_database_stat_table_#{column_name}",
value.to_f,
table_name: table_name) unless value.is_a?(Numeric)
table_name: table_name)
end
end
......
......@@ -13,6 +13,7 @@ module GitLab
class Git
def initialize(repo)
fail "Repository #{repo} does not exists" unless Dir.exist? repo
@repo = repo
@tracker = TimeTracker.new
end
......@@ -35,6 +36,7 @@ module GitLab
def execute(command)
result = CommandResult.new(*Open3.capture2e(command, chdir: @repo))
fail "Command #{command} failed with status #{result.status}\n#{result.stdout}" if result.failed?
result
end
end
......@@ -96,7 +98,7 @@ module GitLab
Utils.pgrep("^git ").each do |pid|
process_cmd = begin
File.read("/proc/#{pid}/cmdline")
rescue
rescue StandardError
"" # Process file is gone (race condition)
end
subcommand = self.class.extract_subcommand(process_cmd)
......@@ -131,6 +133,7 @@ module GitLab
def self.extract_subcommand(cmd)
return if cmd.empty?
cmd_splitted = cmd.split("\u0000") # cmdline does not return it space-separated
cmd_splitted.shift # Because it's "git"
......
......@@ -87,7 +87,7 @@ module GitLab
end
end
end
rescue => e
rescue StandardError => e
puts "Error: #{e}"
@valid = false
create_memstats_not_available(totals)
......
......@@ -25,7 +25,7 @@ module GitLab
# Locked: 0 kB
# VmFlags: rd ex mr mw me dw sd
class Mapping
FIELDS = %w(size rss shared_clean shared_dirty private_clean private_dirty swap pss).freeze
FIELDS = %w[size rss shared_clean shared_dirty private_clean private_dirty swap pss].freeze
attr_reader :address_start
attr_reader :address_end
......
......@@ -105,9 +105,7 @@ module GitLab
::GitLab::Exporter::MemStats::Mapping::FIELDS.each do |field|
value = stats.totals[field]
if value >= 0
@metrics.add("process_smaps_#{field}_bytes", value * 1024, @use_quantiles, **labels)
end
@metrics.add("process_smaps_#{field}_bytes", value * 1024, @use_quantiles, **labels) if value >= 0
end
end
......
......@@ -53,13 +53,12 @@ module GitLab
self
end
def probe_jobs # rubocop:disable Metrics/MethodLength
def probe_jobs
return self unless connected?
job_stats = {}
Sidekiq::Queue.all.each do |queue|
begin
Sidekiq.redis do |conn|
stats = conn.evalsha(QUEUE_JOB_STATS_SHA, ["queue:#{queue.name}"])
job_stats.merge!(stats.to_h)
......@@ -68,7 +67,6 @@ module GitLab
# FIXME: Should we call SCRIPT KILL?
return self
end
end
job_stats.each do |class_name, count|
@metrics.add("sidekiq_enqueued_jobs", count, name: class_name)
......@@ -153,7 +151,7 @@ module GitLab
end
true
end
rescue Redis::CannotConnectError, Redis::TimeoutError # rubocop:disable Lint/HandleExceptions
rescue Redis::CannotConnectError, Redis::TimeoutError
# Maybe we're trying connecting to a slave
end
......@@ -164,6 +162,7 @@ module GitLab
# Using administrative commands on conn directly (which is a Redis::Namespace)
# will be removed in redis-namespace 2.0.
next if conn.redis.script(:exists, QUEUE_JOB_STATS_SHA)
conn.redis.script(:load, QUEUE_JOB_STATS_SCRIPT)
end
end
......
......@@ -24,7 +24,7 @@ module GitLab
# Helper methods, some stuff was copied from ActiveSupport
module Utils
def camel_case_string(str)
str.gsub(/(?:_|^)([a-z\d]*)/i) { $1.capitalize } # rubocop:disable PerlBackrefs
str.gsub(/(?:_|^)([a-z\d]*)/i) { $1.capitalize } # rubocop:disable Style/PerlBackrefs
end
module_function :camel_case_string
......
......@@ -24,7 +24,7 @@ module GitLab
private
def memory_usage
io = IO.popen(%W(ps -o rss= -p #{$PID}))
io = IO.popen(%W[ps -o rss= -p #{$PID}])
mem = io.read
io.close
......
......@@ -26,7 +26,7 @@ describe GitLab::Exporter::Database::BloatCollector do
end
describe GitLab::Exporter::Database::BloatProber do
let(:opts) { { bloat_types: %i(btree table) } }
let(:opts) { { bloat_types: %i[btree table] } }
let(:metrics) { double("PrometheusMetrics", add: nil) }
let(:collector) { double("BloatCollector", run: data) }
......
require "spec_helper"
require "gitlab_exporter/database/ci_builds"
# rubocop:disable Metrics/LineLength
# rubocop:disable Layout/LineLength
describe GitLab::Exporter::Database do
let(:set_random_page_cost_query) { "SET random_page_cost" }
let(:builds_query_ee) { "SELECT BUILDS EE" }
......
require "spec_helper"
require "gitlab_exporter"
# rubocop:disable Metrics/LineLength
# rubocop:disable Layout/LineLength
describe GitLab::Exporter::GitProcessProber do
describe ".extract_subcommand" do
it "extract git subcommand" do
......
......@@ -14,11 +14,11 @@ describe GitLab::Exporter::MemStats do
it "parses the data properly" do
expect(subject.valid?).to be_truthy
nonzero_fields = %w(size rss shared_clean shared_dirty private_dirty pss)
zero_fields = %w(private_clean swap)
nonzero_fields = %w[size rss shared_clean shared_dirty private_dirty pss]
zero_fields = %w[private_clean swap]
nonzero_fields.each do |field|
expect(subject.totals[field]).to be > 0 # rubocop:disable Style/NumericPredicate
expect(subject.totals[field]).to be > 0
end
zero_fields.each do |field|
......
......@@ -51,11 +51,9 @@ class CLIArgs
yield self
end
def on(*args)
end
def on(*args); end
def banner=(banner)
end
def banner=(banner); end
def parse!
@arguments
......
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