airbrake_proxy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 217de27ac0dbe6950a84b4d67b65c3b0ce299b38
4
+ data.tar.gz: 16a0c84c604efb79377bb7a74a1ee1ab1c7b17aa
5
+ SHA512:
6
+ metadata.gz: a9be86792f14fe6a2b13c5c3d8466c0a0dd1ed9f8a1f157261f2e0a460084502760ad79c543607439be18080aebc83117dcdbe18d142b3f20b8b425291b47534
7
+ data.tar.gz: d15952b3dab5a36d14e9cd54310ba588ce036cd4113817f8b59f2f21834dd48884018265332d339885f14f6d6840fff664977fbfb9d68bf505f657c6366c1351
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --fail-fast
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ script: bundle exec rspec
3
+ rvm:
4
+ - 2.3.1
5
+ - 2.4.0
6
+ - ruby-head
7
+ matrix:
8
+ allow_failures:
9
+ - rvm: ruby-head
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ### VERSION 0.0.1
2
+
3
+ * nothing
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at joel.azemar@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in airbrake_proxy.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'mock_redis'
8
+ gem 'coveralls', require: false
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Joel AZEMAR
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # AirbrakeProxy
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/airbrake_proxy.svg)](http://badge.fury.io/rb/airbrake_proxy)
4
+
5
+ [![Code Climate](https://codeclimate.com/github/FinalCAD/airbrake_proxy.png)](https://codeclimate.com/github/FinalCAD/airbrake_proxy)
6
+
7
+ [![Dependency Status](https://gemnasium.com/FinalCAD/airbrake_proxy.png)](https://gemnasium.com/FinalCAD/airbrake_proxy)
8
+
9
+ [![Build Status](https://travis-ci.org/FinalCAD/airbrake_proxy.png?branch=master)](https://travis-ci.org/FinalCAD/airbrake_proxy) (Travis CI)
10
+
11
+ [![Coverage Status](https://coveralls.io/repos/FinalCAD/airbrake_proxy/badge.png)](https://coveralls.io/r/FinalCAD/airbrake_proxy)
12
+
13
+ Basic Circuit Breaker to attempt not reach Airbrake limit for the same exception
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'airbrake_proxy'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install airbrake_proxy
30
+
31
+ ## Usage
32
+
33
+
34
+ ## Development
35
+
36
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
+
38
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/airbrake_proxy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
43
+
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/UPGRADE.md ADDED
@@ -0,0 +1 @@
1
+ # Upgrading
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'airbrake_proxy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "airbrake_proxy"
8
+ spec.version = AirbrakeProxy::VERSION
9
+ spec.authors = ["Joel AZEMAR"]
10
+ spec.email = ["joel.azemar@gmail.com"]
11
+
12
+ spec.summary = %q{Basic Circuit Breaker for Airbrake}
13
+ spec.description = %q{Basic Circuit Breaker to attempt not reach Airbrake limit for the same exception}
14
+ spec.homepage = "https://github.com/FinalCAD/airbrake_proxy"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "airbrake", "~> 5.6"
26
+ spec.add_development_dependency "activesupport", "~> 4.2"
27
+ spec.add_development_dependency "time_constants", "~> 0.2"
28
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "airbrake_proxy"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ require 'securerandom'
2
+
3
+ module AirbrakeProxy
4
+ class Configuration
5
+ attr_accessor :redis, :logger
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ require_relative 'configuration'
2
+
3
+ module AirbrakeProxy
4
+ module Configure
5
+
6
+ attr_writer :configuration
7
+
8
+ def configuration
9
+ @configuration ||= Configuration.new
10
+ end
11
+
12
+ def configure
13
+ yield(configuration)
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ module RedisProxy
2
+ extend self
3
+
4
+ def method_missing method, *args
5
+ tries = 0
6
+ begin
7
+ redis.send method, *args
8
+ rescue Redis::TimeoutError, Redis::CannotConnectError
9
+ if (tries += 1) < 10
10
+ Rails.logger.warn '[RedisProxy] Retry a Redis call'
11
+ retry
12
+ else
13
+ Rails.logger.warn '[RedisProxy] Fail a Redis call after 10 tries'
14
+ raise
15
+ end
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def redis
22
+ @redis ||= AirbrakeProxy.configuration.redis
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module AirbrakeProxy
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,88 @@
1
+ require_relative 'airbrake_proxy/redis_proxy'
2
+ require_relative 'airbrake_proxy/configure'
3
+ require_relative 'airbrake_proxy/version'
4
+
5
+ require 'active_support/inflector'
6
+ require 'time_constants'
7
+
8
+ require 'airbrake'
9
+
10
+ module AirbrakeProxy
11
+ extend self
12
+ extend Configure
13
+
14
+ class TooManyNotification < StandardError; end
15
+
16
+ def notify(exception, params)
17
+ unless exception
18
+ logger.error("AirbrakeProxy#notify(#{exception}, #{params}) => called without exception")
19
+ return false
20
+ end
21
+
22
+ safe_notify(exception) { Airbrake.notify(exception, params) }
23
+ true
24
+ rescue TooManyNotification => e
25
+ logger.info("AirbrakeProxy => #{e.message}")
26
+ end
27
+
28
+ def keys
29
+ _keys.map { |key| [key, RedisProxy.get(key)] }
30
+ end
31
+
32
+ def clean!
33
+ _keys.each { |key| RedisProxy.del(key) }
34
+ end
35
+
36
+ def remove(key)
37
+ if key.match(KEY_PREFIX)
38
+ RedisProxy.del(key) == 1 ? true : false
39
+ else
40
+ false
41
+ end
42
+ end
43
+
44
+ protected
45
+
46
+ KEY_PREFIX = 'AIRBRAKE::'.freeze
47
+
48
+ private
49
+
50
+ def _keys
51
+ RedisProxy.keys.select { |key| key.match(KEY_PREFIX) }
52
+ end
53
+
54
+ THRESHOLD = 5
55
+
56
+ def safe_notify(exception)
57
+ redis_key = key(exception)
58
+
59
+ unless authorized_to_notify?(redis_key)
60
+ raise TooManyNotification.new("#{redis_key} was notified too many times")
61
+ end
62
+ yield
63
+ end
64
+
65
+ def key(exception)
66
+ "#{KEY_PREFIX}#{(exception&.message || exception.inspect).parameterize}"
67
+ end
68
+
69
+ def authorized_to_notify?(key)
70
+ return false if RedisProxy.get(key).to_i >= THRESHOLD # We won't hint Redis#incr(key) to not reset timelife of key
71
+ mark_as_notify(key) # return value is a true predicate
72
+ end
73
+
74
+ def mark_as_notify(key)
75
+ unless RedisProxy.exists(key)
76
+ RedisProxy.set(key, 0)
77
+ RedisProxy.expire(key, T_5_HOURS)
78
+ end
79
+ RedisProxy.incr(key)
80
+ end
81
+
82
+ private
83
+
84
+ def logger
85
+ @logger ||= AirbrakeProxy.configuration.logger
86
+ end
87
+
88
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: airbrake_proxy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joel AZEMAR
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: airbrake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: time_constants
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.2'
97
+ description: Basic Circuit Breaker to attempt not reach Airbrake limit for the same
98
+ exception
99
+ email:
100
+ - joel.azemar@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - CHANGELOG.md
109
+ - CODE_OF_CONDUCT.md
110
+ - Gemfile
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - UPGRADE.md
115
+ - airbrake_proxy.gemspec
116
+ - bin/console
117
+ - bin/setup
118
+ - lib/airbrake_proxy.rb
119
+ - lib/airbrake_proxy/configuration.rb
120
+ - lib/airbrake_proxy/configure.rb
121
+ - lib/airbrake_proxy/redis_proxy.rb
122
+ - lib/airbrake_proxy/version.rb
123
+ homepage: https://github.com/FinalCAD/airbrake_proxy
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.6.10
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Basic Circuit Breaker for Airbrake
147
+ test_files: []