dynamo-autoscale 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/lib/dynamo-autoscale/cw_poller.rb +2 -2
- data/lib/dynamo-autoscale/dispatcher.rb +4 -3
- data/lib/dynamo-autoscale/dynamo_actioner.rb +9 -9
- data/lib/dynamo-autoscale/local_data_poll.rb +1 -1
- data/lib/dynamo-autoscale/rule.rb +2 -0
- data/lib/dynamo-autoscale/table_tracker.rb +6 -6
- data/lib/dynamo-autoscale/version.rb +1 -1
- metadata +1 -1
data/CHANGELOG
CHANGED
@@ -12,7 +12,7 @@ module DynamoAutoscale
|
|
12
12
|
# polling always happens on interval boundaries regardless of how long
|
13
13
|
# polling takes.
|
14
14
|
sleep_duration = INTERVAL - ((Time.now.to_i + INTERVAL) % INTERVAL)
|
15
|
-
logger.debug "Sleeping for #{sleep_duration} seconds..."
|
15
|
+
logger.debug "[cw_poller] Sleeping for #{sleep_duration} seconds..."
|
16
16
|
sleep(sleep_duration)
|
17
17
|
|
18
18
|
do_poll(tables, &block)
|
@@ -20,7 +20,7 @@ module DynamoAutoscale
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def do_poll tables, &block
|
23
|
-
logger.debug "Beginning CloudWatch poll..."
|
23
|
+
logger.debug "[cw_poller] Beginning CloudWatch poll..."
|
24
24
|
now = Time.now
|
25
25
|
|
26
26
|
tables.each do |table|
|
@@ -11,14 +11,14 @@ module DynamoAutoscale
|
|
11
11
|
if datum[:provisioned_reads] and (datum[:consumed_reads] > datum[:provisioned_reads])
|
12
12
|
lost_reads = datum[:consumed_reads] - datum[:provisioned_reads]
|
13
13
|
|
14
|
-
logger.warn "[reads] Lost units: #{lost_reads} " +
|
14
|
+
logger.warn "[dispatcher][reads] Lost units: #{lost_reads} " +
|
15
15
|
"(#{datum[:consumed_reads]} - #{datum[:provisioned_reads]})"
|
16
16
|
end
|
17
17
|
|
18
18
|
if datum[:provisioned_writes] and (datum[:consumed_writes] > datum[:provisioned_writes])
|
19
19
|
lost_writes = datum[:consumed_writes] - datum[:provisioned_writes]
|
20
20
|
|
21
|
-
logger.warn "[writes] Lost units: #{lost_writes} " +
|
21
|
+
logger.warn "[dispatcher][writes] Lost units: #{lost_writes} " +
|
22
22
|
"(#{datum[:consumed_writes]} - #{datum[:provisioned_writes]})"
|
23
23
|
end
|
24
24
|
|
@@ -29,7 +29,8 @@ module DynamoAutoscale
|
|
29
29
|
DynamoAutoscale.rules.test(table)
|
30
30
|
@last_check[table.name] = time
|
31
31
|
else
|
32
|
-
logger.debug "Skipped rule check, already checked for
|
32
|
+
logger.debug "[dispatcher] Skipped rule check, already checked for " +
|
33
|
+
"a later data point."
|
33
34
|
end
|
34
35
|
|
35
36
|
DynamoAutoscale.current_table = nil
|
@@ -1,5 +1,9 @@
|
|
1
1
|
module DynamoAutoscale
|
2
2
|
class DynamoActioner < Actioner
|
3
|
+
def dynamo
|
4
|
+
@dynamo ||= AWS::DynamoDB.new.tables[table.name]
|
5
|
+
end
|
6
|
+
|
3
7
|
def scale metric, value
|
4
8
|
aws_throughput_key = case metric
|
5
9
|
when :reads
|
@@ -12,22 +16,18 @@ module DynamoAutoscale
|
|
12
16
|
end
|
13
17
|
|
14
18
|
def scale_both reads, writes
|
15
|
-
dynamo_scale(
|
16
|
-
read_capacity_units: reads, write_capacity_units: writes
|
17
|
-
})
|
19
|
+
dynamo_scale(read_capacity_units: reads, write_capacity_units: writes)
|
18
20
|
end
|
19
21
|
|
20
22
|
private
|
21
23
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
if aws_table.status == :updating
|
26
|
-
logger.warn "Cannot scale throughputs. Table is updating."
|
24
|
+
def dynamo_scale opts
|
25
|
+
if dynamo.status == :updating
|
26
|
+
logger.warn "[actioner] Cannot scale throughputs. Table is updating."
|
27
27
|
return false
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
dynamo.provision_throughput(opts)
|
31
31
|
return true
|
32
32
|
rescue AWS::DynamoDB::Errors::ValidationException => e
|
33
33
|
# When you try to set throughput to a negative value or the same value it
|
@@ -23,7 +23,7 @@ module DynamoAutoscale
|
|
23
23
|
data = JSON.parse(File.read(table_path)).symbolize_keys
|
24
24
|
|
25
25
|
if data[:consumed_writes].nil? or data[:consumed_reads].nil?
|
26
|
-
logger.warn "Lacking data for table #{table_name}. Skipping."
|
26
|
+
logger.warn "[ld_poller] Lacking data for table #{table_name}. Skipping."
|
27
27
|
next
|
28
28
|
end
|
29
29
|
|
@@ -26,7 +26,7 @@ module DynamoAutoscale
|
|
26
26
|
# :consumed_reads=>342.4033333333333}
|
27
27
|
def tick time, datum
|
28
28
|
if time < (Time.now.utc - TIME_WINDOW)
|
29
|
-
logger.warn "Attempted to insert data outside of the time window."
|
29
|
+
logger.warn "[table] Attempted to insert data outside of the time window."
|
30
30
|
return
|
31
31
|
end
|
32
32
|
|
@@ -36,14 +36,14 @@ module DynamoAutoscale
|
|
36
36
|
datum[:provisioned_writes] = last_provisioned_for :writes, at: time
|
37
37
|
|
38
38
|
if datum[:provisioned_writes]
|
39
|
-
logger.debug "Filled in gap in provisioned writes."
|
39
|
+
logger.debug "[table] Filled in gap in provisioned writes."
|
40
40
|
end
|
41
41
|
end
|
42
42
|
if datum[:provisioned_reads].nil?
|
43
43
|
datum[:provisioned_reads] = last_provisioned_for :reads, at: time
|
44
44
|
|
45
45
|
if datum[:provisioned_reads]
|
46
|
-
logger.debug "Filled in gap in provisioned reads."
|
46
|
+
logger.debug "[table] Filled in gap in provisioned reads."
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -51,7 +51,7 @@ module DynamoAutoscale
|
|
51
51
|
|
52
52
|
# The code below here just makes sure that we're trimming data points that
|
53
53
|
# are outside of the time window.
|
54
|
-
logger.debug "Pruning data that may be outside of time window..."
|
54
|
+
logger.debug "[table] Pruning data that may be outside of time window..."
|
55
55
|
now = Time.now.utc
|
56
56
|
to_delete = @data.each.take_while { |key, _| key < (now - TIME_WINDOW) }
|
57
57
|
to_delete.each { |key, _| @data.delete(key) }
|
@@ -280,7 +280,7 @@ module DynamoAutoscale
|
|
280
280
|
`r --no-save --args #{data_tmp} #{png_tmp} < #{r_script}`
|
281
281
|
|
282
282
|
if $? != 0
|
283
|
-
logger.error "Failed to create graph."
|
283
|
+
logger.error "[table] Failed to create graph."
|
284
284
|
else
|
285
285
|
`open #{png_tmp}` if opts[:open]
|
286
286
|
end
|
@@ -298,7 +298,7 @@ module DynamoAutoscale
|
|
298
298
|
`r --no-save --args #{data_tmp} #{png_tmp} < #{r_script}`
|
299
299
|
|
300
300
|
if $? != 0
|
301
|
-
logger.error "Failed to create graph."
|
301
|
+
logger.error "[table] Failed to create graph."
|
302
302
|
else
|
303
303
|
`open #{png_tmp}`
|
304
304
|
end
|