packages feed

network-metrics 0.3.0 → 0.3.1

raw patch · 2 files changed

+20/−12 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

network-metrics.cabal view
@@ -1,5 +1,5 @@ name:               network-metrics-version:            0.3.0+version:            0.3.1 synopsis:           Send metrics to Ganglia, Graphite, and statsd. license:            OtherLicense license-file:       LICENSE
src/Network/Metric/Sink/Statsd.hs view
@@ -65,16 +65,24 @@     -> BS.ByteString     -> Double     -> IO BL.ByteString-put host group bucket value typ rate =-    liftM bstr (randomRIO (0.0, 1.0))+put host group bucket value typ rate = liftM (BL.fromChunks . bstr) (sample rate)   where-    base   = [key host group bucket, ":", encode value, "|", typ]-    bstr n = BL.fromChunks $ case sample rate n of-        Sampled -> base ++ ["@", BS.pack $ show rate]-        Exact   -> base-        Ignore  -> []+    base = [key host group bucket, ":", encode value, "|", typ]+    bstr Sampled = base ++ ["@", BS.pack $ show rate]+    bstr Exact   = base+    bstr Ignore  = [] -sample :: Double -> Double -> Sampled-sample rate rand | rate < 1.0 && rand <= rate = Sampled-                 | rate == 1.0                = Exact-                 | otherwise                  = Ignore+-- NOTE: The bizarre type and branching logic of this function is entirely+-- for the purpose of hiding the 'randomRIO' call behind the rate < 1.0+-- condition (which currently will always be False).  This is to sidestep+-- a bug in random <=1.0.1.1 in which the 'randomRIO' function has a space leak.+--+-- There is a far saner, pure version of this function that should probably+-- be resurrected when the bug in the random package is fixed.+sample :: Double -> IO Sampled+sample rate+  | rate < 1.0   = do+      r <- randomRIO (0.0, 1.0)+      return $ if r <= rate then Sampled else Ignore+  | rate == 1.0  = return Exact+  | otherwise    = return Ignore