sidekiq-ecs-scaler 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +2 -2
- data/README.md +15 -1
- data/Steepfile +2 -0
- data/lib/sidekiq-ecs-scaler/client.rb +25 -6
- data/lib/sidekiq-ecs-scaler/configuration.rb +31 -4
- data/lib/sidekiq-ecs-scaler/version.rb +1 -1
- data/lib/sidekiq-ecs-scaler.rb +1 -0
- data/sig/sidekiq-ecs-scaler.rbs +14 -2
- data/sig-private/sidekiq.rbs +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4d70a0b678343e315f0d8b64c0d8bd5c957277cd0cd6e201d54a2cf2b828240
|
4
|
+
data.tar.gz: d61d4ed70aad984f619846dfed858ec745db318dab39417749ec0a0c821489dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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
@@ -11,15 +11,19 @@ module SidekiqEcsScaler
|
|
11
11
|
|
12
12
|
# @return [Integer, nil]
|
13
13
|
def update_desired_count
|
14
|
-
return
|
14
|
+
return if !config.enabled || config.task_meta.nil?
|
15
15
|
|
16
|
-
|
17
|
-
|
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
|
-
|
21
|
-
|
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]
|
data/lib/sidekiq-ecs-scaler.rb
CHANGED
data/sig/sidekiq-ecs-scaler.rbs
CHANGED
@@ -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
|
data/sig-private/sidekiq.rbs
CHANGED
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.
|
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-
|
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
|