Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Delete an entire timer key (mean,min,max,etc.) all at once if you don…

…'t specify
  • Loading branch information...
commit f81f348ae1b62921ec61818ab6abb5d4b79fdfbe 1 parent f346e2d
@noahhl authored
Showing with 25 additions and 13 deletions.
  1. +2 −3 bin/batsd
  2. +23 −10 lib/batsd/deleter.rb
View
5 bin/batsd
@@ -77,9 +77,8 @@ begin
when :delete
statistic = ARGV[1]
if statistic && !statistic.empty?
- deleter = Batsd::Deleter.new(config)
- deleter.delete(statistic)
- puts "Deleted \"#{statistic}\"."
+ deletions = Batsd::Deleter.new(config).delete(statistic)
+ puts "Deleted #{deletions.join(",")}."
else
puts "Need to specify a statistic."
exit 1
View
33 lib/batsd/deleter.rb
@@ -16,18 +16,31 @@ def initialize(options={})
end
def delete(statistic)
- retentions = @options[:retentions].keys
-
- # first retention
- retentions.shift
- @redis.clear_key(statistic)
- @redis.remove_datapoint(statistic)
+ if statistic.match(/^timers:/)
+ # Fully specified key
+ if statistic.match(/^timers:.*:(mean|count|min|max|stddev|upper_90)/)
+ deletions = [statistic]
+ else
+ # Only statistic, not mean/min/max. Delete all of them
+ deletions = %w(mean count min max stddev upper_90).collect{|a| "#{statistic}:#{a}"}
+ end
+ else
+ deletions = [statistic]
+ end
+ deletions.each do |statistic|
+ retentions = @options[:retentions].keys
+ # first retention
+ retentions.shift
+ @redis.clear_key(statistic)
+ @redis.remove_datapoint(statistic)
- # other retentions
- retentions.each do |retention|
- key = "#{statistic}:#{retention}"
- @diskstore.delete(@diskstore.build_filename(key), :delete_empty_dirs => true)
+ # other retentions
+ retentions.each do |retention|
+ key = "#{statistic}:#{retention}"
+ @diskstore.delete(@diskstore.build_filename(key), :delete_empty_dirs => true)
+ end
end
+ deletions
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.