hotdog 0.29.0 → 0.30.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
  SHA1:
3
- metadata.gz: cd9ee4784a5a2ae1305938dad9acffbda27344f5
4
- data.tar.gz: ab2ae3bdce389ba30f9bb20f11b9ab5952edc19a
3
+ metadata.gz: 704ccd17864c284a1daa3550e9c955469e718ee4
4
+ data.tar.gz: 0d5e59e8c274f25ebd179e92123380c5336d7cec
5
5
  SHA512:
6
- metadata.gz: 21a810b1448b94c8678e02bccf635a3716b796b2846d317cd493b092f707bc2111a1787dee5c7f6db4df8ad9d56cde2a9d95926cf177f771fec37e61bb4b2c91
7
- data.tar.gz: b1bfbba8629422bb3ede7dee2c5b2f65c0ea1029723ab92d60b4a997656af6bc13a7bf6436600a7c72436d25d4b1ebc2eb59d0ba33052645cc1a770ca5f02781
6
+ metadata.gz: 03d9ceb9147a75449c9b7542f3deecdb331cd0736d902603101508fbd1ef87881c82503b223dcd2c710f5f69c8408b173b95b1a17c57bbb08b5ca27857bfcc14
7
+ data.tar.gz: 5d32974bbbb07110a678538b5275ca792a1d76eb5ae086ad1b9831ff434d1937d4eae8f0ae4048df393bec2f81664223da444ba9aeee3467224b78bf4e0d375d
@@ -163,6 +163,17 @@ module Hotdog
163
163
  options.fetch(:status, STATUS_RUNNING)
164
164
  end
165
165
 
166
+ def status_name()
167
+ {
168
+ STATUS_PENDING => "pending",
169
+ STATUS_RUNNING => "running",
170
+ STATUS_SHUTTING_DOWN => "shutting-down",
171
+ STATUS_TERMINATED => "terminated",
172
+ STATUS_STOPPING => "stopping",
173
+ STATUS_STOPPED => "stopped",
174
+ }.fetch(self.status, "unknown")
175
+ end
176
+
166
177
  private
167
178
  def define_options
168
179
  @optparse.on("--endpoint ENDPOINT", "Datadog API endpoint") do |endpoint|
@@ -10,7 +10,26 @@ module Hotdog
10
10
  default_option(options, :retry, 5)
11
11
  default_option(options, :start, Time.new)
12
12
  optparse.on("--downtime DURATION") do |v|
13
- options[:downtime] = v.to_i
13
+ case v
14
+ when /\A\s*(\d+)\s*(?:seconds?|sec|S)\s*\z/
15
+ options[:downtime] = $1.to_i
16
+ when /\A\s*(\d+)\s*(?:minutes?|min|M)\s*\z/
17
+ options[:downtime] = $1.to_i * 60
18
+ when /\A\s*(\d+)\s*(?:hours?|H)\s*\z/
19
+ options[:downtime] = $1.to_i * 60 * 60
20
+ when /\A\s*(\d+)\s*(?:days?|d)\s*\z/
21
+ options[:downtime] = $1.to_i * 60 * 60 * 24
22
+ when /\A\s*(\d+)\s*(?:weeks?|w)\s*\z/
23
+ options[:downtime] = $1.to_i * 60 * 60 * 24 * 7
24
+ when /\A\s*(\d+)\s*(?:months?|m)\s*\z/i
25
+ options[:downtime] = $1.to_i * 60 * 60 * 24 * 30
26
+ when /\A\s*(\d+)\s*(?:years?|y)\s*\z/i
27
+ options[:downtime] = $1.to_i * 60 * 60 * 24 * 365
28
+ when /\A\s*(\d+)\s*\z/
29
+ options[:downtime] = $1.to_i
30
+ else
31
+ raise(OptionParser::InvalidArgument.new("downtime argument value is invalid: #{v}"))
32
+ end
14
33
  end
15
34
  optparse.on("--retry NUM") do |v|
16
35
  options[:retry] = v.to_i
@@ -236,17 +236,17 @@ module Hotdog
236
236
  end
237
237
 
238
238
  private
239
- def rewrite_expression(expression)
240
- expression = super(expression)
241
- if options[:index]
242
- expression = "SLICE((#{expression}), #{options[:index]}, 1)"
243
- end
244
- expression
245
- end
246
-
239
+ # rewriting `options[:index]` as SLICE expression won't work as expected with hosts' status
240
+ # since the result may be filtered again with using the status,
241
+ # the filtering needs to be done after the `evaluate()`.
242
+ #
243
+ # for now we need to keep using `filter_hosts()` in favor of `rewrite_expression() to do
244
+ # the filtering based on status filtering.
247
245
  def filter_hosts(tuples)
248
246
  tuples = super
249
247
  if options[:index] and options[:index] < tuples.length
248
+ filtered_tuples = tuples.reject.with_index { |tuple, i| i == options[:index] }
249
+ logger.warn("filtered host(s): #{filtered_tuples.map { |tuple| tuple.first }.inspect}")
250
250
  [tuples[options[:index]]]
251
251
  else
252
252
  tuples
@@ -81,10 +81,15 @@ module Hotdog
81
81
  end
82
82
 
83
83
  def get_hosts(host_ids, tags=nil)
84
- status = application.status || STATUS_RUNNING
84
+ status = application.status
85
+ n = Array(host_ids).length
85
86
  host_ids = Array(host_ids).each_slice(SQLITE_LIMIT_COMPOUND_SELECT).flat_map { |host_ids|
86
87
  execute("SELECT id FROM hosts WHERE status = ? AND id IN (%s);" % host_ids.map { "?" }.join(", "), [status] + host_ids).map { |row| row[0] }
87
88
  }
89
+ m = host_ids.length
90
+ if n != m
91
+ logger.warn("filtered out #{n - m} host(s) out of #{n} due to status != #{application.status_name}.")
92
+ end
88
93
  tags ||= @options[:tags]
89
94
  update_db
90
95
  if host_ids.empty?
@@ -139,7 +144,7 @@ module Hotdog
139
144
  when 1
140
145
  get_hosts_field(host_ids, fields.first, options)
141
146
  else
142
- [host_ids.sort.map { |host_id| get_host_fields(host_id, fields, options) }.map { |result, fields| result }, fields]
147
+ [host_ids.map { |host_id| get_host_fields(host_id, fields, options) }.map { |result, fields| result }, fields]
143
148
  end
144
149
  end
145
150
 
@@ -229,9 +229,13 @@ module Hotdog
229
229
  range = (((sqlite_limit_compound_select - 2) / 2) * i)...(((sqlite_limit_compound_select - 2) / 2) * (i + 1))
230
230
  left_selected = left_values.select { |n| range === n }
231
231
  right_selected = right_values.select { |n| range === n }
232
- q = "SELECT id FROM hosts " \
233
- "WHERE ? <= id AND id < ? AND ( id IN (%s) OR id IN (%s) );"
234
- environment.execute(q % [left_selected.map { "?" }.join(", "), right_selected.map { "?" }.join(", ")], [range.first, range.last] + left_selected + right_selected).map { |row| row.first }
232
+ if 0 < left_selected.length or 0 < right_selected.length
233
+ q = "SELECT id FROM hosts " \
234
+ "WHERE ? <= id AND id < ? AND ( id IN (%s) OR id IN (%s) );"
235
+ environment.execute(q % [left_selected.map { "?" }.join(", "), right_selected.map { "?" }.join(", ")], [range.first, range.last] + left_selected + right_selected).map { |row| row.first }
236
+ else
237
+ []
238
+ end
235
239
  }.tap do |values|
236
240
  environment.logger.debug("lhs(#{left_values.length}) OR rhs(#{right_values.length}) => #{values.length}")
237
241
  end
@@ -257,11 +261,15 @@ module Hotdog
257
261
  range = (((sqlite_limit_compound_select - 2) / 4) * i)...(((sqlite_limit_compound_select - 2) / 4) * (i + 1))
258
262
  left_selected = left_values.select { |n| range === n }
259
263
  right_selected = right_values.select { |n| range === n }
260
- q = "SELECT id FROM hosts " \
261
- "WHERE ? <= id AND id < ? AND NOT (id IN (%s) AND id IN (%s)) AND ( id IN (%s) OR id IN (%s) );"
262
- lq = left_selected.map { "?" }.join(", ")
263
- rq = right_selected.map { "?" }.join(", ")
264
- environment.execute(q % [lq, rq, lq, rq], [range.first, range.last] + left_selected + right_selected + left_selected + right_selected).map { |row| row.first }
264
+ if 0 < left_selected.length or 0 < right_selected.length
265
+ q = "SELECT id FROM hosts " \
266
+ "WHERE ? <= id AND id < ? AND NOT (id IN (%s) AND id IN (%s)) AND ( id IN (%s) OR id IN (%s) );"
267
+ lq = left_selected.map { "?" }.join(", ")
268
+ rq = right_selected.map { "?" }.join(", ")
269
+ environment.execute(q % [lq, rq, lq, rq], [range.first, range.last] + left_selected + right_selected + left_selected + right_selected).map { |row| row.first }
270
+ else
271
+ []
272
+ end
265
273
  }.tap do |values|
266
274
  environment.logger.debug("lhs(#{left_values.length}) XOR rhs(#{right_values.length}) => #{values.length}")
267
275
  end
@@ -1,3 +1,3 @@
1
1
  module Hotdog
2
- VERSION = "0.29.0"
2
+ VERSION = "0.30.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotdog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.29.0
4
+ version: 0.30.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yamashita Yuu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-10 00:00:00.000000000 Z
11
+ date: 2017-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler