From 42ecf074e0d8d45a8cde618bc6b3bc86ce85b39f Mon Sep 17 00:00:00 2001 From: Ivo Anjo Date: Sun, 2 Oct 2022 15:41:44 +0100 Subject: [PATCH 01/14] Bump JRuby version used for development --- .ruby-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ruby-version b/.ruby-version index 87d3afa..4b56eec 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -jruby-9.1.12.0 +jruby-9.3.8.0 From d91aa0b54394ded86fa65ed29c5532ebaf03aee1 Mon Sep 17 00:00:00 2001 From: Ivo Anjo Date: Sun, 2 Oct 2022 15:46:57 +0100 Subject: [PATCH 02/14] Add paragraph explaining why TruffleRuby also benefits --- README.adoc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.adoc b/README.adoc index b8271d8..f39db97 100644 --- a/README.adoc +++ b/README.adoc @@ -56,6 +56,12 @@ On kubernetes, you can make use of https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/[readiness probes] to delay service startup while warm-blanket is working. +=== Important for TruffleRuby as well! + +TruffleRuby can be run either on a standalone mode, or with a JVM. +In either configuration, like JRuby, it needs to warm up until it +gets to peak performance, so WarmBlanket is great there too! + == How can I make use of it? To make use of WarmBlanket, you'll need to follow the next sections, From 3e5549b7392ceccf724b3eeaca659a345b8bddb2 Mon Sep 17 00:00:00 2001 From: Ivo Anjo Date: Sun, 2 Oct 2022 15:48:16 +0100 Subject: [PATCH 03/14] Adopt modern name for Gemfile --- bin/pry | 2 +- bin/rspec | 2 +- Gemfile => gems.rb | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename Gemfile => gems.rb (100%) diff --git a/bin/pry b/bin/pry index 927a638..887d17c 100755 --- a/bin/pry +++ b/bin/pry @@ -8,7 +8,7 @@ # require 'pathname' -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../gems.rb', Pathname.new(__FILE__).realpath) require 'rubygems' diff --git a/bin/rspec b/bin/rspec index 7420b57..7ade256 100755 --- a/bin/rspec +++ b/bin/rspec @@ -8,7 +8,7 @@ # require 'pathname' -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../gems.rb', Pathname.new(__FILE__).realpath) require 'rubygems' diff --git a/Gemfile b/gems.rb similarity index 100% rename from Gemfile rename to gems.rb From eba2d7d316086f4e1ae831831d245dc290a1e859 Mon Sep 17 00:00:00 2001 From: Ivo Anjo Date: Sun, 2 Oct 2022 15:52:01 +0100 Subject: [PATCH 04/14] Use modern gems for development --- warm-blanket.gemspec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/warm-blanket.gemspec b/warm-blanket.gemspec index 66273fc..b181e2f 100644 --- a/warm-blanket.gemspec +++ b/warm-blanket.gemspec @@ -17,11 +17,11 @@ Gem::Specification.new do |spec| spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } spec.require_paths = ['lib'] - spec.add_development_dependency 'bundler', '~> 1.15' - spec.add_development_dependency 'rspec', '~> 3.6' - spec.add_development_dependency 'webmock', '~> 3.0' + spec.add_development_dependency 'bundler', '~> 2.3' + spec.add_development_dependency 'rspec', '~> 3.11' + spec.add_development_dependency 'webmock', '~> 3.18' spec.add_development_dependency 'timecop', '~> 0.9' - spec.add_development_dependency 'rake', '~> 12.0' + spec.add_development_dependency 'rake', '~> 13.0' spec.add_development_dependency 'pry' spec.add_development_dependency 'pry-byebug' unless RUBY_PLATFORM == 'java' spec.add_development_dependency 'pry-debugger-jruby' if RUBY_PLATFORM == 'java' From 33cf6e5ff10e9a1826532e61fd84607200d83354 Mon Sep 17 00:00:00 2001 From: Ivo Anjo Date: Sun, 2 Oct 2022 15:55:05 +0100 Subject: [PATCH 05/14] Remove unused variable --- spec/integration/wait_for_port_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/integration/wait_for_port_spec.rb b/spec/integration/wait_for_port_spec.rb index c7251ec..b9c4cf6 100644 --- a/spec/integration/wait_for_port_spec.rb +++ b/spec/integration/wait_for_port_spec.rb @@ -92,7 +92,6 @@ it 'retries until the time_deadline has passed' do Timecop.freeze(Time.local(2017)) - advancing_time = Time.now expect(TCPSocket).to receive(:new).exactly(expected_tries).times do tick_clock_one_second From 95406b834337d0f99ed4147672a9a8fa9b1bf324 Mon Sep 17 00:00:00 2001 From: Ivo Anjo Date: Sun, 2 Oct 2022 16:00:54 +0100 Subject: [PATCH 06/14] Avoid shipping development-related files in gem package --- warm-blanket.gemspec | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/warm-blanket.gemspec b/warm-blanket.gemspec index b181e2f..83fd973 100644 --- a/warm-blanket.gemspec +++ b/warm-blanket.gemspec @@ -14,7 +14,14 @@ Gem::Specification.new do |spec| spec.description = 'Ruby gem for warming up web services on boot' spec.homepage = 'https://github.com/Talkdesk/warm-blanket' - spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } + spec.files = Dir.chdir(File.expand_path(__dir__)) do + `git ls-files -z`.split("\x0") + .reject { |f| f.match(%r{\A(?:test|spec|features|[.]github)/}) } + .reject { |f| + ["gems.rb", ".ruby-version", ".gitignore", ".rspec", + "Rakefile", "bin/pry", "bin/rspec", "bin/console"].include?(f) + } + end spec.require_paths = ['lib'] spec.add_development_dependency 'bundler', '~> 2.3' From 699a1275143bd8c3d6ff43d1ccc81ec86e70db20 Mon Sep 17 00:00:00 2001 From: Ivo Anjo Date: Sun, 2 Oct 2022 16:02:33 +0100 Subject: [PATCH 07/14] Add @ivoanjo (myself) to CODEOWNERS --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 0f62b0e..c026583 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,4 +1,4 @@ # This is the default added code owner and should be changed or overridden. # This will be the default owner for everything in the repo, unless a # later match takes precedence -* @Talkdesk/octo +* @Talkdesk/octo @ivoanjo From c3ee8d4dbf34acd7705269e59187d4ba20f4299d Mon Sep 17 00:00:00 2001 From: Ivo Anjo Date: Sun, 2 Oct 2022 16:03:45 +0100 Subject: [PATCH 08/14] Add minimum Ruby version to gem 2.3 seems a reasonable-ish target, given that the old JRuby 9.1 series implemented that Ruby version. --- warm-blanket.gemspec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/warm-blanket.gemspec b/warm-blanket.gemspec index 83fd973..8007713 100644 --- a/warm-blanket.gemspec +++ b/warm-blanket.gemspec @@ -24,6 +24,8 @@ Gem::Specification.new do |spec| end spec.require_paths = ['lib'] + spec.required_ruby_version = ">= 2.3.0" + spec.add_development_dependency 'bundler', '~> 2.3' spec.add_development_dependency 'rspec', '~> 3.11' spec.add_development_dependency 'webmock', '~> 3.18' From f75560cfbe2db5471e1ac82d43c69743584f00f6 Mon Sep 17 00:00:00 2001 From: Ivo Anjo Date: Sun, 2 Oct 2022 16:10:34 +0100 Subject: [PATCH 09/14] Update .gitignore with new lockfile name --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 24e5f45..0da9045 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ /.bundle/ /.yardoc -/Gemfile.lock +/gems.locked /_yardoc/ /coverage/ /doc/ From 88d4e38dcda080d4f03e62c7979fbd6dded79018 Mon Sep 17 00:00:00 2001 From: Ivo Anjo Date: Sun, 2 Oct 2022 17:53:33 +0100 Subject: [PATCH 10/14] Add example app --- examples/example_app.rb | 44 +++++++++++++++++++++++++++++++++++++++++ warm-blanket.gemspec | 3 ++- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 examples/example_app.rb diff --git a/examples/example_app.rb b/examples/example_app.rb new file mode 100644 index 0000000..86ec543 --- /dev/null +++ b/examples/example_app.rb @@ -0,0 +1,44 @@ +require "webrick" +require "pry" +require "warm-blanket" +require "logging" + +puts "Using #{RUBY_DESCRIPTION}" + +PORT = ENV["PORT"] || 8080 + +Logging.logger.root.add_appenders(Logging.appenders.stdout( + layout: Logging.layouts.pattern(pattern: '[%d] %-5l %c: %m\n', date_pattern: '%Y-%m-%d %H:%M:%S') +)) + +WarmBlanket.configure do |config| + common_headers = { + "X-Api-Key": "test-api-key", + } + + config.port = PORT + config.endpoints = [ + {get: "/foo", headers: common_headers}, + {get: "/", headers: common_headers}, + ] + config.enabled = true + config.warmup_time_seconds = 3 +end + +WarmBlanket.trigger_warmup + +server = WEBrick::HTTPServer.new(Port: PORT) + +server.mount_proc("/") do |request, response| + response.body = "/ endpoint" +end + +server.mount_proc("/foo") do |request, response| + response.body = "/foo endpoint" +end + +trap("INT") do + server.shutdown +end + +server.start diff --git a/warm-blanket.gemspec b/warm-blanket.gemspec index 8007713..b97ab5f 100644 --- a/warm-blanket.gemspec +++ b/warm-blanket.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |spec| spec.files = Dir.chdir(File.expand_path(__dir__)) do `git ls-files -z`.split("\x0") - .reject { |f| f.match(%r{\A(?:test|spec|features|[.]github)/}) } + .reject { |f| f.match(%r{\A(?:test|spec|features|[.]github|examples)/}) } .reject { |f| ["gems.rb", ".ruby-version", ".gitignore", ".rspec", "Rakefile", "bin/pry", "bin/rspec", "bin/console"].include?(f) @@ -34,6 +34,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'pry' spec.add_development_dependency 'pry-byebug' unless RUBY_PLATFORM == 'java' spec.add_development_dependency 'pry-debugger-jruby' if RUBY_PLATFORM == 'java' + spec.add_development_dependency 'webrick', '~> 1.7.0' spec.add_dependency 'faraday', '~> 0.9' spec.add_dependency 'dry-configurable', '~> 0.7' From 5e2bc42957abcad65304ff26d56c0dff33520154 Mon Sep 17 00:00:00 2001 From: Ivo Anjo Date: Sun, 2 Oct 2022 17:56:26 +0100 Subject: [PATCH 11/14] Adopt faraday 1.x series --- warm-blanket.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/warm-blanket.gemspec b/warm-blanket.gemspec index b97ab5f..79374cf 100644 --- a/warm-blanket.gemspec +++ b/warm-blanket.gemspec @@ -36,7 +36,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'pry-debugger-jruby' if RUBY_PLATFORM == 'java' spec.add_development_dependency 'webrick', '~> 1.7.0' - spec.add_dependency 'faraday', '~> 0.9' + spec.add_dependency 'faraday', '~> 1.10' spec.add_dependency 'dry-configurable', '~> 0.7' spec.add_dependency 'logging', '~> 2.1' end From 4d4cc60fdcb45e4ae70bbe8f864e872afec49e38 Mon Sep 17 00:00:00 2001 From: Ivo Anjo Date: Sun, 2 Oct 2022 18:06:49 +0100 Subject: [PATCH 12/14] Tweak minimum versions for dependencies Upgrade the ones we can, but still ask for versions that work on JRuby. --- warm-blanket.gemspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/warm-blanket.gemspec b/warm-blanket.gemspec index 79374cf..376db60 100644 --- a/warm-blanket.gemspec +++ b/warm-blanket.gemspec @@ -36,7 +36,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'pry-debugger-jruby' if RUBY_PLATFORM == 'java' spec.add_development_dependency 'webrick', '~> 1.7.0' - spec.add_dependency 'faraday', '~> 1.10' - spec.add_dependency 'dry-configurable', '~> 0.7' - spec.add_dependency 'logging', '~> 2.1' + spec.add_dependency 'faraday', '~> 1.0' # Kept at 1.0 because it still supports Ruby 2.3 (JRuby 9.1) + spec.add_dependency 'dry-configurable', '~> 0.8' # Kept at 0.8 because it still supports Ruby 2.3 (JRuby 9.1) + spec.add_dependency 'logging', '~> 2.3' end From 5cd1c342b429861912e361b091e906c7fd4ceb8e Mon Sep 17 00:00:00 2001 From: Ivo Anjo Date: Sun, 2 Oct 2022 18:15:13 +0100 Subject: [PATCH 13/14] Disable dry-configurable warning See comment for details. --- lib/warm-blanket.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/warm-blanket.rb b/lib/warm-blanket.rb index 6af7800..26fffb6 100644 --- a/lib/warm-blanket.rb +++ b/lib/warm-blanket.rb @@ -25,6 +25,14 @@ module WarmBlanket extend Dry::Configurable + # Compatibility with Ruby 2.3 / JRuby 9.1: Modern versions of dry-configurable emit deprecation warnings for the way + # we're passing in defaults, but older versions of the gem don't work on the older Ruby/JRuby versions. + # See https://github.com/dry-rb/dry-configurable/blob/main/CHANGELOG.md#0130-2021-09-12 . + # This can be dropped when we drop support for Ruby 2.3/JRuby 9.1 + if Dry::Configurable.respond_to?(:warn_on_setting_positional_default) + Dry::Configurable.warn_on_setting_positional_default(false) + end + # Endpoints to be called for warmup, see README setting :endpoints, [], reader: true From f006ab6066f709c46c159e986a78b9c3430b51c0 Mon Sep 17 00:00:00 2001 From: Ivo Anjo Date: Sun, 2 Oct 2022 18:17:46 +0100 Subject: [PATCH 14/14] Release version 1.1.0 --- lib/warm_blanket/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/warm_blanket/version.rb b/lib/warm_blanket/version.rb index d079075..34c29bf 100644 --- a/lib/warm_blanket/version.rb +++ b/lib/warm_blanket/version.rb @@ -19,5 +19,5 @@ # frozen_string_literal: true module WarmBlanket - VERSION = '1.0.0' + VERSION = '1.1.0' end