rails-autoscale-core 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: aea9f97efeaa39ee58923722220094d45ee721e925064f9f344e442cf839e10b
4
- data.tar.gz: 2eb632696c60647be6af0023e3202007d1ef045f26a07ecc7d84b33db108efc6
3
+ metadata.gz: ecb527ab4d6f7a97247bd1aa47424414ea57ef62eaea688e24674820d9c20e8b
4
+ data.tar.gz: d1fa82cb48feb2fe4dd8136647b51d83a439632a19cc14f2cc6114d2e3677a54
5
5
  SHA512:
6
- metadata.gz: 80b2d814748d4ec90fce53a11f98a22e6ba4c17135798188742ce0b1b8a5a8ed5f4231ced13df03ce19fde892423e965ada294e287696b9d903860c178f562f4
7
- data.tar.gz: d12cde36b76a75f737b1a1aab3e2959ab318e93c461680532905868de7d4a31503e401ae8544d989a2f2a5e3bdef3bd33854711220405ddd5815244ecc51bc52
6
+ metadata.gz: 4f4403334de767802741291af1799bfa1f0f911e002d89a6f8d9e82465da3e1bef724aa75196fd09e25342fa43e66e516852463e8c8e4063eab526d597605f61
7
+ data.tar.gz: d3f82c8c7387ff7627c30b70571c72bca3f4c8d000933e5917a595b6cb6a7a20827f52c1fe4ad9b55d343907085710e59ac21426bfea9a241ecd63b2899e5df1
@@ -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: rails-autoscale-core
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