dboard 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60c9af8ba57dc09e45ec0f39a2e8394705c4cfadd771f52210578438f4f64219
4
- data.tar.gz: d1422616d6c609c49cd32c1a88481ae929391d5d3d937cc81b5abb1e37457a90
3
+ metadata.gz: 7f55103d286932b6db32979de3f7716857da2ad42b7234681796fd9f814a9e09
4
+ data.tar.gz: 9ba897eddcbf09741ab43d07eb24d8da35071e7e4137e06c3be3afdf6bceaf46
5
5
  SHA512:
6
- metadata.gz: '091c5bebede637161ece4d905ec07acb12d018c2d7dde186bb427639edbebe43211393ea6279b9ec212f02cdaff847b9812d21e6f1e1bc98dd9dbf117d0ee33a'
7
- data.tar.gz: dcc00cb4d504f0911b19f68c98af3db66e76a4cef444a8efcbb0e1a8daaa2a281da11f12eb3ae132bee5c7b06c09e0e228c17b2ad1ad2af005e47d379d71c5b0
6
+ metadata.gz: 76034350ee61d117fcc963d8789b20cfdfd308f4c602313e9fd15f2f833e311e2bc7cf517361b409ab58a4ccd4e8589df6985fdeaafc7f5f9c1045ae89002a4c
7
+ data.tar.gz: 9738a25264c457fb50af8b7d9e7a96f3c8bda68b19fae10b64ce505d6a3b0c30df9bb0521f682847f8bfa76b145ae99879373581b15b934c35ed670aa247fd7a
data/Gemfile CHANGED
@@ -1,7 +1,11 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec
3
3
 
4
+ gem "net_http_timeout_errors"
5
+
4
6
  group :development, :test do
5
- gem "barsoom_utils", github: "barsoom/barsoom_utils"
7
+ gem "barsoom_utils"
8
+ gem "rspec"
6
9
  gem "rubocop"
10
+ gem "webmock"
7
11
  end
data/dboard.gemspec CHANGED
@@ -17,10 +17,9 @@ Gem::Specification.new do |s|
17
17
  s.files = `git ls-files`.split("\n")
18
18
  s.require_paths = [ "lib" ]
19
19
 
20
+ s.add_dependency "dalli"
20
21
  s.add_dependency "httparty"
21
- s.add_dependency "rake"
22
22
  s.add_dependency "json"
23
- s.add_dependency "dalli"
23
+ s.add_dependency "rake"
24
24
  s.add_dependency "sinatra"
25
- s.add_development_dependency "rspec", "~> 3.9"
26
25
  end
data/lib/api.rb CHANGED
@@ -3,6 +3,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), "collector.rb"))
3
3
  require "digest/md5"
4
4
  require "json"
5
5
  require "httparty"
6
+ require "net_http_timeout_errors"
6
7
 
7
8
  module Dboard
8
9
  class Api
@@ -11,6 +12,27 @@ module Dboard
11
12
 
12
13
  class Client
13
14
  include HTTParty
15
+
16
+ def self.post(...)
17
+ with_retries { super }
18
+ end
19
+
20
+ private
21
+
22
+ private_class_method \
23
+ def self.with_retries
24
+ remaining_attempts = 3
25
+
26
+ begin
27
+ remaining_attempts -= 1
28
+ yield
29
+ rescue *NetHttpTimeoutErrors.all
30
+ raise if remaining_attempts == 0
31
+
32
+ sleep((ENV["RACK_ENV"] == "test") ? 0 : 5)
33
+ retry
34
+ end
35
+ end
14
36
  end
15
37
 
16
38
  def self.get(params)
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dboard
2
- VERSION = "1.1.1"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
2
2
 
3
- describe Dboard::Collector, "register_source" do
3
+ describe Dboard::Collector, ".register_source" do
4
4
  before do
5
5
  Dboard::Collector.instance.sources.clear
6
6
  end
@@ -48,14 +48,14 @@ describe Dboard::Collector, "update_source" do
48
48
  Dboard::Collector.instance.sources.clear
49
49
  end
50
50
 
51
- it "should collect and publish data from sources" do
51
+ it "collects and publishes data from sources" do
52
52
  new_relic = double
53
53
  allow(new_relic).to receive(:fetch).and_return({ db: "100%" })
54
54
  expect(Dboard::Publisher).to receive(:publish).with(:new_relic, { db: "100%" })
55
55
  Dboard::Collector.instance.update_source(:new_relic, new_relic)
56
56
  end
57
57
 
58
- it "should print out debugging info" do
58
+ it "prints out debugging info" do
59
59
  new_relic = double
60
60
  allow(new_relic).to receive(:fetch).and_raise(Exception.new("some error"))
61
61
  expect(Dboard::Collector.instance).to receive(:puts).twice
@@ -1,12 +1,31 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
2
2
 
3
- describe "Publisher", "publish" do
4
- it "should send data to the dashboard server" do
3
+ describe "Publisher", ".publish" do
4
+ it "sends data to the dashboard server" do
5
5
  expect(Dboard::Api::Client).to receive(:post).with("/sources/new_relic", body: { data: { db: "80%" }.to_json }, timeout: 10000)
6
6
  Dboard::Publisher.publish(:new_relic, { db: "80%" })
7
7
  end
8
8
 
9
- it "should handle and log socket errors" do
9
+ it "retries network errors" do
10
+ stub_request(:post, "http://api.example/sources/new_relic").
11
+ to_timeout.times(2).
12
+ to_return({ body: "OK!" })
13
+
14
+ Dboard::Publisher.publish(:new_relic, {})
15
+ end
16
+
17
+ it "raises network errors if we run out of retries" do
18
+ stub_request(:post, "http://api.example/sources/new_relic").
19
+ to_timeout.times(3).
20
+ to_return({ body: "OK!" })
21
+
22
+ expect {
23
+ Dboard::Publisher.publish(:new_relic, {})
24
+ }.to raise_error(Net::OpenTimeout)
25
+ end
26
+
27
+ # 2021-12-07: No idea why we've treated this one specially, but keeping it for now.
28
+ it "logs socket errors if we run out of retries" do
10
29
  expect(Dboard::Api::Client).to receive(:post).and_raise(SocketError.new("failed to connect"))
11
30
  expect(Dboard::Publisher).to receive(:puts).with("SocketError: failed to connect")
12
31
  Dboard::Publisher.publish(:new_relic, {})
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require "rspec"
2
+ require 'webmock/rspec'
2
3
 
3
4
  ENV["RACK_ENV"] ||= "test"
4
- ENV["API_URL"] = "http://localhost:20843"
5
+ ENV["API_URL"] = "http://api.example"
5
6
  ENV["API_USER"] = "test"
6
7
  ENV["API_PASSWORD"] = "test"
7
8
 
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dboard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joakim Kolsjö
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-19 00:00:00.000000000 Z
11
+ date: 2021-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: httparty
14
+ name: dalli
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: httparty
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: dalli
56
+ name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: rspec
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '3.9'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '3.9'
97
83
  description: Dashboard framework
98
84
  email:
99
85
  - joakim.kolsjo@gmail.com
@@ -139,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
125
  - !ruby/object:Gem::Version
140
126
  version: '0'
141
127
  requirements: []
142
- rubygems_version: 3.2.28
128
+ rubygems_version: 3.2.32
143
129
  signing_key:
144
130
  specification_version: 4
145
131
  summary: Dashboard framework