about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-10-14 14:38:16 -0700
committerEric Wong <normalperson@yhbt.net>2011-10-14 14:38:16 -0700
commit5d76462eb312df5343c1870fb68094459deca6ca (patch)
tree116254eb2b1ac7d3a1ee9bea625fd6ccfcc84c75
parentd5fc6f66bc17f27770b38126b6c4211fd938c5b5 (diff)
downloadraindrops-5d76462eb312df5343c1870fb68094459deca6ca.tar.gz
Math.sqrt on 1.8.7 does not give NaN for certain errors.
We'll also fix our Errno::EDOM retry loop to avoid resetting
the "retried" flag.
-rw-r--r--lib/raindrops/watcher.rb46
1 files changed, 27 insertions, 19 deletions
diff --git a/lib/raindrops/watcher.rb b/lib/raindrops/watcher.rb
index 1f3aaf3..869fa17 100644
--- a/lib/raindrops/watcher.rb
+++ b/lib/raindrops/watcher.rb
@@ -215,13 +215,19 @@ class Raindrops::Watcher
     end
   end
 
+  def std_dev(agg)
+    agg.std_dev.to_s
+  rescue Errno::EDOM
+    "NaN"
+  end
+
   def agg_to_hash(reset_at, agg, current, peak)
     {
       "X-Count" => agg.count.to_s,
       "X-Min" => agg.min.to_s,
       "X-Max" => agg.max.to_s,
       "X-Mean" => agg.mean.to_s,
-      "X-Std-Dev" => agg.std_dev.to_s,
+      "X-Std-Dev" => std_dev(agg),
       "X-Outliers-Low" => agg.outliers_low.to_s,
       "X-Outliers-High" => agg.outliers_high.to_s,
       "X-Last-Reset" => reset_at.httpdate,
@@ -261,29 +267,31 @@ class Raindrops::Watcher
 
   def get(env)
     retried = false
-    case env["PATH_INFO"]
-    when "/"
-      index
-    when %r{\A/active/(.+)\.txt\z}
-      histogram_txt(active_stats(unescape($1)))
-    when %r{\A/active/(.+)\.html\z}
-      addr = unescape $1
-      histogram_html(active_stats(addr), addr)
-    when %r{\A/queued/(.+)\.txt\z}
-      histogram_txt(queued_stats(unescape($1)))
-    when %r{\A/queued/(.+)\.html\z}
-      addr = unescape $1
-      histogram_html(queued_stats(addr), addr)
-    when %r{\A/tail/(.+)\.txt\z}
-      tail(unescape($1), env)
-    else
-      not_found
-    end
+    begin
+      case env["PATH_INFO"]
+      when "/"
+        index
+      when %r{\A/active/(.+)\.txt\z}
+        histogram_txt(active_stats(unescape($1)))
+      when %r{\A/active/(.+)\.html\z}
+        addr = unescape $1
+        histogram_html(active_stats(addr), addr)
+      when %r{\A/queued/(.+)\.txt\z}
+        histogram_txt(queued_stats(unescape($1)))
+      when %r{\A/queued/(.+)\.html\z}
+        addr = unescape $1
+        histogram_html(queued_stats(addr), addr)
+      when %r{\A/tail/(.+)\.txt\z}
+        tail(unescape($1), env)
+      else
+        not_found
+      end
     rescue Errno::EDOM
       raise if retried
       retried = true
       wait_snapshot
       retry
+    end
   end
 
   def not_found