Skip to content

Commit

Permalink
use monotonic clock instead of system clock
Browse files Browse the repository at this point in the history
  • Loading branch information
bergey committed Feb 17, 2021
1 parent 6dc2793 commit e05c471
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
12 changes: 7 additions & 5 deletions lib/Servant/Ekg/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Data.Monoid
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import Data.Time.Clock
import GHC.Clock (getMonotonicTime)
import GHC.Generics (Generic)
import Network.HTTP.Types (Method, Status (..))
import Network.Wai (Middleware, responseStatus)
Expand Down Expand Up @@ -58,12 +58,14 @@ countResponseCodes (c2XX, c4XX, c5XX, cXXX) application request respond =

responseTimeDistribution :: Distribution.Distribution -> Middleware
responseTimeDistribution dist application request respond =
bracket getCurrentTime stop $ const $ application request respond
bracket getMonotonicTime stop $ const $ application request respond
where
stop t1 = do
t2 <- getCurrentTime
let dt = diffUTCTime t2 t1
Distribution.add dist $ fromRational $ (*1000) $ toRational dt
t2 <- getMonotonicTime
let
dt = t2 - t1
milliseconds = dt * 1000
Distribution.add dist milliseconds

initializeMeters :: Store -> APIEndpoint -> IO Meters
initializeMeters store APIEndpoint{..} = do
Expand Down
1 change: 0 additions & 1 deletion servant-ekg.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ library
, hashable >=1.2.7.0 && <1.4
, servant >=0.14 && <0.19
, text >=1.2.3.0 && <1.3
, time >=1.6.0.1 && <1.12
, unordered-containers >=0.2.9.0 && <0.3
, wai >=3.2.0 && <3.3

Expand Down

0 comments on commit e05c471

Please sign in to comment.