dboard 3.2.2 → 3.2.3

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: 5cf9252b64db369ffc253e270f6fffaf640b552dd6baf6afb46d19925a5d0141
4
- data.tar.gz: 9f531c357070278e600b2a31a7eb2a0020069d4aef969bab1bdb7ddbd3c50b2d
3
+ metadata.gz: a9931a1f53b9ace7790cebe3ea4ae8a63048f94a46060c39b331016c85c49d2a
4
+ data.tar.gz: eaf80b9f6c5d057a904308fe60c2f1408627d53b0f211a13b2c22ff594d23756
5
5
  SHA512:
6
- metadata.gz: e94447daf4a183474fa0648b56a85135618b7378dbc0bfa0251ac41eae69193e096f1a19f28c4cd092e49deeb063f6a19b4e677f1188a01a676e6ee29804d3e1
7
- data.tar.gz: d0faa64446c6544422d5bc235387c6981742190756118cd9a391439973cb2e9d4b5f7bdccca10355a64e122b0b5b6842ff3a124a4db080813cddb086388082f7
6
+ metadata.gz: a429b056de777feda66bf30e80c3341acb03ae4443bb8bbd8de8ed3d29870580a1749fa8c9adeff684fba463b2d3fdfae54b6ce55e8111bb10496b8d7693b42a
7
+ data.tar.gz: 15e09890a79432bdbff0a2297fd8c192393e0156f7829544da8cc9e0d5d6641e0064c8c504338298bb4bce22a2a5e1f11a289078d8d86662416b9800af2afdba
data/lib/collector.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "logging"))
1
2
  require File.expand_path(File.join(File.dirname(__FILE__), "publisher"))
2
3
  require "singleton"
3
4
 
@@ -103,8 +104,8 @@ module Dboard
103
104
  @after_update_callback.call
104
105
  end
105
106
  rescue Exception => ex
106
- puts "Failed to update #{source}: #{ex.message}"
107
- puts ex.backtrace
107
+ Dboard.logger.error("Failed to update #{source}: #{ex.message}")
108
+ Dboard.logger.error(ex.backtrace.join("\n"))
108
109
  @error_callback.call(ex)
109
110
  end
110
111
 
@@ -158,8 +159,8 @@ module Dboard
158
159
  break if cleared
159
160
  end
160
161
  rescue Exception => ex
161
- puts "Something failed in the update worker for #{key}: #{ex.message}"
162
- puts ex.backtrace
162
+ Dboard.logger.error("Something failed in the update worker for #{key}: #{ex.message}")
163
+ Dboard.logger.error(ex.backtrace.join("\n"))
163
164
  ensure
164
165
  @mutex.synchronize { @active[key] = false } unless cleared
165
166
  end
@@ -189,7 +190,7 @@ module Dboard
189
190
 
190
191
  started = monotonic_now
191
192
  update_source(source, instance, batch)
192
- puts [ "#{source} refreshed", describe_batch(batch), "in #{(monotonic_now - started).round(1)}s" ].compact.join(" ")
193
+ Dboard.logger.info([ "#{source} refreshed", describe_batch(batch), "in #{(monotonic_now - started).round(1)}s" ].compact.join(" "))
193
194
  true
194
195
  }
195
196
  end
data/lib/logging.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "logger"
2
+
3
+ module Dboard
4
+ class << self
5
+ attr_writer :logger
6
+
7
+ def logger
8
+ @logger ||= Logger.new($stdout)
9
+ end
10
+ end
11
+ end
data/lib/publisher.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "logging"))
1
2
  require "json"
2
3
 
3
4
  module Dboard
@@ -5,7 +6,7 @@ module Dboard
5
6
  def self.publish(source, data)
6
7
  Api::Client.post("/sources/#{source}", body: { data: data.to_json }, timeout: 10000)
7
8
  rescue SocketError => ex
8
- puts "SocketError: #{ex.message}"
9
+ Dboard.logger.error("SocketError: #{ex.message}")
9
10
  end
10
11
  end
11
12
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dboard
2
- VERSION = "3.2.2"
2
+ VERSION = "3.2.3"
3
3
  end
@@ -105,7 +105,6 @@ RSpec.describe Dboard::Collector do
105
105
  allow(new_relic).to receive(:fetch).and_raise(error)
106
106
  allow(callback).to receive(:call)
107
107
  allow(Dboard::Publisher).to receive(:publish)
108
- allow_any_instance_of(Dboard::Collector).to receive(:puts)
109
108
  Dboard::Collector.register_error_callback callback
110
109
 
111
110
  Dboard::Collector.instance.update_source(:new_relic, new_relic)
@@ -133,13 +132,13 @@ RSpec.describe Dboard::Collector do
133
132
  expect(Dboard::Publisher).to have_received(:publish).with(:new_relic, { db: "100%" })
134
133
  end
135
134
 
136
- it "prints out debugging info" do
135
+ it "logs debugging info" do
137
136
  allow(new_relic).to receive(:fetch).and_raise(Exception.new("some error"))
138
- allow(Dboard::Collector.instance).to receive(:puts)
137
+ allow(Dboard.logger).to receive(:error)
139
138
 
140
139
  Dboard::Collector.instance.update_source(:new_relic, new_relic)
141
140
 
142
- expect(Dboard::Collector.instance).to have_received(:puts).twice
141
+ expect(Dboard.logger).to have_received(:error).twice
143
142
  end
144
143
  end
145
144
 
@@ -148,7 +147,6 @@ RSpec.describe Dboard::Collector do
148
147
 
149
148
  before do
150
149
  reset_collector!
151
- allow(collector).to receive(:puts)
152
150
  allow(Dboard::Publisher).to receive(:publish)
153
151
  end
154
152
 
@@ -26,8 +26,11 @@ describe "Publisher", ".publish" do
26
26
 
27
27
  # 2021-12-07: No idea why we've treated this one specially, but keeping it for now.
28
28
  it "logs socket errors if we run out of retries" do
29
- expect(Dboard::Api::Client).to receive(:post).and_raise(SocketError.new("failed to connect"))
30
- expect(Dboard::Publisher).to receive(:puts).with("SocketError: failed to connect")
29
+ allow(Dboard::Api::Client).to receive(:post).and_raise(SocketError.new("failed to connect"))
30
+ allow(Dboard.logger).to receive(:error)
31
+
31
32
  Dboard::Publisher.publish(:new_relic, {})
33
+
34
+ expect(Dboard.logger).to have_received(:error).with("SocketError: failed to connect")
32
35
  end
33
36
  end
data/spec/spec_helper.rb CHANGED
@@ -11,3 +11,5 @@ require File.expand_path(File.join(File.dirname(__FILE__), "../lib/dboard"))
11
11
  Dboard::Api::Client.endpoints = [
12
12
  { base_uri: ENV["API_URL"], basic_auth: [ ENV["API_USER"], ENV["API_PASSWORD"] ] },
13
13
  ]
14
+
15
+ Dboard.logger = Logger.new(IO::NULL)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dboard
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.2
4
+ version: 3.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joakim Kolsjö
@@ -113,6 +113,7 @@ files:
113
113
  - lib/collector.rb
114
114
  - lib/config.rb
115
115
  - lib/dboard.rb
116
+ - lib/logging.rb
116
117
  - lib/publisher.rb
117
118
  - lib/version.rb
118
119
  - spec/collector_spec.rb