rails-autoscale-core 1.5.2 → 1.5.4

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: 03aadf04a101c5dfdaf9a715a25f36d3304943833c4feeba551c11645590418c
4
- data.tar.gz: 8e46c89f87301ff458ae77640ebf1dad10abf53ffde7110448d4c6c6ffafd5c0
3
+ metadata.gz: f7c5c0bb0fd736aaa1d20bdc0bb2211ba39e55e8652bc1d0e1532e9dec26ea38
4
+ data.tar.gz: 3aca72349348c7ba01c994839a7a4d59674bcd0087d7ea6e08707fd9b4a1a9c6
5
5
  SHA512:
6
- metadata.gz: 1a754daf2618a1e9d7a7dadd773b798493ecdbbfc27882231df528170ffa44e159941bd7f52ecf1878df53e50291abd9b00aafbe8938ae3f263aa1accb4fa700
7
- data.tar.gz: f3b11817285f7afbc3c656419d06f797d75f829ec329cd6a526ec51ea2322fb4a060e3d9fe4c827eb89e03b99fc58999d01f794308d0aead18013b81cbded9db
6
+ metadata.gz: 123d04789e7015e6a45dc1b0e701207dae4b655dc864d8b0bf1f101984ce3e4822e19b22acf39f2c918b7ae6a627470a5eec6d6be9cb09b84748ce3b5f249e5d
7
+ data.tar.gz: b79af282afc336c17f216aa13c8dd5324faba3271a1ae8b57ae90bd0b6328d352180903cd68ac5fb9f9f4c6c82923e547cccea23930a8417813ae5db0a481cf2
@@ -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)
@@ -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,23 +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
- in_generator = defined?(::Rails::Command::GenerateCommand)
8
-
9
- !in_generator && (!in_rake_task || in_whitelisted_rake_tasks?(config.allow_rake_tasks))
6
+ true
10
7
  end
11
8
 
12
9
  def collect
13
10
  []
14
11
  end
15
-
16
- def self.in_whitelisted_rake_tasks?(allowed_rake_tasks)
17
- # Get the tasks that were invoked from the command line.
18
- tasks = Rake.application.top_level_tasks
19
-
20
- allowed_rake_tasks.any? do |task_regex|
21
- tasks.any? { |task| task =~ task_regex }
22
- end
23
- end
24
12
  end
25
13
  end
@@ -19,15 +19,13 @@ 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
- if adapter.metrics_collector&.collect?(config)
29
- adapter.enabled = true
30
- end
28
+ adapter.metrics_collector&.collect?(config)
31
29
  }
32
30
  metrics_collectors_classes = enabled_adapters.map(&:metrics_collector)
33
31
  adapters_msg = enabled_adapters.map(&:identifier).concat(
@@ -74,17 +72,26 @@ module Judoscale
74
72
  @_thread&.terminate
75
73
  @_thread = nil
76
74
  @pid = nil
75
+ @reported = false
77
76
  end
78
77
 
79
78
  private
80
79
 
81
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
+
82
88
  report = Report.new(Judoscale.adapters, config, metrics)
83
89
  logger.info "Reporting #{report.metrics.size} metrics"
84
90
  result = AdapterApi.new(config).report_metrics(report.as_json)
85
91
 
86
92
  case result
87
93
  when AdapterApi::SuccessResponse
94
+ @reported = true
88
95
  logger.debug "Reported successfully"
89
96
  when AdapterApi::FailureResponse
90
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.2"
4
+ VERSION = "1.5.4"
5
5
  end
@@ -21,17 +21,8 @@ module Judoscale
21
21
  end
22
22
 
23
23
  class Adapter < Struct.new(:identifier, :adapter_info, :metrics_collector)
24
- attr_accessor :enabled
25
-
26
- def initialize(identifier, adapter_info, metrics_collector)
27
- super
28
- self.enabled = false
29
- end
30
-
31
24
  def as_json
32
- {
33
- identifier => adapter_info.merge(enabled: enabled)
34
- }
25
+ {identifier => adapter_info}
35
26
  end
36
27
  end
37
28
 
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.2
4
+ version: 1.5.4
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-10 00:00:00.000000000 Z
13
+ date: 2024-02-07 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.2)
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