Skip to content

Commit 4127a49

Browse files
author
Jan Kunzmann
committed
check-mysql-replication-status: address RuboCop findings
1 parent f619d3b commit 4127a49

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

bin/check-mysql-replication-status.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class CheckMysqlReplicationStatus < Sensu::Plugin::Check::CLI
103103
option :lag_outlier_threshold,
104104
long: '--lag-outlier-threshold=VALUE',
105105
description: 'Lag threshold to trigger outlier protection',
106-
default: 100000,
106+
default: 100_000,
107107
proc: proc { |s| s.to_i }
108108

109109
option :lag_outlier_sleep,
@@ -117,8 +117,7 @@ class CheckMysqlReplicationStatus < Sensu::Plugin::Check::CLI
117117
description: 'Level to report lag outlier',
118118
default: :ok,
119119
proc: proc(&:to_sym),
120-
in: %i(ok warning critical)
121-
120+
in: %i[ok warning critical]
122121

123122
def detect_replication_status?(row)
124123
%w[
@@ -166,7 +165,7 @@ def query_slave_status(db)
166165
"SHOW SLAVE '#{db_conn}' STATUS"
167166
end
168167
result = db.query sql
169-
if result.nil? || result.size < 1
168+
if result.nil? || result.count == 0
170169
nil
171170
else
172171
result.fetch_hash
@@ -193,7 +192,7 @@ def ok_slave_message
193192
db_conn = config[:master_connection]
194193

195194
if db_conn.nil?
196-
"slave running: true"
195+
'slave running: true'
197196
else
198197
"master connection: #{db_conn}, slave running: true"
199198
end
@@ -203,7 +202,7 @@ def run
203202
db = open_connection
204203

205204
retries = config[:lag_outlier_retry]
206-
unknown "Invalid value for --lag-outlier-retry" if retries < 0
205+
unknown 'Invalid value for --lag-outlier-retry' if retries < 0
207206

208207
lag_outlier = 0
209208

@@ -233,7 +232,7 @@ def run
233232
critical message if config[:lag_outlier_report] == :critical
234233
warning message if config[:lag_outlier_report] == :warning
235234
else
236-
# TODO (breaking change): Thresholds are exclusive which is not consistent with all other checks
235+
# TODO: (breaking change) Thresholds are exclusive which is not consistent with all other checks
237236
critical message if replication_delay > config[:crit]
238237
warning message if replication_delay > config[:warn]
239238
end

test/check-mysql-replication-status_spec.rb

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
require_relative '../bin/check-mysql-replication-status'
3030
require_relative './spec_helper.rb'
3131

32+
# rubocop:disable Metrics/BlockLength
3233
describe CheckMysqlReplicationStatus do
3334
let(:checker) { described_class.new }
3435
let(:exit_code) { nil }
@@ -48,23 +49,23 @@ def checker.critical(*_args)
4849
end
4950

5051
[
51-
['Yes', 'Yes', 0, 0, 'ok'],
52-
['No', 'Yes', nil, 2, 'critical'],
53-
['Yes', 'No', nil, 2, 'critical'],
54-
['No', 'No', nil, 2, 'critical'],
55-
['Yes', 'Yes', 900, 0, 'ok'],
56-
['Yes', 'Yes', 901, 1, 'warning'],
52+
['Yes', 'Yes', 0, 0, 'ok'],
53+
['No', 'Yes', nil, 2, 'critical'],
54+
['Yes', 'No', nil, 2, 'critical'],
55+
['No', 'No', nil, 2, 'critical'],
56+
['Yes', 'Yes', 900, 0, 'ok'],
57+
['Yes', 'Yes', 901, 1, 'warning'],
5758
['Yes', 'Yes', 1800, 1, 'warning'],
5859
['Yes', 'Yes', 1801, 2, 'critical'],
5960
].each do |testdata|
6061
it "returns #{testdata[4]} for default thresholds" do
6162
slave_status_row = {
62-
"Slave_IO_State" => '',
63-
"Slave_IO_Running" => testdata[0],
64-
"Slave_SQL_Running" => testdata[1],
65-
"Last_IO_Error" => '',
66-
"Last_SQL_Error" => '',
67-
"Seconds_Behind_Master" => testdata[2]
63+
'Slave_IO_State' => '',
64+
'Slave_IO_Running' => testdata[0],
65+
'Slave_SQL_Running' => testdata[1],
66+
'Last_IO_Error' => '',
67+
'Last_SQL_Error' => '',
68+
'Seconds_Behind_Master' => testdata[2]
6869
}
6970
begin
7071
allow(checker).to receive(:open_connection) # do nothing
@@ -78,29 +79,29 @@ def checker.critical(*_args)
7879
end
7980

8081
[
81-
[ 0, 0, 'ok'],
82-
[99999, 2, 'critical'],
82+
[0, 0, 'ok'],
83+
[99_999, 2, 'critical'],
8384
].each do |testdata|
8485
it "sleeps with lag outlier protection and returns #{testdata[2]} for default thresholds" do
8586
checker.config[:lag_outlier_retry] = 1
8687
checker.config[:lag_outlier_sleep] = 10
8788

8889
slave_status_row = [
8990
{
90-
"Slave_IO_State" => '',
91-
"Slave_IO_Running" => 'Yes',
92-
"Slave_SQL_Running" => 'Yes',
93-
"Last_IO_Error" => '',
94-
"Last_SQL_Error" => '',
95-
"Seconds_Behind_Master" => 100000
91+
'Slave_IO_State' => '',
92+
'Slave_IO_Running' => 'Yes',
93+
'Slave_SQL_Running' => 'Yes',
94+
'Last_IO_Error' => '',
95+
'Last_SQL_Error' => '',
96+
'Seconds_Behind_Master' => 100_000
9697
},
9798
{
98-
"Slave_IO_State" => '',
99-
"Slave_IO_Running" => 'Yes',
100-
"Slave_SQL_Running" => 'Yes',
101-
"Last_IO_Error" => '',
102-
"Last_SQL_Error" => '',
103-
"Seconds_Behind_Master" => testdata[0]
99+
'Slave_IO_State' => '',
100+
'Slave_IO_Running' => 'Yes',
101+
'Slave_SQL_Running' => 'Yes',
102+
'Last_IO_Error' => '',
103+
'Last_SQL_Error' => '',
104+
'Seconds_Behind_Master' => testdata[0]
104105
}
105106
]
106107

0 commit comments

Comments
 (0)