Skip to content

Commit

Permalink
Merge pull request #125 from ncbo/develop
Browse files Browse the repository at this point in the history
merge develop to master
  • Loading branch information
alexskr authored Aug 31, 2023
2 parents 5f2fdc9 + ac42238 commit 895d3bf
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Capfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ require 'capistrano/bundler'
# require 'capistrano/rails/assets'
# require 'capistrano/rails/migrations'
require 'capistrano/locally'

require 'new_relic/recipes' # announce deployments in NewRelic
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
10 changes: 7 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ gem 'redis-store', '1.9.1' # remove after https://github.com/redis-store/redis-s

# Monitoring
gem 'cube-ruby', require: 'cube'
gem 'newrelic_rpm'
gem 'newrelic_rpm', group: [:default, :deployment]

# HTTP server
gem 'unicorn'
Expand All @@ -50,15 +50,19 @@ gem 'ontologies_linked_data', github: 'ncbo/ontologies_linked_data', branch: 'ma
gem 'sparql-client', github: 'ncbo/sparql-client', branch: 'master'

group :development do
# bcrypt_pbkdf and ed35519 is required for capistrano deployments when using ed25519 keys; see https://github.com/miloserdow/capistrano-deploy/issues/42
gem 'shotgun', github: 'palexander/shotgun', branch: 'ncbo'
gem 'rubocop'
end

group :deployment do
# bcrypt_pbkdf and ed35519 is required for capistrano deployments when using ed25519 keys; see https://github.com/miloserdow/capistrano-deploy/issues/42
gem 'bcrypt_pbkdf', '>= 1.0', '< 2.0', require: false
gem 'capistrano', '~> 3', require: false
gem 'capistrano-bundler', require: false
gem 'capistrano-locally', require: false
gem 'capistrano-rbenv', require: false
gem 'ed25519', '>= 1.2', '< 2.0', require: false
gem 'pry'
gem 'shotgun', github: 'palexander/shotgun', branch: 'ncbo'
end

group :profiling do
Expand Down
28 changes: 27 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ GEM
public_suffix (>= 2.0.2, < 6.0)
airbrussh (1.4.2)
sshkit (>= 1.6.1, != 1.7.0)
ast (2.4.2)
backports (3.24.1)
base64 (0.1.1)
bcrypt (3.1.19)
bcrypt_pbkdf (1.1.0)
bigdecimal (1.4.2)
Expand Down Expand Up @@ -201,6 +203,7 @@ GEM
json_pure (2.6.3)
jwt (2.7.1)
kgio (2.11.4)
language_server-protocol (3.17.0.3)
libxml-ruby (4.1.1)
logger (1.5.3)
macaddr (1.7.2)
Expand Down Expand Up @@ -240,13 +243,18 @@ GEM
omni_logger (0.1.4)
logger
os (1.1.4)
parallel (1.23.0)
parseconfig (1.1.2)
parser (3.2.2.3)
ast (~> 2.4.1)
racc
pony (1.13.1)
mail (>= 2.0)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (5.0.3)
racc (1.7.1)
rack (1.6.13)
rack-accept (0.4.5)
rack (>= 0.4)
Expand All @@ -263,6 +271,7 @@ GEM
rack-test (2.1.0)
rack (>= 1.3)
rack-timeout (0.6.3)
rainbow (3.1.1)
raindrops (0.20.1)
rake (10.5.0)
rdf (1.0.8)
Expand All @@ -277,6 +286,7 @@ GEM
redis-store (>= 1.6, < 2)
redis-store (1.9.1)
redis (>= 4, < 5)
regexp_parser (2.8.1)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
Expand All @@ -286,6 +296,21 @@ GEM
rsolr (2.5.0)
builder (>= 2.1.2)
faraday (>= 0.9, < 3, != 2.0.0)
rubocop (1.56.2)
base64 (~> 0.1.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.3)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
ruby-xxHash (0.4.0.2)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
Expand Down Expand Up @@ -330,6 +355,7 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.8.2)
unicode-display_width (2.4.2)
unicorn (6.1.0)
kgio (~> 2.6)
raindrops (~> 0.7)
Expand Down Expand Up @@ -369,7 +395,6 @@ DEPENDENCIES
oj (~> 3.0)
ontologies_linked_data!
parseconfig
pry
rack
rack-accept (~> 0.4)
rack-attack (~> 6.6.1)
Expand All @@ -385,6 +410,7 @@ DEPENDENCIES
redis-activesupport
redis-rack-cache (~> 2.0)
redis-store (= 1.9.1)
rubocop
shotgun!
simplecov
simplecov-cobertura
Expand Down
1 change: 1 addition & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
after :publishing, :get_config
after :get_config, :restart
# after :deploy, :smoke_test
after :restart, "newrelic:notice_deployment"

after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
Expand Down
15 changes: 9 additions & 6 deletions config/rack_attack.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

puts "(API) >> Throttling enabled at #{LinkedData::OntologiesAPI.settings.req_per_second_per_ip} req/sec"
limit_req_ip = LinkedData::OntologiesAPI.settings.req_per_second_per_ip
limit_req_ip_heavy = limit_req_ip / 5
puts "(API) >> Throttling enabled at #{limit_req_ip} req/sec"

require 'rack/attack'
require 'redis-activesupport'
Expand Down Expand Up @@ -28,11 +30,12 @@
request.env['REMOTE_USER']&.admin?
end

Rack::Attack.throttle('requests by ip',
limit: LinkedData::OntologiesAPI.settings.req_per_second_per_ip,
period: 1.second
) do |request|
request.ip
Rack::Attack.throttle('req/ip/heavy', limit: limit_req_ip_heavy, period: 1.second) do |req|
req.ip if req.path.include?('/recommender') || req.path.include?('/annotator')
end

Rack::Attack.throttle('req/ip', limit: limit_req_ip, period: 1.second) do |req|
req.ip
end

Rack::Attack.throttled_responder = lambda do |request|
Expand Down

0 comments on commit 895d3bf

Please sign in to comment.