-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #538 from symbiont-io/journal-latency
feat(sut): try to add latency to metrics (still not working)
- Loading branch information
Showing
10 changed files
with
76 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,41 @@ | ||
{-# LANGUAGE DeriveGeneric, DeriveFunctor#-} | ||
{-# LANGUAGE DeriveFunctor #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE DerivingStrategies #-} | ||
|
||
module Dumblog.Journal.Codec where | ||
|
||
import Data.Binary (Binary) | ||
import qualified Data.Binary as Binary | ||
import Data.ByteString (ByteString) | ||
import qualified Data.ByteString.Lazy as LBS | ||
import Data.Int (Int64) | ||
import Data.Time (UTCTime, getCurrentTime, nominalDiffTimeToSeconds) | ||
import Data.Time.Clock.POSIX (utcTimeToPOSIXSeconds) | ||
import GHC.Generics (Generic) | ||
|
||
import GHC.Generics(Generic) | ||
------------------------------------------------------------------------ | ||
|
||
data Envelope a = Envelope | ||
{ eLength :: Int | ||
, eContent :: a | ||
} deriving (Functor, Generic) | ||
{ eLength :: !Int | ||
, eContent :: !a | ||
, eArrival :: !Int64 -- Nano seconds since epoch. | ||
} deriving stock (Functor, Generic) | ||
|
||
instance Binary a => Binary (Envelope a) where | ||
|
||
encode :: Binary a => Envelope a -> ByteString | ||
encode e = LBS.toStrict (Binary.encode e) | ||
|
||
-- this is guaranteed not to copy the bytestring | ||
-- but we should probably allow this to fail | ||
-- This is guaranteed not to copy the bytestring but we should probably | ||
-- allow this to fail. | ||
decode :: Binary a => ByteString -> Envelope a | ||
decode bs = Binary.decode $ LBS.fromStrict bs | ||
|
||
nanosSinceEpoch :: UTCTime -> Int64 | ||
nanosSinceEpoch = | ||
floor . (1e9 *) . nominalDiffTimeToSeconds . utcTimeToPOSIXSeconds | ||
|
||
getCurrentNanosSinceEpoch :: IO Int64 | ||
getCurrentNanosSinceEpoch = do | ||
now <- getCurrentTime | ||
return (nanosSinceEpoch now) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters