gitlab-fluent-plugin-redis-slowlog 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c1ce26c15184cd4542891a3175434b81ed44b295a6ffd2a8c96222d4fd16da8
4
- data.tar.gz: 632613b3d6b036a6f94c66bea02dc08d5dff119202b1614f5df4ff1efd3c1c58
3
+ metadata.gz: 1c64f62b09c3902e94875fa90ca310357fda747eb68960f81c28f4f0e566ed0d
4
+ data.tar.gz: 3ccbe9ea9af8e67dc6e0b226538494462889bedebb7e9706fb88efebf2001999
5
5
  SHA512:
6
- metadata.gz: aea063934370511db16b64743463868b909d4685c141e0d56365f2edb604688125851d815b5c241f0a721be42e17785aea0f6ce862e726b050e1812d70a0bd2a
7
- data.tar.gz: 99ff9bf22f51fc3b5d6bffc55db8c3979b67bc41a4ef0ba69bb4ab136332a6de938694f39a9f4fc4409a2f41dcfdcb84a14bc8aec6fc353544a14dd9578713c2
6
+ metadata.gz: 1c394e1220236241046c06ef56a7fb59e823e46a9d4fa0382b589b4d7af035b7d9832a5c3c2daa207341e368b9f208707ed502617bcd7c6c55de9cf2af253093
7
+ data.tar.gz: 3b03fe4132255c47dccfff8411a31bd94b5a41ceb3806e96f1fd6875963d68560f47a61180c683b700c5f96556e9b860f204ae78240aa7c910beccf753e8cd8c
@@ -4,6 +4,8 @@ require "redis"
4
4
  module Fluent
5
5
  module Plugin
6
6
  class RedisSlowlogInput < Fluent::Plugin::Input
7
+ helpers :thread
8
+
7
9
  Fluent::Plugin.register_input("redis_slowlog", self)
8
10
 
9
11
  Entry = Struct.new(:id, :timestamp, :exec_time_us, :command)
@@ -16,6 +18,7 @@ module Fluent
16
18
  config_param :password, :string, default: nil
17
19
  config_param :logsize, :integer, default: 128
18
20
  config_param :interval, :integer, default: 10
21
+ config_param :timeout, :integer, default: 2
19
22
 
20
23
  def configure(conf)
21
24
  super
@@ -25,7 +28,8 @@ module Fluent
25
28
  host: host,
26
29
  port: port,
27
30
  path: path,
28
- password: password
31
+ password: password,
32
+ timeout: timeout
29
33
  )
30
34
  end
31
35
 
@@ -38,7 +42,7 @@ module Fluent
38
42
  end
39
43
 
40
44
  self.watching = true
41
- self.watcher = Thread.new(&method(:watch))
45
+ self.watcher = thread_create(:redis_slowlog_watcher, &method(:watch))
42
46
  end
43
47
 
44
48
  def shutdown
@@ -57,10 +61,17 @@ module Fluent
57
61
  # Check the current id of the slowlog, and start logging from there
58
62
  current_log_id = get_slowlogs(1).first&.id || -1
59
63
 
60
- while watching
61
- sleep interval
62
-
63
- current_log_id = output(current_log_id)
64
+ begin
65
+ while watching
66
+ sleep interval
67
+
68
+ current_log_id = output(current_log_id)
69
+ end
70
+ rescue Redis::BaseError => e
71
+ msg = "Error fetching slowlogs: #{e.inspect}"
72
+ log.error(msg)
73
+ router.emit("#{tag}.error", Fluent::EventTime.new(Time.now.to_i), { "message" => msg })
74
+ retry
64
75
  end
65
76
  end
66
77
 
@@ -34,12 +34,13 @@ describe Fluent::Plugin::RedisSlowlogInput do
34
34
  path: "/path/to/redis.sock",
35
35
  host: "localhost",
36
36
  port: 1234,
37
- password: "5iveL!fe" }
37
+ password: "5iveL!fe",
38
+ timeout: 2 }
38
39
  end
39
40
 
40
41
  it "delegates all of them to redis-rb" do
41
42
  # In ruby 2.5+ this could be config.slice(*[])
42
- redis_params = config.select { |name, _| [:url, :path, :host, :port, :password].include?(name) }
43
+ redis_params = config.select { |name, _| [:url, :path, :host, :port, :password, :timeout].include?(name) }
43
44
 
44
45
  expect(Redis).to receive(:new).with(redis_params).and_return(fake_redis)
45
46
 
@@ -70,6 +71,9 @@ describe Fluent::Plugin::RedisSlowlogInput do
70
71
  end
71
72
 
72
73
  it "polls the slowlog with the configured interval and size" do
74
+ # thread_create startup
75
+ expect(plugin).to receive(:sleep).with(0.1).at_least(:once)
76
+ # core test
73
77
  expect(fake_redis).to receive(:slowlog).with("get", 1).ordered
74
78
  expect(plugin).to receive(:sleep).with(0).ordered
75
79
  expect(fake_redis).to receive(:slowlog).with("get", 10).ordered
@@ -82,6 +86,22 @@ describe Fluent::Plugin::RedisSlowlogInput do
82
86
  run
83
87
  end
84
88
 
89
+ it "retries when a connection error occurs" do
90
+ # thread_create startup
91
+ expect(plugin).to receive(:sleep).with(0.1).at_least(:once)
92
+ # core test
93
+ expect(fake_redis).to receive(:slowlog).with("get", 1).ordered
94
+ expect(plugin).to receive(:sleep).with(0).ordered
95
+ expect(fake_redis).to receive(:slowlog).with("get", 10).ordered.and_raise(Redis::ConnectionError)
96
+ expect(plugin).to receive(:sleep).with(0).ordered
97
+ expect(fake_redis).to receive(:slowlog).with("get", 10).ordered
98
+
99
+ # Limit to 2 cycles
100
+ allow(plugin).to receive(:watching).thrice.and_return(true, true, false)
101
+
102
+ run
103
+ end
104
+
85
105
  context "when the slowlog returns entries", :aggregate_failures do
86
106
  let(:startup_slowlog) { [[25637, 1590522108, 5, %w[SCAN 0]]] }
87
107
  let(:logged_slowlog) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-fluent-plugin-redis-slowlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Van Landuyt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-25 00:00:00.000000000 Z
11
+ date: 2020-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler