judoscale-ruby 1.5.1 → 1.5.3

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: 34e63423106d499e2a555bf9343d38224e1eeb1e4f2fa2177d532ff33df3de81
4
- data.tar.gz: 7efed4c6de8f587dac09c10ede982a67f73aba88e6ffeb3275db19dc968f1df7
3
+ metadata.gz: 5e8936dd7c732f65718653a778b6434e318dc5f32dec8210c2ac70d86065757b
4
+ data.tar.gz: 0f8fcec57301d504673d13d8c0af45f1f269d20dfcd1f7a4c40242faae0aa616
5
5
  SHA512:
6
- metadata.gz: 2858316d5ec92aaca9b448a30699fb64dae7a970a97bf3bd4e54437d5ed5877782efd2b2c698e7c45e5f1c122b652c6463d26e98349c248cf580869bea974aa6
7
- data.tar.gz: 659d23cad27612aff9c3653890758a40a315eaea4e3d319cbb0d36ada38568a00168e13601220ef06dcec7ed49dec325accd1fb844924665e031d7e32bfd4fa4
6
+ metadata.gz: d7f104f4d7bdda5123493df3481619982cbe81c3ccdd455c9e73ac5a7a643fed4f2b6af55db0b898f8675ee2d11684e5aa4d1511c89565ab41c184f17adfd246
7
+ data.tar.gz: b7480e12b5e6e06814a5838c912c1109f56f536dabe5674438cf11cc7b41b2c6a01253633b00c90ca3b4575f3c0bdad0cfa50878c31ac8deb3e873be479d9168
@@ -65,7 +65,7 @@ module Judoscale
65
65
  end
66
66
 
67
67
  attr_accessor :api_base_url, :report_interval_seconds,
68
- :max_request_size_bytes, :logger, :log_tag, :current_runtime_container, :allow_rake_tasks
68
+ :max_request_size_bytes, :logger, :log_tag, :current_runtime_container
69
69
  attr_reader :log_level
70
70
 
71
71
  def initialize
@@ -77,7 +77,6 @@ module Judoscale
77
77
  @log_tag = "Judoscale"
78
78
  @max_request_size_bytes = 100_000 # ignore request payloads over 100k since they skew the queue times
79
79
  @report_interval_seconds = 10
80
- @allow_rake_tasks = []
81
80
 
82
81
  self.log_level = ENV["JUDOSCALE_LOG_LEVEL"] || ENV["RAILS_AUTOSCALE_LOG_LEVEL"]
83
82
  @logger = ::Logger.new($stdout)
@@ -12,6 +12,13 @@ module Judoscale
12
12
  sql
13
13
  end
14
14
 
15
+ # This will respect a multiple-database setup, unlike the `table_exists?` method.
16
+ def self.table_exists_for_model?(model)
17
+ model.connection.schema_cache.data_source_exists?(model.table_name)
18
+ rescue ActiveRecord::NoDatabaseError
19
+ false
20
+ end
21
+
15
22
  def self.table_exists?(table_name)
16
23
  ::ActiveRecord::Base.connection.table_exists?(table_name)
17
24
  rescue ActiveRecord::NoDatabaseError
@@ -6,7 +6,11 @@ require "logger"
6
6
  module Judoscale
7
7
  module Logger
8
8
  def logger
9
- @logger ||= LoggerProxy.new(Config.instance.logger, Config.instance.log_level)
9
+ if @logger && @logger.log_level == Config.instance.log_level
10
+ @logger
11
+ else
12
+ @logger = LoggerProxy.new(Config.instance.logger, Config.instance.log_level)
13
+ end
10
14
  end
11
15
  end
12
16
 
@@ -5,7 +5,7 @@ module Judoscale
5
5
  # No queue_name is assumed to be a web request metric
6
6
  # Metrics: qt = queue time (default), qd = queue depth, busy
7
7
  def initialize(identifier, value, time, queue_name = nil)
8
- super identifier, value.to_i, time.utc, queue_name
8
+ super(identifier, value.to_i, time.utc, queue_name)
9
9
  end
10
10
  end
11
11
  end
@@ -3,22 +3,11 @@
3
3
  module Judoscale
4
4
  class MetricsCollector
5
5
  def self.collect?(config)
6
- in_rake_task = defined?(::Rake) && Rake.respond_to?(:application) && Rake.application.top_level_tasks.any?
7
-
8
- !in_rake_task || in_whitelisted_rake_tasks?(config.allow_rake_tasks)
6
+ true
9
7
  end
10
8
 
11
9
  def collect
12
10
  []
13
11
  end
14
-
15
- def self.in_whitelisted_rake_tasks?(allowed_rake_tasks)
16
- # Get the tasks that were invoked from the command line.
17
- tasks = Rake.application.top_level_tasks
18
-
19
- allowed_rake_tasks.any? do |task_regex|
20
- tasks.any? { |task| task =~ task_regex }
21
- end
22
- end
23
12
  end
24
13
  end
@@ -19,25 +19,24 @@ module Judoscale
19
19
  def start!(config, adapters)
20
20
  @pid = Process.pid
21
21
 
22
- if !config.api_base_url
22
+ if config.api_base_url.nil? || config.api_base_url.strip.empty?
23
23
  logger.debug "Set api_base_url to enable metrics reporting"
24
24
  return
25
25
  end
26
26
 
27
27
  enabled_adapters, skipped_adapters = adapters.partition { |adapter|
28
- # judoscale-ruby adapter does not have a metrics collector
29
- adapter.metrics_collector.nil? || adapter.metrics_collector.collect?(config)
28
+ adapter.metrics_collector&.collect?(config)
30
29
  }
31
30
  metrics_collectors_classes = enabled_adapters.map(&:metrics_collector)
32
- metrics_collectors_classes.compact!
31
+ adapters_msg = enabled_adapters.map(&:identifier).concat(
32
+ skipped_adapters.map { |adapter| "#{adapter.identifier}[skipped]" }
33
+ ).join(", ")
33
34
 
34
35
  if metrics_collectors_classes.empty?
35
- adapters_msg = skipped_adapters.map(&:identifier).join(", ")
36
36
  logger.debug "No metrics need to be collected (adapters: #{adapters_msg})"
37
37
  return
38
38
  end
39
39
 
40
- adapters_msg = enabled_adapters.map(&:identifier).join(", ")
41
40
  logger.info "Reporter starting, will report every ~#{config.report_interval_seconds} seconds (adapters: #{adapters_msg})"
42
41
 
43
42
  metrics_collectors = metrics_collectors_classes.map(&:new)
@@ -73,17 +72,26 @@ module Judoscale
73
72
  @_thread&.terminate
74
73
  @_thread = nil
75
74
  @pid = nil
75
+ @reported = false
76
76
  end
77
77
 
78
78
  private
79
79
 
80
80
  def report(config, metrics)
81
+ # Make sure we report at least once, even if there are no metrics,
82
+ # so Judoscale knows the adapter is installed and running.
83
+ if @reported && metrics.empty?
84
+ logger.debug "No metrics to report - skipping"
85
+ return
86
+ end
87
+
81
88
  report = Report.new(Judoscale.adapters, config, metrics)
82
89
  logger.info "Reporting #{report.metrics.size} metrics"
83
90
  result = AdapterApi.new(config).report_metrics(report.as_json)
84
91
 
85
92
  case result
86
93
  when AdapterApi::SuccessResponse
94
+ @reported = true
87
95
  logger.debug "Reported successfully"
88
96
  when AdapterApi::FailureResponse
89
97
  logger.error "Reporter failed: #{result.failure_message}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Judoscale
4
- VERSION = "1.5.1"
4
+ VERSION = "1.5.3"
5
5
  end
@@ -20,7 +20,7 @@ module Judoscale
20
20
  attr_reader :adapters
21
21
  end
22
22
 
23
- Adapter = Struct.new(:identifier, :adapter_info, :metrics_collector) do
23
+ class Adapter < Struct.new(:identifier, :adapter_info, :metrics_collector)
24
24
  def as_json
25
25
  {identifier => adapter_info}
26
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: judoscale-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam McCrea
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-08-09 00:00:00.000000000 Z
13
+ date: 2024-01-25 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description:
16
16
  email:
@@ -20,7 +20,6 @@ extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
22
  - Gemfile
23
- - Gemfile.lock
24
23
  - Rakefile
25
24
  - judoscale-ruby.gemspec
26
25
  - lib/judoscale-ruby.rb
data/Gemfile.lock DELETED
@@ -1,48 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- judoscale-ruby (1.5.1)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- addressable (2.8.1)
10
- public_suffix (>= 2.0.2, < 6.0)
11
- crack (0.4.5)
12
- rexml
13
- debug (1.7.1)
14
- irb (>= 1.5.0)
15
- reline (>= 0.3.1)
16
- hashdiff (1.0.1)
17
- io-console (0.6.0)
18
- irb (1.6.2)
19
- reline (>= 0.3.0)
20
- minitest (5.17.0)
21
- minitest-stub-const (0.6)
22
- public_suffix (5.0.1)
23
- rake (13.0.6)
24
- reline (0.3.2)
25
- io-console (~> 0.5)
26
- rexml (3.2.5)
27
- webmock (3.18.1)
28
- addressable (>= 2.8.0)
29
- crack (>= 0.3.2)
30
- hashdiff (>= 0.4.0, < 2.0.0)
31
-
32
- PLATFORMS
33
- arm64-darwin-20
34
- arm64-darwin-21
35
- arm64-darwin-22
36
- x86_64-darwin-21
37
- x86_64-linux
38
-
39
- DEPENDENCIES
40
- debug
41
- judoscale-ruby!
42
- minitest
43
- minitest-stub-const
44
- rake (>= 12.3.3)
45
- webmock
46
-
47
- BUNDLED WITH
48
- 2.3.9