sidekiq-ecs-scaler 0.1.0 → 0.2.0

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: 6e788a43a1d4013b88babd60929d35dc465dca7dbe73daa633566929be57f501
4
- data.tar.gz: 9a6c856115de94d05edb69662d2de03ea0ae536d40d3b36a1f74f1f2f2c9239b
3
+ metadata.gz: e4d70a0b678343e315f0d8b64c0d8bd5c957277cd0cd6e201d54a2cf2b828240
4
+ data.tar.gz: d61d4ed70aad984f619846dfed858ec745db318dab39417749ec0a0c821489dc
5
5
  SHA512:
6
- metadata.gz: 137a41c9d0c6fbc53bb16652b7d9c711347618e2c3ce37130ce1087ec774c09956c0746e345d6bbd7bca5395aaa36b02c1f1a6a08e9a4c65a3eb51dd347a0280
7
- data.tar.gz: bdab45f712315863eb32d08e3aba9edb35db1d9d50f2966206baf6948ea1ce97cc9a6672402ffd09cd66ab27d5a222a02fa3fb8d902d9d7e9287bfb4045824e1
6
+ metadata.gz: 115d9a719b314f47901711eeefb3ab3015525a5d163a698f868ef9e358ad06a91e9e19b9686102193c8bd9c69d377210929581f90de601aa4d30ff795700a78d
7
+ data.tar.gz: 99242f8721633c865b5e6defc1750f6346a5a411c958b97094a3dd19a91b3a0e950856818c571a8231e03843e1383969aaab81e8084a2ca79175cac4937f79b0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [0.2.0] - 2021-12-01
2
+
3
+ - Add configuration items
4
+ - `enabled` is possible to enable / disable the scale.
5
+ - `logger` is possible to changing the logger that outputs the required number of changes.
6
+ - UPDATE README.md
7
+
1
8
  ## [0.1.0] - 2021-11-29
2
9
 
3
10
  - initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sidekiq-ecs-scaler (0.1.0)
4
+ sidekiq-ecs-scaler (0.2.0)
5
5
  aws-sdk-ecs (> 1, < 2)
6
6
  sidekiq (> 5, < 7)
7
7
 
@@ -16,7 +16,7 @@ GEM
16
16
  zeitwerk (~> 2.3)
17
17
  ast (2.4.2)
18
18
  aws-eventstream (1.2.0)
19
- aws-partitions (1.535.0)
19
+ aws-partitions (1.536.0)
20
20
  aws-sdk-core (3.123.0)
21
21
  aws-eventstream (~> 1, >= 1.0.2)
22
22
  aws-partitions (~> 1, >= 1.525.0)
data/README.md CHANGED
@@ -22,6 +22,12 @@ And then execute:
22
22
 
23
23
  ```ruby
24
24
  SidekiqEcsScaler.configure do |config|
25
+ # enable / disable of scaler, default is true
26
+ config.enabled = true
27
+
28
+ # logger, default is Sidekiq.logger
29
+ config.logger = Sidekiq.logger
30
+
25
31
  # queue to monitor latency, default is "default"
26
32
  config.queue_name = "default"
27
33
 
@@ -34,7 +40,7 @@ SidekiqEcsScaler.configure do |config|
34
40
  # maximum latency(seconds), default is 3600
35
41
  config.max_latency = 3600
36
42
 
37
- # custom ECS Client
43
+ # custom ECS Client, default is Aws::ECS::Client.new
38
44
  config.ecs_client = Aws::ECS::Client.new
39
45
 
40
46
  # Set worker options for scaling
@@ -57,6 +63,14 @@ When using [sidekiq-scheduler](https://github.com/moove-it/sidekiq-scheduler), s
57
63
  queue: scheduler
58
64
  ```
59
65
 
66
+ ### About AWS IAM Policy
67
+
68
+ The task role of ECS task that runs Sidekiq workers requires the following permissions:
69
+
70
+ - `ecs:DescribeTasks`
71
+ - `ecs:DescribeServices`
72
+ - `ecs:UpdateService`
73
+
60
74
  ## Development
61
75
 
62
76
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/Steepfile CHANGED
@@ -6,4 +6,6 @@ target :lib do
6
6
  check "lib"
7
7
 
8
8
  library "json"
9
+ library "logger"
10
+ library "monitor"
9
11
  end
@@ -11,15 +11,19 @@ module SidekiqEcsScaler
11
11
 
12
12
  # @return [Integer, nil]
13
13
  def update_desired_count
14
- return unless config.task_meta
14
+ return if !config.enabled || config.task_meta.nil?
15
15
 
16
- desired_count_by_latency.then do |desired_count|
17
- describe_service.then do |service|
18
- update_service(service: service, desired_count: desired_count) if service.desired_count != desired_count
16
+ desired_count = desired_count_by_latency
17
+ service = describe_service
19
18
 
20
- desired_count
21
- end
19
+ if service.desired_count == desired_count
20
+ not_change_log(desired_count)
21
+ else
22
+ update_service(service: service, desired_count: desired_count)
23
+ change_log(service.desired_count, desired_count)
22
24
  end
25
+
26
+ desired_count
23
27
  end
24
28
 
25
29
  private
@@ -70,5 +74,20 @@ module SidekiqEcsScaler
70
74
  }
71
75
  )
72
76
  end
77
+
78
+ # @param count [Integer]
79
+ # @return [void]
80
+ def not_change_log(count)
81
+ config.logger.info("SidekiqEcsScaler doesn't have updated the desired count of tasks from #{count}.")
82
+ end
83
+
84
+ # @param before_count [Integer]
85
+ # @param after_count [Integer]
86
+ # @return [void]
87
+ def change_log(before_count, after_count)
88
+ config.logger.info(
89
+ "SidekiqEcsScaler has updated the desired count of tasks from #{before_count} to #{after_count}."
90
+ )
91
+ end
73
92
  end
74
93
  end
@@ -3,6 +3,9 @@
3
3
  module SidekiqEcsScaler
4
4
  # SidekiqEcsScaler::Configuration
5
5
  class Configuration
6
+ # @!attribute [r] enabled
7
+ # @return [Boolean]
8
+ attr_reader :enabled
6
9
  # @!attribute [r] queue_name
7
10
  # @return [String]
8
11
  attr_reader :queue_name
@@ -18,9 +21,6 @@ module SidekiqEcsScaler
18
21
  # @!attribute [r] task_meta
19
22
  # @return [SidekiqEcsScaler::TaskMetaV4, nil]
20
23
  attr_reader :task_meta
21
- # @!attribute [r] ecs_client
22
- # @return [Aws::ECS::Client]
23
- attr_reader :ecs_client
24
24
 
25
25
  # @return [void]
26
26
  def initialize
@@ -28,8 +28,30 @@ module SidekiqEcsScaler
28
28
  @min_count = 1
29
29
  @max_count = 1
30
30
  @max_latency = 3600
31
- @ecs_client = Aws::ECS::Client.new
32
31
  @task_meta = TaskMetaV4.build_or_null
32
+ @enabled = true
33
+ end
34
+
35
+ # @param enabled [Boolean]
36
+ # @return [void]
37
+ # @raise [ArgumentError]
38
+ def enabled=(enabled)
39
+ raise ArgumentError if !enabled.is_a?(TrueClass) && !enabled.is_a?(FalseClass)
40
+
41
+ @enabled = enabled
42
+ end
43
+
44
+ # @return [Logger]
45
+ def logger
46
+ @logger ||= Sidekiq.logger
47
+ end
48
+
49
+ # @param logger [Logger]
50
+ # @return [void]
51
+ def logger=(logger)
52
+ raise ArgumentError unless logger.is_a?(Logger)
53
+
54
+ @logger = logger
33
55
  end
34
56
 
35
57
  # @param queue_name [String]
@@ -69,6 +91,11 @@ module SidekiqEcsScaler
69
91
  @max_latency = max_latency
70
92
  end
71
93
 
94
+ # @return [Aws::ECS::Client]
95
+ def ecs_client
96
+ @ecs_client ||= Aws::ECS::Client.new
97
+ end
98
+
72
99
  # @param ecs_client [Aws::ECS::Client]
73
100
  # @return [void]
74
101
  # @raise [ArgumentError]
@@ -2,5 +2,5 @@
2
2
 
3
3
  module SidekiqEcsScaler
4
4
  # @return [String]
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "logger"
3
4
  require "uri"
4
5
  require "net/http"
5
6
  require "json"
@@ -28,9 +28,15 @@ module SidekiqEcsScaler
28
28
  def describe_service: () -> ::Aws::ECS::Types::Service
29
29
 
30
30
  def update_service: (service: ::Aws::ECS::Types::Service, desired_count: ::Integer) -> ::Aws::ECS::Types::UpdateServiceResponse
31
+
32
+ def not_change_log: (::Integer) -> void
33
+
34
+ def change_log: (::Integer, ::Integer) -> void
31
35
  end
32
36
 
33
37
  class Configuration
38
+ attr_reader enabled: bool
39
+
34
40
  attr_accessor queue_name: ::String
35
41
 
36
42
  attr_reader min_count: ::Integer
@@ -41,16 +47,22 @@ module SidekiqEcsScaler
41
47
 
42
48
  attr_reader task_meta: ::SidekiqEcsScaler::TaskMetaV4?
43
49
 
44
- attr_reader ecs_client: ::Aws::ECS::Client
45
-
46
50
  def initialize: () -> void
47
51
 
52
+ def enabled=: (bool) -> void
53
+
54
+ def logger: () -> ::Logger
55
+
56
+ def logger=: (::Logger) -> void
57
+
48
58
  def min_count=: (::Integer) -> void
49
59
 
50
60
  def max_count=: (::Integer) -> void
51
61
 
52
62
  def max_latency=: (::Integer) -> void
53
63
 
64
+ def ecs_client: () -> ::Aws::ECS::Client
65
+
54
66
  def ecs_client=: (::Aws::ECS::Client) -> void
55
67
 
56
68
  def latency_per_count: () -> ::Integer
@@ -1,4 +1,6 @@
1
1
  module Sidekiq
2
+ def self.logger: () -> ::Logger
3
+
2
4
  module Worker
3
5
  def self.sidekiq_options: (?::Hash[untyped, untyped]) -> ::Hash[untyped, untyped]
4
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-ecs-scaler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - shoma07
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-29 00:00:00.000000000 Z
11
+ date: 2021-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-ecs